r3 - 19 Jul 2007 - 06:24:02 - MimiYinYou are here: OSAF >  Journal Web  >  QualityAssuranceTeam > AdamChristianNotes > AdamChristianSeleniumMethods

Selenium Test Writing

Selenium uses a HTML table format to specify the function being called and its parameters.
Each test is a table, within that table each row is an action, and each column in that row is a parameter:

example

<tr>
<td>function</td>
<td>parameter 1</td>
<td>parameter 2</td>
</tr>

Methods being used:

open

<tr>
<td>open</td>
<td>/scooby/main.page</td>
<td></td>
</tr>

To open a URL

click

<tr>
<td>click</td>
<td>id=savebuttonText</td>
<td></td>
</tr>

To click on a div by id

type

<tr>
<td>type</td>
<td>eventdescr</td>
<td>Super important event. </td>
</td>

To type text into a form field select

<tr>
<td>select</td>
<td>status</td>
<td>label=Tentative</td>
</tr>

Selecting an option from a drop down box

clickAndWait

<tr>
<td>clickAndWait</td>
<td>link=Log in to Scooby</td>
<td></td>
</tr>

Clicking on a link and waiting for it to load

pause

<tr>
<td>pause</td>
<td>4000</td>
<td></td>
</tr>

Waiting for x amount of milliseconds

dblclick

<tr>
<td>dblclick</td>
<td>id=hourDiv3-1000</td>
<td></td>
</tr>

This is the way double click is done when creating new events.

dragdrop

<tr>
<td>dragdrop</td>
<td>id=eventDivContent__${did}</td>
<td>+5, 0</td>
</tr>

This is the format for doing drag and drop, the second parameter is using a dynamic id, I will show you how I receive in the next example, the third parameter is the distance to move the id, (left (+) right (-) from div, up (+) and down (-) from div)

Note: It would be more convenient to specify the div ID where I want to drag the current div, but there is an unfortunate bug in the Selenium API that crashes JavaScript in the browser, so we are stuck using coordinates.

store

<tr>
<td>store</td>
<td>javascript{this.browserbot.getCurrentWindow().Cal.eventRegistry.getFirst().id}</td>
<td>did</td>
</tr>

This allows us to call the Cal.eventRegistry on the current window for the current browser and get the id of the first registered event div. Changing getFirst() to getNext() allows you to maneuver through all of the events in the system. This then stores the id of the event you are querying in the variable did so you can use it later as ${did} this is done in the last example.

As demonstrated javascript can be executed using it as a parameter in various functions with javascript{code here}

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
 
Open Source Applications Foundation
Except where otherwise noted, this site and its content are licensed by OSAF under an Creative Commons License, Attribution Only 3.0.
See list of page contributors for attributions.