0% found this document useful (0 votes)
680 views4 pages

Selenium Tips and Tricks Guide

Selenium tips and tricks document provides various recommendations for using Selenium including: checking the reference manual for commands, using assert over verify, dealing with timeouts, dealing with browser and certificate issues, capturing screenshots, removing hardcoded values, and using AutoIT scripts to handle browser dialogs. It also provides links to additional Selenium FAQ documents.

Uploaded by

Ravi Sankar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
680 views4 pages

Selenium Tips and Tricks Guide

Selenium tips and tricks document provides various recommendations for using Selenium including: checking the reference manual for commands, using assert over verify, dealing with timeouts, dealing with browser and certificate issues, capturing screenshots, removing hardcoded values, and using AutoIT scripts to handle browser dialogs. It also provides links to additional Selenium FAQ documents.

Uploaded by

Ravi Sankar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Selenium Tips and Tricks/FAQ

 Do check the reference manual here to get concepts of selenium locators


and the various commands that are available. You could get condensed version of the
manual here.

Without reading the manual - You may easily miss useful commands like pause(to test
session timeout), storeHtmlSource (you can potentially apply selenium regular expression
to verify the values of hidden variables insides that html) , typeKeys (to do things like
page up etc)
 Assert vs verify: If you use seleniums verify command - then the test suite/case - will still
run - and fail at the end. Hence in most cases you should use assert command which will
cause the test to stop.
 Sometimes selenium IDE may use "click" instead of "clickAndWait" for some
"submit" button cases resulting in your next page's assert/verify to fail. Hence
you should change it manually or add waitForPageToLoad with some timeout.
 If the recording is not working - then go to firefox and click on "Tools->Add on ->
Selenium IDE " .First disable it and then enable it and restart the browser. Sometimes
clicking on Selenium IDEs
Options->HTML Format helps.
 If web site does not allow itself to be frameable then use -multiwidow option(instead of
-interactive) with selenium rc.
 To eliminate certificate warning(and work cross domains ) use chrome/iehta modes -
which is now default(as compared with rc beta1 version)
[Link]
 If you check selenium rc options eg "java -jar [Link] -h"
then you will find that it has a "timeout" option. But that timeout is for the overall
run(and not for individual "clickAndWait" ) . Hence you may be advised to use
"setTimeOut" via your
java program or in case of HTML use -Selenium IDE open test case-> Add Insert new
command
-> setTimeout with value(not Target) of say 240000 (ms)
 Selneium has this cool - captureEntirePageScreenShot command which works
well with IDE/HTML . Consider using it at critical points(to debug
issues, if you schedule your test cases).
But with programming language like java - it may not work(try
using the experimental - captureScreenshot .
 Consider writing a wrapper for your TestCase/TestSuite in .net/jsp
so that you can maintain your testcase/test suite in HTML.
 Sometimes the browsers or the java process may not get killed after the test is run.. So
you may need to manually
kill it(you can try to use some automated tools like Pskill on Windows ).
 When your client java test (using RC) finishes with error - then it does not give clear
error -
you just the line number of the failed assert in stack trace - Hence you may need to trap
all exceptions and - print the last body test
 If you are testing with page where the id dynamically changes - then You may need to
use lots of xpath in your test . In that case install firebug and use "Inspect element" by
right clicking on the element -> Copy XPath by right click on bottom-> Add "/" in front
of value you got in your clipboard-> paste this as a "target" in Selenium IDE for your
"clickAndWait" command. You can check the validility by - click on find button in
Selenium IDE to ensure that your XPath is correct(assuming that page is open) . You may
find more tip on xpath using firebug/xpather here
 If you are using Selenium HTML test case - then one way to remove hard coded values
in your selenium test is to have simple JSP(or asp/php) that converts CSV file to HTML
file.
Then you just need to invoke that JSP page (for particular CSV) - and call various "store"
values
and replace hard coded values in your test with "get" values .
That way you can just change your test/data by just replacing the CSV file.
 Do use (minor) javascript in HTML test case. You would need javascript to access stored
values anyway.
eg store 1 abc (store on one page)
, type id javascript{storedVars['abc'].toUpperCase()} (extract or evaluate it on another
page)

However if ther are too much javascripts - consider use programming languate.

 The latest selenium rc(1.0 beta 2) does support Firefox 3..


With firefox 3 you can easily add your local https server with invalid certificate in safe
list(to remove warning message).
Its difficult to do that with Firefox 2.
 If you are running selenium rc test with IE a site which already has invalid certificate -
then IE will give a warning for "invalid certificate". You can have selenium
automatically click on "Continue" link in it(which has ID of overridelink) by adding
below command in your IE specific test case.
<tr>
<td>clickAndWait</td>

<td>//a[@id='overridelink'] </td>

<td></td>

</tr>
With firefox 3 - you can permanently store the exception. However selenium -rc starts
new firefox profile every time(probably to get around lock issues) - hence you may
need to start firefox with same/particular profile.

You may also consider changing IE options to be strict (eg Tool->Internet Options-
>Advanced->Display
Notification on every script error) to have selenium catch any javascript issues/bugs in
your website.

 Consider use of UI-Element - which is now supported in RC here

 There are other good tips here.

9-important-tips-for-selenium-remote-control-java-client-test-tool
Selenium core faq(eg permission denied) - Must read
Selenium rc Faq - Must read

 How to run the generated java Test file?


This is really a JUnit question but in short you can add the following code in the
generated file to get it running:

public static Test suite() {


return new TestSuite([Link]);
}

public static void main(String args[]) {


[Link](suite());
}

Note: Replace SeleniumSTSanityTest with the name of your Java source file (without
the .java extension)

 if you read above FAQ - you will realize selenium has limitation in IE with certain dialog
box(eg upload file, basic auth). You can get around some of the limitation with autoit
script
from this site.
Its advisable not to directly download the exe from above site - but rather install autoit,
compile autoit script - from one of it program menus options - to Exe and than use the
compiled exe.
For whatever reasons (firefox does not expose its model)- the above scripts(or autoit)
does not help in Firefox dialog boxes(but you dont need it anyway as in chrome mode -
selenium automatically gets rids of dialog boxes)
However if you are trying to get rid of basic authentication dialog - you can directly pass
user/pass in URL.(however for IE you would need to add some registery settings)

PS: Autoit and autohotkey seem to have same codebase - and both have primitive
recorder.
(else we probably wont have needed selenium)
But in autoit vs autohotkey - I will give slight edge to autoit.
NOTE: On windows - you should use 'start' in front of exe/.au3 file to make it run in
background -
and then run your selenium rc test in the same batch file(eg start autotItscript.au3)

You might also like