WebDriver and Grid 2
WebDriver is the latest greatest API for testing browsers, and is incorporated into Selenium 2 in a variety of languages, including Python. I'm building it into my ptest framework as well, in the WebDriverLib class in the weblib.py module.
The plan is to move all the legacy Selenium 1 tests to Grid 2
Since all of my tests are in Selenium 1 and WebDriver is a completely different API (woo hoo) I have a translation layer to map the existing tests to the new API.
cd $TEST_HOME/src
python
then, in the python shell ...
from weblib import WebDriverLib
settings = {"browser": "*iehta"}
lib = WebDriverLib(settings)
email = settings.get('email', 'auto_test@your.co.com')
password = settings.get('password', 'autotest1')
dev_url = settings.get("dev_url", "https://your.co.com")
lib.open(dev_url) # translation layer for 'get'
lib.wait_and_type("//input[@id='Email']", email) # translation layer for find element and send_keys
lib.wait_and_type("//input[@id='Password']", password)
lib.wait_and_click("//a[@class='ui-button submit']") # translation layer for find element and click it
lib.wait_for_page_to_load(30000)
Grid 2
BASICS:
to launch the hub locally:
java -jar selenium-server-standalone-2.15.0.jar -role hub
to launch a node (formerly 'remote control') locally:
java -jar selenium-server-standalone-2.15.0.jar -role node -port 5555 -hubHost localhost -hubPort 4444 -hub http://localhost:4444/grid/register
running on my qa-jenkins machine at port 4445:
hub:
nohup java -jar selenium-server-standalone-2.15.0.jar -role hub -port 4445
node:
java -jar selenium-server-standalone-2.15.0.jar -role node -port 5555 -hubHost qa-jenkins -hubPort 4445 -hub http://qa-jenkins:4445/grid/register
node
multiple firefox nodes on the remote control machine (note the different versions and executable paths specified)
java -jar selenium-server-standalone-2.15.0.jar -role node -port 2333 -hubHost qa-jenkins -hubPort 4445 -hub http://
qa-jenkins :4445/grid/register -browser browserName=firefox,version=3.6,firefox_binary=c:\progra~2\mozill~2\firefox.exe,maxInstances=1,platform=WINDOWS
and
java -jar selenium-server-standalone-2.15.0.jar -role node -port 2888 -hubHost
qa-jenkins -hubPort 4445 -hub http://
qa-jenkins :4445/grid/register -browser browserName=firefox,version=8,firefox_binary=c:\progra~2\mozill~1\firefox.exe,maxInstances=1,platform=WINDOWS
for ptest config:
-b *firefox3 will invoke the 3.6 node, and *firefox8 will invoke the 8 node
ptest
example:
python ptest.py -c webtest_config.json -t test_webdriver -w true -b *firefox8
Internet Explorer node:
java -jar selenium-server-standalone-2.15.0.jar -role node -hub http://qa-jenkins:4445/grid/register -browser browserName=iexplore,version=9,platform=WINDOWS -port 8000
Google Chrome node: (note the path is to the chromedriver executable, not to an installed Chrome browser. Also, the path to the chromedriver executable must be set in the PATH environment variable)
java -jar selenium-server-standalone-2.15.0.jar -role node -port 6000 -hubHost qa-jenkins -hubPort 4445 -hub http://qa-jenkins:4445/grid/register -browser browserName=chrome,chrome_binary=C:\chromedriver\chromedriver,maxInstances=1,platform=WINDOWS
see http://code.google.com/p/selenium/wiki/ChromeDriver for more information
For SSL Issues with Google Chrome, initialize the WebDriver client with a chrome.switches array as below (python bindings example) ->
from selenium import webdriver
dc = webdriver.DesiredCapabilities.CHROME
dc["chrome.switches"] = ["--ignore-certificate-errors"]
driver = webdriver.Remote(str(remote_url), self.dc)
No comments:
Post a Comment