How to call user-extensions.js in Selenium WebDriver

I need to use the functions defined in user-extensions.js.We are in the process of switching from RC to webdriver. I found out that there is a JavascriptExecutor that will replace runScript and getEval. But as I point out the user-extensions.js file. Is it the same as java -jar selenium-server-standalone.jar -userExtensions user-extensions.js?

+4
source share
3 answers

They now have an IJavaScriptExecutor interface that can be used to replace custom extensions.

This is the C # / NUnit version.

IJavaScriptExecutor js = driver as IJavaScriptExecutor; long tableRowCount = (long)js.ExecuteScript("return $('#tableid tr').length); 

Here is the Java / JUnit version:

 JavascriptExecutor js = (JavascriptExecutor) driver; Object o = js.executeScript("return '123'"); 
+1
source

Finally, after 2 years and 2 months, I found a solution to use the user extension file in webdriver, and now we move on to webdriver.

  loadjsFile(driver); 

Function below:

 public static void loadjsFile(WebDriver driver){ String scriptSrc = "http://localhost:8080/test/user-extensions.js"; String injectScript = "var script = document.createElement(\"script\");"; injectScript += "script.src = \""+scriptSrc+"\";"; injectScript += "script.setAttribute(\"type\",\"text/javascript\");"; injectScript += "document.body.appendChild(script);"; ((JavascriptExecutor) driver).executeScript(injectScript); } 
+4
source

It is not possible to embed javascript that is accessible through your test run, for example, Selenium RC, here is a thread about some possible hints for migration: http://groups.google.com/group/selenium-developers/browse_thread/thread/15cb4b774b734cc7/c7baf10db0bc2bc0

+1
source

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


All Articles