Selenium Web Test Tool Training: Kangeyan Passoubady (Kangs)
Selenium Web Test Tool Training: Kangeyan Passoubady (Kangs)
Copy Right: 2008, All rights reserved by Kangeyan Passoubady (Kangs). Republishing requires authors permission
Lesson
Selenese Commands
Variable Substitution
#1
You can store any value into a variable using selenium accessors. Variable substitution provides a simple way to include a previously stored variable in a command parameter If you give the variable name as intAmount. To use the variable anywhere else use ${intAmount}. This will substitute the actual value in the place of ${intAmount}. Use echo ${intAmount} to display the values in the Log. Any of the selenium accessors can be used to store a value. Some of the key accessors are storeText, storeValue, storeCookie, storeAlert and storeEval
Variable Substitution
1. Open the HelloWorld.html in Firefox 2. Create a test case by opening FirefoxToolsSelenium IDE (by default it is in Recording mode) 3. Update the base URL of Selenium IDE with the URL in the Firefox address 4. Click on the link Click here to enter your name, when prompter for your name, enter your name. 5. Your name will be displayed in next line.
#3
6. Highlight your name Right click and select the assertText, then Stop the recording in Selenium IDE.
7. Rerun the test case in Selenium IDE
Variable Substitution
1. Your test case will look like in Selenium IDE as shown in the figure right side 2. Try to run multiple time and make sure your test case is passed without any failures.
#4
Your answerOnNextPrompt should be before than the click command. Make sure it precedes otherwise your test case will fail.
Variable Substitution
#5
1. Now well try to do the same exercise using variable substitution 2. In the Selenium IDE, select answerOnNextPrompt, Right Click and Select a new command 3. Select the command store 4. Target Kangeyan 5. Value vName 6. Store | Kangeyan | vName 7. Underneath insert a new command and provide the below values 8. echo | ${vName} 9. Right click and copy the echo command, and paste before the assertText command line
Discover the automating power of Selenium
Copyright 2008-2010 by Kangeyan Passoubady (Kangs)
Variable Substitution
#6
Your recorded test case will look something similar to this one
Variable Substitution
echo shows the variable values in the Log
#7
See the usage of ${vName} in answerOnNextPrompt and assertText echo prints the variable values in the third column of the command in Test Runner
storedVars
#1
All the variables are internally stored in a map named storedVars. storedVars allows you to access the ${varName} using the varName key within the map. Using storedVars you can reference the values within Javascript Evaluation code. What is a Map? Maps provide a more general way of storing elements. An object that maps keys to values. A map cannot contain duplicate keys (duplicate variable names); The Map collection type allows to store pairs of elements, termed "keys" and "values", where each key maps to one value. Here Keys refers Selenium variable Names and values refers to their values.
Discover the automating power of Selenium
Copyright 2008-2010 by Kangeyan Passoubady (Kangs)
storedVars
#2
10
storedVars
#3
Your recorded test case will look something similar to this one
11
JavaScript Evaluation
#1
JavaScript evaluation allows full power of JavaScript code in constructing the Command Parameter JavaScript snippet can be given using the following syntax. Javascript { <code snippet goes here> } Javascript keyword is optional The code given is treated as a JavaScript code and executed. storedVars Map can be used to access the previously stored variables Variable substitution should be handled carefully within the JavaScript code.
Discover the automating power of Selenium
Copyright 2008-2010 by Kangeyan Passoubady (Kangs)
12
JavaScript Evaluation #2 1. You can use any of the following Eval commands assertEval, assertNotEval, VerifyEval, verifyNotEval, waitForEval, waitForNotEval, storeEval 2. You can use any of the following Expression commands assertExpression, assertNotExpression,verifyExpression, verifyNotExpression, waitForExpression, waitForNotExpression, storeExpression, store and WaitForCondition
Discover the automating power of Selenium
Copyright 2008-2010 by Kangeyan Passoubady (Kangs)
13
#3
Open a specific URL (http://www.barnesandnoble.com/) Search for a specific text (Javascript) in #1 page Sort by Prizev How do you check Online Price: $$$ is in sorted order?
14
Answer #4 In this case I have decided to check the first two Amounts displayed on that page are in the ascending order. The first value is A, the second value is B If A <= B then we assume the first two listed prices are in ascending order. Now get the third value C If B <= C then we assume that A, B and C are in ascending order. (i.e., A <= B <=C )
Discover the automating power of Selenium
Copyright 2008-2010 by Kangeyan Passoubady (Kangs)
15
Answer
#5
16
Answer
Xpath for first amount storeText in a variable T1
#6
17
Answer
1. Now we can store true in T6 and compare with value with T5 2. If that comparison yields true then it is Ascending Order
#7
18
Alert
storeAlert(seleniumVariableName)
#1
Checks for JavaScript Alert, stores the alert message. If no alert generated then throws an exception. Getting an alert has the same effect as manually clicking OK. If an alert is generated but you do not get/verify it, then the next Selenium action will fail. JavaScript alerts will NOT pop up a visible alert dialog. Selenium does NOT support JavaScript alerts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.
Returns:
The message of the most recent JavaScript alert. Other Alert commands are: assertAlert ( pattern ), assertNotAlert ( pattern ), verifyAlert ( pattern ) verifyNotAlert ( pattern ),waitForAlert ( pattern ),waitForNotAlert (pattern)
Discover the automating power of Selenium
Copyright 2008-2010 by Kangeyan Passoubady (Kangs)
19
AlertPresent
This command never throws an exception
#2
verifyAlertPresent() The best way to check the alerts are using this command
Returns:
True or False. Other AlertPresent Commands are: storeAlertPresent ( seleniumVariableName ) assertAlertPresent ( ) assertAlertNotPresent ( ) verifyAlertNotPresent ( ) waitForAlertPresent ( ) waitForAlertNotPresent ( )
20
Alert Download the ClickAlert.html under the Alert section Record a test Are you able to test it?
(This is do-able)
#3
21
Alert
On load Alert will not be sensed by Selenium. You need to manually press Ok to continue the test.
#4
22
goBack
#1
goBack and goBackAndWait are the two commands simulates a user clicking on the back button of the browser. Download the SelectAWebSite.html under Exercises.
23
goBackAndWait
#2
waitForPopup
#1
waitForPopUp ( windowID,timeout ) and selectWindow ( windowID ) are the two commands allows you to test the Popup Windows. selectWindow selects a specific Popup, use null to select Parent window. Download Ex1.html to Ex3.html under wait for Popup, Open CreatePopUps.html in Firefox browser.
25
waitForPopup
#2
26
Navigator Properties
To get Browser information, you can use navigator object The common properties of navigator object is like
appName appCodeName appEnabled JavaEnabled language cookieEnabled navigator.userAgent navigator.plugins navigator.platform navigator.mimeTypes
#1
27
Navigator Properties
#2
Download Test Case Navigator Properties.html from the Exercises Section Run the Test Case Look at the Selenium IDE Log You can See all the Navigator Properties
28
Navigator Properties
#3
29
#1
Create a Test Suite based on the previous exercises: Well use the following three test cases to create one Test Suite (Test Script Package) Test Case Alert Button Click.html Test Case Navigator Properties.html Reviewed Test Case Popup.html
Use the test cases which are reviewed and working well.
30
#2
<tr><td><a href="Test Case Alert Button Click.html">Test Case Alert Button Click</a></td></tr> <tr><td><a href="Test Case Navigator Properties.html">Test Case Navigator Properties</a></td></tr> <tr><td><a href="Reviewed Test Case Popup.html">Test Case Creating Popups</a></td></tr>
Use the test cases which are reviewed and working well.
Discover the automating power of Selenium
Copyright 2008-2010 by Kangeyan Passoubady (Kangs)
31
#3
32
#4
Open the Firefox browser Open the Selenium IDE Select File Open Test Suite Choose the Test Suite on Commands.html from your local folder Press the TestRunner icon to run the test suite It will show the Test Suite in the firefox browser Click the Run All Tests button to run all the test cases Click the Run the Selected Tests button to run a specific test case
Discover the automating power of Selenium
Copyright 2008-2010 by Kangeyan Passoubady (Kangs)
33
#5
34
35
Exercise 1 Questions
Answer the below Questions once you complete your Devry Popup Window Test Case: What are the Popups link works without any problem? Why one of the Popups assertTitle produces an Error?
36