Contents
Command =pause
Target = ( delay in milliseconds )
If a command needs to be inserted between 2 lines.
Right click on the bottom line >Select
Insert New Command
Command
|
Target
|
Value
|
open
|
/
|
|
verifyTitle
|
Google
|
|
type
|
id=gbqfq
|
helloselenium
blog
|
click
|
id=gbqfb
|
|
waitForElementPresent
|
//em[contains(text(),'Hello
Selenium')]
|
|
verifyTitle
|
helloselenium
blogspot - Google Search
|
|
clickAndWait
|
//em[contains(text(),'Hello
Selenium')]
|
|
verifyTitle
|
Hello
Selenium
|
|
How to
declare a variable?
Command - store
(keyword)
Target – give
Data here
Value –
Variable Name
How to display
contents of variable?
Command (Use keyword) - echo
Target -
${Variable Name}
Command (keywords)
1.
Store: Command to tell Ide to store Target inside the Variable.
2.
Echo : To Display variable or value
Target (Target Data)
1.
${} - Used along with echo to display the contents
of a variable. (Ex: echo ${var})
2.
javascript{} - Contents within
the brackets are JavaScript commands
3.
new Date().getHours()
4.
new Date().getMinutes()
5.
new Date().getSeconds()
6.
new Date.getMonth()
7.
new Date.getDate()
8.
new Date.getFullYear()
9.
+
Value: Contains Variable name
In the screenshot below:
1. Date
is a variable name , contains todays
date
2. Time
is also variable name, contains current Time.
3. Timestamp
is also a variable name , contains
following data:-
Test_${Data}
${Time}
=
Test_10/22/13 12:20
Check if
the object exists
Use Command:
verifyElementPresent
Target: xpath (directly use -- //h1[@class='warning'))
Eg
(“ xpath = //h1[@class='warning']”)
------Xpath
2. Use the
above url to add a plug-in to Firefox (Ide should already have to be installed
)
Note: Save the file with “.html” Extension
Assert Commands: Quit test
Case on Fail
Verify Commands: Continue
even if fails
New Test
|
Command
|
Target
|
Value
|
open
|
http://www.wikipedia.org/
|
|
verifyAttribute
|
css=input
+ input@id
|
searchInput
|
assertAttribute
|
css=input
+ input@id
|
searchInput
|
verifyAttribute
|
css=input
+ select@name
|
language
|
verifyAttribute
|
xpath=//div[2]@class
|
central-featured
|
verifyAttribute
|
xpath=//input[@type='search']@name
|
search1
|
assertAttribute
|
xpath=//div[2]@class
|
central-featured
|
assertAttribute
|
css=input
+ select@name
|
anguage
|
verifyAttribute
|
css=input
+ input@id
|
searchInput
|
Various Pattern syntaxes are
available for matching string values:
glob: pattern
Match a string
against a "glob" (aka "wildmat") pattern. "Glob"
is a kind of limited regular-expression syntax typically used in command-line
shells. In a glob pattern, "*" represents any sequence of characters,
and "?" represents any single character. Glob patterns match against
the entire string.
regexp: regexp
Match a
string using a regular-expression. The full power of JavaScript
regular-expressions is available.
exact: string
Match a
string exactly, verbatim, without any of that fancy wildcard stuff.
If no pattern prefix is
specified, Selenium assumes that it's a "glob" pattern.
Using Regular Expression Pattern to select label from drop down in
selenium
New Test
|
Command
|
Target
|
Value
|
open
|
http://www.ebay.com
|
|
select
|
gh-cat
|
label=regexp:.*am.*
P.*
|
Using Regular Expression Pattern verify dynamic text pattern
New Test
|
Command
|
Target
|
Value
|
open
|
http://software-testing-tutorials-automation.blogspot.in/2013/06/matching-text-patterns-globbing.html
|
|
verifyTextPresent
|
regexp:Friday.*[0-9]{4}
|
|
Using Regular
Expression Pattern to click on link in selenium
New Test
|
Command
|
Target
|
Value
|
open
|
http://software-testing-tutorials-automation.blogspot.in/
|
|
clickAndWait
|
link=regexp:.*bo.*
M.*
|
|
You can try with
storeAllWindowIds , storeAllWindowTitles
Or you can
try this Javascript.
javascript:{var
windowtitles=selenium.getAllWindowTitles();
selenium.doSelectWindow(windowtitles[1]);}
If you want to perform some actions
on new opened popup window then you need to select that popup first then and
then you can perform any action on new window
New Test
|
Command
|
Target
|
Value
|
open
|
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_a_target
|
|
verifyTextPresent
|
Open
link in a new window or tab
|
|
click
|
link=Visit
W3Schools!
|
|
pause
|
2000
|
|
selectPopUp
|
W3Schools
Online Web Tutorials
|
|
waitForTextPresent
|
Learn
to Create Websites
|
|
verifyTextPresent
|
Learn
to Create Websites
|
|
deselectPopUp
|
|
|
verifyTextPresent
|
Open
link in a new window or tab
|
|
verifyTextPresent
|
Learn
to Create Websites
|
|
selectPopUp
|
W3Schools
Online Web Tutorials
|
|
verifyTextPresent
|
Learn
to Create Websites
|
|
Scenario:
- Page loads with a JavaScript
that adds an iframe to the DOM <iframe id="iframeId" />
- iframe loads
- Now I want to check for an
element within the iframe <div
id="divElement"></div>
Solution:
(Command
> C, Target > T, Value > V) If I didn't include, it means leave it
blank
- C: open
| T: /
- C: waitForElementPresent
| T: iframeId
| V: 3000
- C: waitForFrameToLoad
| T: iframeId
| V: 5000
- C: selectFrame
| T: iframeId
- C: assertElementPresent
| T: css=div#divElement
- C: verifyElementPresent
| T: css=div#divElement
Ø Manual
IDE commands will need to be entered to complete your script.
Ø To
identify elements in a pop-up, you will need to use the 'selectPopup' command
to focus into the pop-up.
Ø To
identify elements within an iframe, use the 'selectFrame' command and enter the
iframe id into the Target parameter. Using the 'selectFrame' command without a
target id may silently fail, depending on page structure (may have multiple
iframes etc).
E.g.:
New
Test
|
Command
|
Target
|
Value
|
click
|
link=AltaVista.com
|
|
selectFrame
|
name=iframe1
|
|
waitForElementPresent
|
link=Images
|
|
clickAndWait
|
link=Images
|
|
selectFrame
|
relative=up
|
|
click
|
link=AOL.com
|
|
selectFrame
|
name=iframe1
|
|
waitForElementPresent
|
id=ghnav-news
|
|
clickAndWait
|
id=ghnav-news
|
|
New
Test
|
Command
|
Target
|
Value
|
open
|
http://www.bing.com
|
|
storeTitle
|
i
|
|
openWindow
|
https://www.google.com
|
|
pause
|
5000
|
|
selectWindow
|
Google
|
|
clickAndWait
|
css=#gb_2
> span.gbts
|
|
storeTitle
|
j
|
|
selectWindow
|
${i}
|
|
clickAndWait
|
css=#scpt1
> a
|
|
storeTitle
|
i
|
|
selectWindow
|
${j}
|
|
close
|
i
|
|
selectWindow
|
${i}
|
|
close
|
|
|
|
|
|
|
For this you will need to use the selectWindow
| windowName command.
To go back to the main window from
the other window then do selectWindow | null
Arguments:
In
some cases, you can force Selenium to notice the open window's name by using
the Selenium openWindow command, using an empty (blank) url, like this:
openWindow("", "myFunnyWindow").
selectWindow(windowID)
If it is a popup then do selectPopUp | windowId and then to go back to the main
window do selectWindow
| null
selectPopUp(windowID)
Arguments:
* windowID - an identifier for the popup window, which can take on a
number of different meanings
* If windowID is either not specified, or specified as "null",
the first non-top window is selected. This should not be used when more than one
popup window is in play.
You can open the other window
(considered popup by selenium i guess) like so
selenium.openWindow("http://example.com/","dev");
selenium.selectWindow("dev");
selenium.open("/");
And then you switch b/w the windows.
To go back to original one you will have to do
selenium.selectWindow(null);
Print array values using selenium IDE
<tr>
<td>echo</td>
<td>${ans}</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>javascript{storedVars['ans'].split('/');}</td>
<td>final</td>
</tr>
<tr>
<td>echo</td>
<td>${final}</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>javascript{storedVars['final'][0];}</td>
<td></td>
</tr>
TC_StoreVars
|
store
|
ABD:XYZ:123
|
v
|
echo
|
${v}
|
|
echo
|
javascript{storedVars['v'].split(':').length}
|
|
echo
|
javascript{storedVars['v'].split(':')[2]}
|
|
New Test
|
Command
|
Target
|
Value
|
storeEval
|
new
Array("car","truck", "Bus",
"motorcycle", "bicycle");
|
vehicles
|
getEval
|
myitems=0;
|
|
while
|
myitems
< storedVars['vehicles'].length
|
|
storeEval
|
myitems
|
myvar
|
echo
|
javascript{storedVars['vehicles'][storedVars['myvar']]}
|
|
getEval
|
myitems++;
|
|
endWhile
|
|
|
In above
example,
1.
"storeEval"
command will create one array to store all vehicle's values.
2.
"getEval"
command will store value 0 in variable 'myitems'.
3.
while
loop will rotate until end of the array item
4.
echo
command will print related values in log every time.
Execute above
script in your selenium IDE first then you can use same parameterisation method
with your software application test script.
storeEval
Using
storeEval command you can directly assign or print value of a variables without
help of 'javascript{}' in the target.
Ex:
Command: storeEval
Target: storedVars['a']
value: c
Observe that in the above example we are directly calling storedVars['a'] to
assign value of variable ‘a’ to ‘c’.
How to add value 10 to
variable ‘a’ and assigning it to variable ‘d’ ?
Command: storeEval
Target: storedVars['a']+10
value: d
Now if you try to print value of ‘d’ using echo command, then it will print
string "1000+10" but not "1010". This is because the return
value of storedVars['a'] in the target is being treated as a string. In order
to avoid this, we need to type caste it to a number as follows,
Command: storeEval
Target: new Number(storedVars['a'])+10
Value: d
storeAttribute ( attributeLocator, variableName
)
Example :
storeAttribute | xpath=//html/body/div/div[2]/p/em/a/@href | var
openAndWait | ${var}
1.
‘@href’ retrieves href property from the element.
2.
var
contains “url” of the element
http://webigniter.wordpress.com/2011/04/07/storing-variables-in-selenium-ide/