In the implementation of the Keyword Framework Approach for testing a web application we can used Selenium IDE as the Record/Replay tool. Once you have the script you can then run the scripts using Selenium RC or Selenium Grid.
A typical script for automation involves a number of actions or steps on a web page. I this example we will look at automation of Google’s Gmail Login page.
Here are some of the steps
1. Open http://www.gmail.com
2. Enter “user id”
3. Enter “password”
4. Click on “login button”
Here is an example of using store and store eval in selenium in C# its GetEval
String SiteName = "Selenium Wiki";
String SiteName = selenium.GetEval("storedVars['SiteName'].substring(9);");
Console.WriteLine(SiteName);
The output will be Wiki
If you are new to Selenium IDE and you are looking for a simple selenium ide script here is one in HTML format.
selenium.Open("/");
selenium.Type("q", "selenium wiki");
selenium.Click("btnG");
Thread.Sleep(5000);
selenium.Click("link=Selenium Wiki");
selenium.WaitForPageToLoad("30000");
User-extensions are very easy to use with the selenium IDE.
1. Create your user extension and save it as user-extensions.js. While this name isn’t technically necessary, it’s good practice to keep things consistent.
2. Open Firefox and open Selenium-IDE.
3. Click on Tools, Options
4. In Selenium Core Extensions click on Browse and find the user-extensions. js file. Click on OK.
5. Your user-extension will not yet be loaded, you must close and restart Selenium-IDE.
6. In your empty test, create a new command, your user-extension should now be an options in the Commands dropdown.
These are probably the most commonly used commands for building test.
open opens a page using a URL.
click/clickAndWait performs a click operation, and optionally waits for a new page to load.
verifyTitle/assertTitle verifies an expected page title.
verifyTextPresent verifies expected text is somewhere on the page.
verifyElementPresent verifies an expected UI element, as defined by its HTML tag, is present on the page.
verifyText verifies expected text and it’s corresponding HTML tag are present on the page.
verifyTable verifies a table’s expected contents.
waitForPageToLoad pauses execution until an expected new page loads. Called automatically when clickAndWait is used.
waitForElementPresent pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.
* Tests developed on Firefox via Selenium-IDE can be executed on any other supported browser via a simple Selenium-RC command line.
** Selenium-RC server can start any executable, but depending on browser security settings there may be technical limitations that would limit certain features.