Clicking on the given coordinates of the element in the protractor

I want to click on a specific location of my canvas , so I wrote the following Protractor code:

 var canvas = element(by.id("canvas")); var clickCanvas = function(toRight, toBottom) { browser.actions() .mouseMove(canvas, -toRight, -toBottom) .click(); } 

toRight / toBottom is the number of pixels where a click should be made, relative to the upper left corner of my canvas.

However, the click does not seem to be executed at the given coordinates. I got a snippet from a related question about exchanging quality assurance and software testing stacks.

Can you confirm that this fragment works?
Can you suggest alternatives?

+6
source share
3 answers

I did this job by passing an object representing the coordinate as the second argument to mouseMove :

 var canvas = element(by.id("canvas")); var clickCanvas = function (toRight, toBottom) { browser.actions() .mouseMove(canvas, {x: toRight, y: toBottom}) .click() .perform(); }; 
+15
source

you missed .perform ()

browser.actions().mouseMove(canvas, -toRight, -toBottom).click().perform();

I use this several times in my tests and confirm that it works

+2
source

In this case, you missed the call to perform() :

  browser.actions() .mouseMove(canvas, -toRight, -toBottom) .click(); // < no .perform() HERE 

This is one of the common mistakes when writing e2e tests in Protractor / WebDriverJS.

To prevent these errors, there is an eslint-plugin-protractor in ESLint that will warn you if perform() not been called in the browser.actions() chain.

+1
source

Source: https://habr.com/ru/post/982504/


All Articles