+ All Categories
Home > Documents > Selenium Testing

Selenium Testing

Date post: 27-Nov-2014
Category:
Upload: shreshtt-bhatt
View: 1,723 times
Download: 3 times
Share this document with a friend
Description:
 
Popular Tags:
31
PowerPoint Presentation on SELENIUM TESTING
Transcript
Page 1: Selenium Testing

PowerPoint Presentation on

SELENIUM TESTING

Page 2: Selenium Testing

WHAT IS SELENIUM ?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.

Page 3: Selenium Testing

WHERE TO GET IT• 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/

Page 4: Selenium Testing

Selenium Components

Page 5: Selenium Testing

• 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.

Selenium-IDE

Page 6: Selenium Testing

• 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.

Page 7: Selenium Testing

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.

Selenium-RC (Remote Control)

Page 8: Selenium Testing

Selenium-RC (Remote Control)

Page 9: Selenium Testing

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.

Selenium-Grid

Page 10: Selenium Testing

This allows for running tests in parallel, with the entire test suite theoretically taking only as long to run as the longest individual test.

Page 11: Selenium Testing

Steps to start with Selenium!

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.

Selenium-IDE

Page 12: Selenium Testing

STEP 2 – running a simple test : a. Start Selenium IDE  in Firefox: Tools->Selenium IDE. You will see the following

popup. The list ofactions in theactual test caseto execute

The root of web application youwant to test

The log of theevents that wereexecuted, includingany errors orwarning that mayhave occurred

Page 13: Selenium Testing

ExecutionCommands

Record testactions

Specify commands,including asserts

Reference of thecurrently selectedcommand

Page 14: Selenium Testing

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.

Page 15: Selenium Testing

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.

Page 16: Selenium Testing

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.

Page 17: Selenium Testing
Page 18: Selenium Testing

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.

Page 19: Selenium Testing

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.

Page 20: Selenium Testing

Selenium-RCInstallation-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.

Page 21: Selenium Testing

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

Page 22: Selenium Testing

Server Start selenium Server

Page 23: Selenium Testing

• 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.columbia.edu/site_media/selenium/TestRunner.html

Page 24: Selenium Testing

Run a HTML test suite using Selenium-RCAfter 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:\absolute\path\to\my\HTMLSuite.html")* resultFile (e.g. "c:\absolute\path\to\my\results.html")

Follow these steps to run the suite:

1.    Create a HTML file that will keep your test results2.    Open a command line3.    cd to the selenium-server.jar location.

For example: cd E:\java\selenium\selenium-server-standalone-2.1.0.jar

Page 25: Selenium Testing

4.    Run the command with the required arguments. For examplejava -jar selenium-server.jar -port 4546 -htmlSuite *firefox "http://www.google.com" "c:\SeleniumTest\TestSuite.html" "C:\test.html"You will see how Test runner is invoked and starts running the test in Firefox

Page 26: Selenium Testing

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.

Page 27: Selenium Testing

Selenium-GridHow 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.

Page 28: Selenium Testing

• 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

Page 29: Selenium Testing

• 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 MachineNow 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:

Page 30: Selenium Testing

Host Port Environment

localhost 5555 *firefox

localhost 5556 *firefox

localhost 5557 *firefox

localhost 5558 *firefox

Available Remote Controls

Launch the tests in parallel in a new terminal: ant run-demo-in-parallel

Page 31: Selenium Testing

Recommended