Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Automate Testing : Browserstack and SeleniumJS

Arnaud Poncet-Montanges edited this page Jan 19, 2015 · 1 revision

Browserstack and SeleniumJS

Basics

A simple test can be run using

node tests.js -t http://map.geo.admin.ch

in the folder test/selenium/

Be sure to load the BROWSERSTACK_USER and BROWSERSTACK_PASSWORD environment variables locally.

WebdriverJS functions

  • Enable implicit timeout to give the driver some time before **timing out **

driver.manage().timeouts().implicitlyWait(TIMEOUT);

  • Maximize the browser resolution (only on desktop browsers)

driver.manage().window().maximize();

  • Resize the browser resolution (only on desktop browsers)

driver.manage().window().resize(x,y);

  • Load a page / Refresh

driver.get(target + '/?lang=de');

  • Click on an element found in the page using xpath

driver.findElement(webdriver.By.xpath("//*[@id='pulldown']")).click();

  • Push keys in a field found in the page using xpath

driver.findElement(webdriver.By.xpath("//*[@type='search']")).sendKeys('Bern');

  • Compare two URLS (require assert module)

driver.getCurrentUrl().then(function(url) {
assert.ok(url.indexOf(QUERYSTRING_OF_BERN) > -1);
});

See : https://code.google.com/p/selenium/wiki/WebDriverJs for more functions or http://selenium-suresh.blogspot.ch/2012/09/selenium-web-driver-command-list.html

Available Webdrivers

See : https://www.browserstack.com/automate/capabilities and http://www.browserstack.com/automate/node

Workflow

tests.js actual state

  • Webdrivers are generated (Capabilities)

  • Tests are loaded (start / search and print)

  • Browserstack sessions are created (one for each webdriver)

  • Tests are performed

  • Errors are reported

Rules to avoid errors

Since the webdriver is not getting any infos from the User Interface (UI), we need to add some safety parameters to ensure that the webpage we assume to test is really the webpage we are testing

  1. Manage time use (use implicit timeout and not sleep)
  2. Check the DOM/JS state after passing a driver command (search for new/modified DOM element after click event/ key input)

Source : http://bocoup.com/weblog/a-day-at-the-races/