Execute A Customized Script in Protractor and SerenityJS

Often times, Selenium/Protactor action(s) will work on one browser but not on another browser. As in my case, the Scroll action and DoubleClick action are both accepted by Chrome, however not by Firefox Gecko driver. Some research find it to be a known issue with Firefox Gecko Driver not implementing the moveTo() action in selenium WebDriver. If run with the Scroll or DoubleClick actions agaist Firefox Gecko Driver, an exception will be thrown stating moveTo() is not implemented.

That aside, today we are not covering resolving those issues, they deserve a separate post. We will show how to execute a customized Javascript with Protractor and SerenityJS, which will be used later to implement the missing actions mentioned above.

So to exeecute a customized Javascript is very straight forward as documented in protractor’s documentation, we just need simple to have the following:

Where the second parameter is an argument that can be passed into the Javascript defined in the first parameter. As shown in the Javascript definition, arguments[0] is actually the second parameter passed into the executeScript method.

A second alternative done through SerenityJS implementation of a smiliar functionality, as shown:

where this.script is defined as:

 

 

 

References:

[1] https://github.com/mozilla/geckodriver/issues/776

[2] https://www.protractortest.org/#/api?view=webdriver.WebDriver.prototype.executeScript

[3] http://www.webdriverjs.com/javascript-executor-protractor/

Leave a Reply

Your email address will not be published. Required fields are marked *