Selenium: Difference between revisions

From Genecats
Jump to navigationJump to search
Line 34: Line 34:
* [http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/ Selenium Tips: CSS Selectors in Selenium Demystified]
* [http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/ Selenium Tips: CSS Selectors in Selenium Demystified]


=Testing AJAX applications=
=Testing AJAX and other dynamic applications=
The main things you'll need to test AJAX calls are the waitFor... commands. Here are a few of the most useful ones:
The main things you'll need to test AJAX calls and other dynamic functions are the waitFor... commands. Here are a few of the most useful ones:


====waitForCondition(script, timeout)====
====waitForCondition(script, timeout)====
This is probably the most important one. [http://wiki.openqa.org/display/SEL/waitForCondition Examples].
This is '''the''' AJAX command.
 
Arguments:
Arguments:
*script - the JavaScript snippet to run
*script - the JavaScript snippet to run
Line 45: Line 44:
Runs the specified JavaScript snippet repeatedly until it evaluates to "true". The snippet may have multiple lines, but only the result of the last line will be considered.
Runs the specified JavaScript snippet repeatedly until it evaluates to "true". The snippet may have multiple lines, but only the result of the last line will be considered.


Note that, by default, the snippet will be run in the runner's test window, not in the window of your application. To get the window of your application, you can use the JavaScript snippet selenium.browserbot.getCurrentWindow(), and then run your JavaScript in there
Note that, by default, the snippet will be run in the runner's test window, not in the window of your application. To get the window of your application, you can use the JavaScript snippet selenium.browserbot.getCurrentWindow(), and then run your JavaScript in there.
 
[http://wiki.openqa.org/display/SEL/waitForCondition Examples].
 


====waitForVisible(locator)====
====waitForVisible(locator)====

Revision as of 22:50, 9 December 2011


This is mostly a place holder while we develop more content. Here are some useful links...

The Basics

Setting up Selenium IDE

1. Download/install Selenium IDE for Firefox

2. Open Selenium IDE from Firefox under the Tools pulldown menu

3. Once IDE is open, go to: Options > Options... > Locator Builders and reorder them to (from top down): id, name, link, css, ui, ...then everything else...

Ordering them like this makes for faster running tests, as finding unique elements (id, name, link) is faster (and easier to read) than hunting for them using another method. The fallback is using css selectors, as css selectors have proven to be faster than xPath.

Element Locators

A common way to find elements on a page using Selenium is xPath, however, we should use CSS selectors when possible, as the tests run faster - especially in IE. Here's some info:

Testing AJAX and other dynamic applications

The main things you'll need to test AJAX calls and other dynamic functions are the waitFor... commands. Here are a few of the most useful ones:

waitForCondition(script, timeout)

This is the AJAX command. Arguments:

  • script - the JavaScript snippet to run
  • timeout - a timeout in milliseconds, after which this command will return with an error

Runs the specified JavaScript snippet repeatedly until it evaluates to "true". The snippet may have multiple lines, but only the result of the last line will be considered.

Note that, by default, the snippet will be run in the runner's test window, not in the window of your application. To get the window of your application, you can use the JavaScript snippet selenium.browserbot.getCurrentWindow(), and then run your JavaScript in there.

Examples.


waitForVisible(locator)

Generated from isVisible(locator). Also not it's evil twin, waitForNotVisible(locator). These are good when an element is on a page but hidden (i.e., a popup) and your test requires you to wait for it to become visible before clicking on some element inside it.

Arguments:

  • locator - an element locator

Returns: true if the specified element is visible, false otherwise

Determines if the specified element is visible. An element can be rendered invisible by setting the CSS "visibility" property to "hidden", or the "display" property to "none", either for the element itself or one if its ancestors. This method will fail if the element is not present.

Example:

waitForVisible(id=hgTrackUiDialog)

Wait for the UiDialog (which has an id=hgTrackUiDialog) to appear so the test can continue and click on elements in this dialog.

Selenium Resources

General Automated Testing Resources