2. Selenium is a portable software testing framework for web
applications. Selenium provides a record/playback tool for
authoring tests without learning a test scripting language.
Selenium provides a test domain specific language (DSL) to
write tests in a number of popular programming
languages, including C#, Java, Groovy, Perl, PHP, Python
and Ruby. Test playback is possible in most modern web
browsers. Selenium deploys on Windows, Linux, and
Macintosh platforms.
It works anywhere JavaScript is supported. Selenium was
originally developed by Jason Huggins, who was later
joined by other programmers and testers at Thought Works.
It is open source software, released under the Apache 2.0
license and can be downloaded and used without charge.
3. • You can use Selenium-Core and customize
everything – deprecated.
• But it is easier to just get a Firefox plug-in
“Selenium-IDE” that helps you “record” test
Cases.
• You can record how an app is being used and then
playback those recordings followed by asserts.
• Get everything at: www.openqa.org/selenium/
4.
5. • Integrated Development Environment for building
Selenium test cases.
• Operates as a Firefox add-on and provides an interface for
developing and running individual test cases or entire test
suites.
• Selenium-IDE has a recording feature, which will keep
account of user actions as they are performed and store
them as a reusable script to play back.
• It also has a context menu (right-click) integrated with the
Firefox browser, which allows the user to pick from a list
of assertions and verifications for the selected location.
6. • Offers full editing of test cases.
• Although it is a Firefox only add-on, tests
created in it can also be run against other
browsers by using Selenium-RC &
specifying the name of the test suite on
the command line.
7. Selenium-RC (Remote Control)
Selenium Remote Control (RC) is a test tool that
allows you to write automated web application UI
tests in any programming language against any
HTTP website using any mainstream JavaScript-
enabled browser.
Selenium RC comes in two parts.
1. A server which automatically launches and kills
browsers, and acts as a HTTP proxy for web
requests from them.
2. Client libraries for your favorite computer
language.
8.
9. Selenium-Grid allows the Selenium-RC solution to
scale for test suites or test suites to be run in multiple
environments.
• With Selenium-Grid multiple instances of Selenium-
RC are running on various operating system and
browser configurations, each of these when
launching register with a hub. When tests are sent to
the hub they are then redirected to an available
Selenium-RC, which will launch the browser and
run the test.
10. This allows for running tests in parallel, with the entire
test suite theoretically taking only as long to run as the
longest individual test.
11. Selenium-IDE
STEP 1 – installation :
You can download Selenium IDE from this
locations.
http://selenium-
ide.openqa.org/download.jsp
https://addons.mozilla.org/en-
US/firefox/addon/2079
Once the add-on is installed make sure you
do not forget to restart Firefox.
12. STEP 2 – running a simple test :
a. Start Selenium IDE in Firefox:
Tools->Selenium IDE. You will see the following popup.
The list of
actions in the
actual test
case
to execute
The root of web
application you
want to test
The log of the
events that were
executed, including
any errors or
warning that may
have occurred
13. Execution Record test
Commands actions
Reference of the
currently selected
command Specify commands,
including asserts
14. b. Click on the red record button on the right.
c. Browse to Google.com and enter ‟selenium‟ in the
search box and click enter.
d. Click on the first result, which is that of
selenium.openqa.org.
e. Stop the recording by clicking on the record button.
You should see something like in next slide.
15. If you click on the „ Source‟ tab you can see the test html generated by selenium.
The „table‟ tab shows the commands recorded by Selenium.
16. f. Open a new tab in Firefox and click on the Selenium IDE‟s
play button to run the recorded test.
The IDE should play your recorded test. The IDE after the
test run is shown in next slide. In the „Log section‟ you can
see the various events run by the test. In the table tab you
can see that all the rows are green, which means that the test
ran successfully.
17.
18. Now lets add a small assertion to the above test.
a. Click on the blank line below after the last „clickAndWait‟
command and insert „assertTextPresent‟ command from
the drop down box as shown below. You should see
something like this.
19. This test checks to see if the text „Selenium News‟ is present in the last rendered
page. Run the test again and you should see that the test has run successfully. No
try replacing the text with something that is not present on the page, take for
example „elvis‟ and run the test again. Now the test fails and you should get the
screen below.
20. Selenium-RC
Installation-
Installation is rather a misnomer for Selenium. Selenium has set of
libraries available in the programming language of your choice. You
could download them from www.openqa.org/selenium/
Once you‟ve chosen a language to work with, you simply need to:
Install the Selenium RC Server.
Set up a programming project using a language specific client driver.
Installing Selenium Server-
• Ensure that JDK is present on the machine and is in the class path.
• The Selenium RC server is simply a Java jar file (selenium-server-
standalone-<version-number>.jar), which doesn‟t require any special
installation. Just downloading the zip file and extracting the server in
the desired directory is sufficient.
21. Creating a Selenium Test Case in Java
• I assume you have Eclipse installed
• I assume you have downloaded the Selenium RC
1. The files selenium-server.jar and selenium-java-client-
driver.jar will be needed
• In Eclipse create a new Java Project
1. Add the selenium-java-<version-number>.jar files to
your project as references.
2. Add to your project class path the file selenium-java-
<version-number>.jar.
3. Finish
• Right click on the src folder and create a new JUnit Test Case
• You should now be looking at the JUnit test case class in the
editor
23. • Once you have the server running, in Eclipse you want to
run the test case as a JUnit Test
For details on Java test project configuration, see the Appendix
sections
Configuring Selenium RC With Eclipse
SEE DEMO OF TESTRUNNER.HTML
http://masivukeni.ccnmtl.columbi
a.edu/site_media/selenium/TestR
unner.html
24. Run a HTML test suite using Selenium-RC
After you generated your HTML suite file, you can run the suite using –
htmlSuite command.
-htmlSuite requires you to specify:
* browserString (e.g. "*firefox")
* startURL (e.g. "http://www.google.com")
* suiteFile (e.g. "c:absolutepathtomyHTMLSuite.html")
* resultFile (e.g. "c:absolutepathtomyresults.html")
Follow these steps to run the suite:
1. Create a HTML file that will keep your test results
2. Open a command line
3. cd to the selenium-server.jar location.
For example: cd E:javaseleniumselenium-server-standalone-2.1.0.jar
25. 4. Run the command with the required arguments. For example
java -jar selenium-server.jar -port 4546 -htmlSuite
*firefox "http://www.google.com"
"c:SeleniumTestTestSuite.html" "C:test.html"
You will see how Test runner is invoked and starts running the test in Firefox
26. In case Test runner does not start running the test cases, ensure pop-up
windows are enabled in your browser.
After the test script is done, you can check the test results in the HTML file
you provided as argument.
27. How to set up selenium Grid
• You will need to download and install the latest Java JRE on your
system. You can find this at http://java.sun.com .
• You need to check that you have Apache Ant. If you open up a
terminal/command prompt and type ant -version. If it doesn't return an
error then you should be fine. If it returns an error you will need to
download Apache Ant and expand the archive to a folder on hard drive.
• You will need to now download Selenium Grid and put that in a folder
that is easy to access. Now that we have all the relevant parts installed
lets start the grid up.
• We are going to start up the Selenium Grid Hub first. Open up a
command prompt or terminal and navigate to the folder where the
Selenium Grid files are stored.
28. • From the command prompt run ant launch-hub. This will get the
hub running. To see it running put http://localhost:4444/console
into a browser and you will be shown a webpage with 3 columns.
The first column shows what Environments it can handle, the
second column shows what remote controls are available and the
third column shows what remote controls are currently running
tests. Like the following screenshot
29. • Now that we have our hub running, lets start up a remote control. Open up
another command prompt or terminal and navigate to the Selenium Grid folder.
Run ant launch-remote-control. This will launch a Selenium Remote Control for
handling Firefox on your OS on port 5555.
• We now have a Selenium Grid up and running.
Running the Tests in Parallel on Firefox on a Single Machine
Now let‟s start three more remote control instances. Launch them in separate
terminals:
ant -Dport=5556 launch-remote-control
ant -Dport=5557 launch-remote-control
ant -Dport=5558 launch-remote-control
You should now see a total of four remote controls available in the Hub console
http://localhost:4444/console:
30. Available Remote Controls
Host Port Environment
localhost 5555 *firefox
localhost 5556 *firefox
localhost 5557 *firefox
localhost 5558 *firefox
Launch the tests in parallel in a new terminal:
ant run-demo-in-parallel