Learning Resources
JavaScript Usage
Selenium RC launches the browser with itself as the proxy server (hence you may get certificate warning in some modes) and then it injects javascript - to play the test. This also means it can easily work in ALL browsers/platform - and it can be easily used to test AJAX(unlike professional tools).
Since Selenium is based on JavaScript, you can use it in your tests.It is an excellent way to extract information from the pages for later reuse.
There are 2 methods available:
-
getEval(script)
: it takes the script as a string, executes it and return the value to which the script evaluates too. In ruby useget_eval
orjs_eval
-
Using this method, the
window
object refers to the Selenium context, which is different from the tested application’s JavaScript contextTo work around this, you need to get the application’s
window
object usingcurrentwindow = this.browserbot.getCurrentWindow()
* If you want to get an element, just useelement = this.browserbot.findElement("locator")
-
-
runScript(script)
: it actually adds atag in the current page of the tested application, making it easier to debug