Software Testing Lab
Software Testing Lab
Automation
offers automation wizards and commands of its own in addition to providing a task
recording and re-play capabilities. Using these programs you can record an IT or
business task.
Benefits of Automation
1. Fast
2. Reliable
3. Repeatable
4. Programmable
5. Reusable
6. Makes Regression testing easy
7. Enables 24*78 Testing
8. Robust verification.
Automation
Document Manual
test Steps
Create Basic
Test
Confirm successful
1
STV LAB MANUAL
playback
Enhance Basic
Test
Add
Synchronization
Integrate Tests
Pass Data
Build integrated
test sets
2
STV LAB MANUAL
INTRODUCTION TO SELENIUM
1. History of Selenium
Thoughtworks.
2. What is Selenium?
3. Selenium Components
– Selenium IDE
– Selenium Core
– Selenium RC
– Selenium Grid
3
STV LAB MANUAL
• It is Firefox plug-in
• Based on Selenese
B. Toolbar
C.Menu Bar
D.Log/Reference/UI-Element/Rollup Pane
B. Toolbar: The toolbar contains buttons for controlling the execution of your
. Page 5
C. Menu Bar:
4
STV LAB MANUAL
can set the timeout value for certain commands, add user-defined user
extensions to the base set of Selenium commands, and specify the format
D. Help Menu:
The command set is often called selenese. Selenium commands come in three
“flavors”:
something.
application.
2. Selecting items
b. Accessors: Accessors examine the state of the application and store the
NOTE:
5
STV LAB MANUAL
These are probably the most commonly used commands for building test.
page to load.
verifyText - verifies expected text and it’s corresponding HTML tag are present on
the page.
a. Remember Base URL MODE - Using Base URL to Run Test Cases in Different Domains
Run a Test Case Click the Run button to run the currently displayed test case.
6
STV LAB MANUAL
Run a Test Suite Click the Run All button to run all the test cases in the currently
Stop and Start The Pause button can be used to stop the test case while it is
running. The icon of this button then changes to indicate the Resume button. To
Stop in the Middle You can set a breakpoint in the test case to cause it to stop on a
particular command. This is useful for debugging your test case. To set a
breakpoint, select a command, right-click, and from the context menu select
Toggle Breakpoint.
Start from the Middle You can tell the IDE to begin running from a specific
command in the middle of the test case. This also is used for debugging. To set a
startpoint, select a command, right-click, and from the context menu select
Run Any Single Command Double-click any single command to run it by itself.
This is useful when writing a single command. It lets you immediately test a
command you are constructing, when you are not sure if it is correct. You can
double-click it to see if it runs correctly. This is also available from the context
menu.
Test Suite:
A test suite is a collection of tests. Often one will run all the tests in a test suite as
When using Selenium-IDE, test suites also can be defined using a simple HTML
file. The syntax again is simple. An HTML table defines a list of tests where each
Using Firefox, first, download the IDE from the SeleniumHQ downloads page
Firefox will protect you from installing addons from unfamiliar locations, so you
7
STV LAB MANUAL
will need to click ‘Allow’ to proceed with the installation, as shown in the
following screenshot.
When downloading from Firefox, you’ll be presented with the following window.
Select Install Now. The Firefox Add-ons window pops up, first showing a progress
Restart Firefox. After Firefox reboots you will find the Selenium-IDE listed under
To run the Selenium-IDE, simply select it from the Firefox Tools menu. It opens as
follows with an empty script-editing window and a menu for loading, or creating
8
STV LAB MANUAL
EXPT NO:-2 Using Selenium IDE, Write a test suite containing minimum 4 test
cases.
TC’S #2:
1. Create more Tc’s save each Test Case with <.html> extension.
2. Open Firefox
9
STV LAB MANUAL
EXPT NO:-3 Conduct a test suite for nay two web sites.
TC#2:
(Select and
present.)
7: Verify the browsers title has the value "energy efficient - Yahoo! Search
Results"
1. Create more Tc’s save each Test Case with <.html> extension.
2. Open Firefox
10
STV LAB MANUAL
Selenium-RC
1. Introduction
Selenium-RC is the solution for tests that need more than simple browser actions
complex tests like reading and writing files, querying a database, emailing test
results.
You’ll want to use Selenium-RC whenever your test requires logic not supported
by Selenium-IDE.
What logic could this be? For example, Selenium-IDE does not directly support:
• condition statements
• iteration
• database testing
Although these tasks are not supported by Selenium directly, all of them can be
client library.
11
STV LAB MANUAL
Java/PHP
Download Eclipse
1. Go to URL – http://www.eclipse.org/downloads/
2. Select Eclipse IDE for Java Developers (Click on Windows 32 bit platform)
6. Create Eclipse desktop shortcut (go to C:Eclipse folder –> right click
WorkspaceSeleniumTests
2. Download Selenium Client driver for Java (from Selenium Client Drivers
section)
12
STV LAB MANUAL
Downloading and unzipping the files into a folder is done. We need to configure
1. Go to Eclipse –> Click File –> New –> Project (from various options need to
2. In Select Wizard –> Click Java –> “Java Project” (demonstrated in the below
figure)
5. Now we are done with creation of project and need to configure the
11. Click OK
12.Referenced libraries –> contains both the Selenium Client driver jar files as
Selenium RC allows to write the automated tests in any language. Selenium Scripts
Class
13
STV LAB MANUAL
Before you start with your script, the following are the steps that should be
performed.
control-1.0.3\selenium-java-client-driver-1.0.1\selenium-javaclientdriver.
import com.thoughtworks.selenium.SeleneseTestCase;
setUp("http://www.hexbytes.com/", "*firefox");
selenium.open("/");
selenium.click("css=input[type='submit'][value='Search']");
selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent("selenium rc"));
7.Click on the RunAs button and run the script as JUnit Test. If you don’t
find the option Install the JUnit plug-in and run the script.
14
STV LAB MANUAL
Some times we need the selenium scripts to contact the server running on a
different port and different machine. You can configure the selenium scripts to
class.
package test;
import junit.framework.*;
import com.thoughtworks.selenium.DefaultSelenium;
selenium=new
DefaultSelenium("localhost",4444,"*iexplore","http://hexbytes.com");
selenium.start();
selenium.open("/");
selenium.click("css=input[type='submit'][value='Search']");
selenium.waitForPageToLoad("30000");
Assert.assertTrue(selenium.isTextPresent("selenium rc"));
15
STV LAB MANUAL
EXPT NO:-5 Write and test a program to login a specific web page.
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;
@Before
"http://demo.opensourcecms.com/");
selenium.start();
@Test
selenium.open("/wordpress/wp-login.php");
selenium.type("id=user_login", "admin");
selenium.type("id=user_pass", "demo123");
selenium.click("id=wp-submit");
selenium.waitForPageToLoad("30000");
@After
selenium.stop();
16
STV LAB MANUAL
TestNG
TestNG is a testing framework inspired from JUnit and NUnit but introducing
some new functionalities that make it more powerful and easier to use, such as:
(all methods in their own thread, one thread per test class, etc...).
integration, etc...
17
STV LAB MANUAL
even programatically. We are going to use the Eclipse plugin. Follow the
recommended in order to handle large amount of test data. To read data from
Excel, we need APIs which support opening file, reading data, and writing data
into Excel. We should know various classes and methods which support above
mentioned operations. In this post, let us try to figure out which is the API that
Jxl.jar is an open source Java API which supports read Excel spreadsheets and to
write into Excel spreadsheets. Below are some of the operations that we can
3. Generate spreadsheets
To access the methods and classes provided by this API inside Eclipse we need to
add this JAR file to the Java Build Path. (I have explained steps to add external Jar
18
STV LAB MANUAL
Add import statements to the .java file as below to read from an Excel spreadsheet
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
19
STV LAB MANUAL
EXPT NO :-6 Write and test a program to update 10 student records into table
import java.io.FileInputStream;
import java.io.FileOutputStream;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.testng.annotations.*;
@BeforeClass
@Test
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
20
STV LAB MANUAL
ws.addCell(l2);
ws.addCell(l1);
int x=Integer.parseInt(a[i][j]);
ws.addCell(l1);
else
ws.addCell(l1);
break;
wwb.write();
wwb.close();
21
STV LAB MANUAL
INPUT
OUTPUT
EXPT NO :-7 Write and test a program to select the number of students who have
import java.io.FileInputStream;
import java.io.FileOutputStream;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.testng.annotations.*;
@BeforeClass
@Test
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
int c=0;
22
STV LAB MANUAL
if(i >= 1)
b=s.getCell(3,i).getContents();
int x= Integer.parseInt(b);
. Page 28
c++;
break;
ws.addCell(l2);
wwb.write();
wwb.close();
INPUT
OUTPUT
23
STV LAB MANUAL
EXPT NO :-8 Write and test a program to provide total number of objects present
package testscripts;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
@BeforeClass
seleniumserver.start();
selenium.start();
@Test
selenium.open("http://www.google.co.in/");
selenium.windowMaximize();
String lc[]=selenium.getAllLinks();
System.out.println("TOTAL NO OF LINKS="+lc.length);
String bc[]=selenium.getAllButtons();
System.out.println("TOTAL NO OF BUTTONS="+bc.length);
String fc[]=selenium.getAllFields();
24
STV LAB MANUAL
@AfterClass
selenium.stop();
seleniumserver.stop();
OUTPUT
TOTAL NO OF LINKS=41
TOTAL NO OF BUTTONS=1
25
STV LAB MANUAL
EXPT NO :-9 Write and test a program to get the number of list items in a list /
combo box.
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
@BeforeClass
seleniumserver.start();
selenium.start();
@Test
selenium.open("http://www.schools9.com/kdiploma11022011.htm");
selenium.waitForPageToLoad("3000");
26
STV LAB MANUAL
out.write(""+option[i]);
out.newLine();
out1.write(""+option[i]);
out1.newLine();
out.close();//excel
out1.close();//notepad
@AfterClass
selenium.stop();
seleniumserver.stop();
OUTPUT
27
STV LAB MANUAL
EXPT NO :-10 Write and test a program to count number of check boxes on the
package testscripts;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
@BeforeClass
seleniumserver.start();
selenium.start();
@Test
selenium.open("http://browsershots.org/");
selenium.windowMaximize();
Number c =selenium.getXpathCount("//input[@type['checkbox']]");
28
STV LAB MANUAL
@checked]");
not(@checked)]");
@AfterClass
selenium.stop();
seleniumserver.stop();
OUTPUT
29