How to perform context click in protractor with typescript


#1

here I need to move my mouse cursor and perform context click (right click) action to do further actions.
I tried with this code snippets
{ await general.mouseMove();
const ele = await browser.actions().mouseMove({ x: 150, y: 450 }).perform();
await browser.actions().click( protractor.Button.RIGHT).perform();
}
and it didn’t work.


#2

Hi @lohitN,

sadly this seems to be a trouble with the native Webdriver.JS implementation, which is backing Protractor. You can find an issue at Github here.

Long story short, the browser.actions API supports only the legacy format, whereas the new W3C conforming actions aren’t yet supported by Protractor. There is a way to work around this - although not nice- but we need to add an additional feature to Webtestit in order to be able to properly pass a browser configuration of desired capabilities to ignore w3c standards. We hope to be able to ship this with the next release, but since this is already next week it might be pretty tight :wink:

Last but not least instead of hardcoding the X & Y coordinates you can make use of getLocation and also the APIs can be chained one after another instead which is necessary to perform a series (go to element AND right click)

const location = await element(this.yourPageObjectElement).getLocation();
await browser.actions().mouseMove(location).click(protractor.Button.RIGHT).perform();

#3

I tried this, it’s doing left click.


#4

yep as said without the fix for Chrome to ignore w3c mode it wont work for now, so we’ll have to squeeze that in with the next release.
Meanwhile if you want to try it out by yourself, open the file protractor.conf.js, look at the line 85 and you’ll see something like this:

configuration.capabilities = Object.assign({
    browserName: process.env.RX_ENDPOINT_BROWSER,
    operaOptions: {
      args: [],
      extensions: [],
      binary: process.env.RX_OPERA_PATH
    }
  }, capabilities);

now if you change that to

configuration.capabilities = Object.assign({
    browserName: process.env.RX_ENDPOINT_BROWSER,
    operaOptions: {
      args: [],
      extensions: [],
      binary: process.env.RX_OPERA_PATH
    },
    chromeOptions: {
      w3c: false
    }
  }, capabilities);

it should work. But as said, we’ll offer a better solution instead of this hack.