Selenium IDE is a Firefox plugin for functional testing of websites. Download from http://seleniumhq.org. Current version 2.8.0. All entries have in common a command, a target and a value. Use XPath for flexibility.

Actions

Actions in Selenese are commands that change the state of the application. Examples are clicking a hyperlink or filling out a form. Can be done by running the IDE in “record mode”.

Open a url:
command: open
target: /login
value:

An input box:
command: type
target: //input[@name=’age’]
value: 15

Radio buttons
command: click
target: xpath=(//input[@name=’color’])[2]
value:

Selects
command: click
target: //select[@name=’country’]
value: label=NL

Find the target by attribute and partial string
command: type
target: //input[contains(@ref, ‘Number_’)]
value: 15

Running a test at maximum speed may fail the test because it is possible a page has not loaded yet. Therefore momentary halt the script with actions “pause” or “waitForPageToLoad” with target value 1000 as the time to wait in milliseconds.

command: pause
target: 1000
value:

Other options:
* “waitforText” will wait for text to appear on next page before moving on to the next command
* with forms: use the WaitForElementPresent action

command: waitforText
target: css=label
value: My Office

If a new window opens first grab the new window before moving on:

command: selectWindow
target: null
value:

Accessors

Accessors in Selenese grab and store the state of an application

Store a random number, accessible as value as ${name}:
command: store
target: javascript{Math.floor(Math.random()*11)}
value: random_number

Select a random option in a select box:
command: storeXpathCount
target: //select[@name=’country’]/option
value: counter
command: store
target: javascript{Math.floor(storedVars[‘counter’]*Math.random())}
value: rand
command: select
target: //select[@name=’country’]
value: index=${rand}

Select a random radio button:
command: storeXpathCount
target: //select[@name=’country’]/option
value: counter
command: store
target: javascript{Math.floor(storedVars[‘counter’]*Math.random()) +1}
value: rand
command: click
target: xpath=(//input[name=’country’])[${rand}]
value:

Echo a variable to the log output for debugging:
command: echo
target: ${name}
value:

Grab any inner text of an element for example from a table:
command: storeText
target: //table/tbody/tr[4]/td[2]
value: numQ

Assertions

Assertions test if the state of an application is what is expected. An assert will fail the test and the remainder of the test is aborted. A verify will fail the test but the test will continue to run.
Verify if a text is present on a page:
command: verifyText
target: xpath=(//html/body/div[3]/h1/span)
value: Earth
Tip: copy xpath with help from a development tool like Firebug

Better still use a regular expression:
command: verifyText
target: xpath=(//html/body/div[3]/h1/span)
value: regexp:[Ee]arth

or a glob:
command: verifyText
target: xpath=(//html/body/div[3]/h1/span)
value: glob:*arth

SAving your data

When starting a project
* start with creating a test case
* then save the test case
* then save the test suite as
Any attempt to save the suite first will end up in confusion

Speed

Best run a test at top-speed. There are however browser quirks beyond your control. The slow loading of a page is already mentioned. Combat remaining quirks with a simple but effective pause.

Advertisements