ST Lab Manual
ST Lab Manual
List of Experiments:
2. Using Selenium IDE, Write a test suite containing minimum 4 test cases.
6. Write and test a program to update 10 student records into table into Excel file
7. Write and test a program to select the number of students who have scored more than 60 in any
one subject (or all subjects)
8. Write and test a program to provide total number of objects present / available on the page
9. Write and test a program to get the number of list items in a list / combo box
10. Write and test a program to count number of check boxes on the page checked and unchecked
count.
Exercise Number: 1
Date:
Aim:
Automation
Automation is making a process automatic eliminating the need for human intervention. It is a self-
controlling or self-moving process. Automation Software 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.
Reliable Repeatable
Programmable
Reusable
Makes Regression testing easy Enables
24*78 Testing
Robust verification.
1. History of Selenium
• Open source browser based integration test framework built originally by Thought
works.
2. What is Selenium?
JavaScript
DHTML
Frame
3. Selenium Components
– Selenium IDE
– Selenium Core
– Selenium RC
– Selenium Grid
Selenium IDE
• It is Firefox plug-in
• Firefox extension which allows record/play testing paradigm
• Automates commands, but asserts must be entered by hand
• Creates the simplest possible Locator
• Based on Selenese
Overview of Selenium IDE:
B. Toolbar
C. Menu Bar
D. Log/Reference/UI-Element/Rollup Pane
one for displaying the command (source) and their parameters in a readable “table”
format
B. Toolbar: The toolbar contains buttons for controlling the execution of your test cases,
including a step feature for
C. Menu Bar:
File Menu: The File menu allows you to create, open and save test case and test
suite files.
Edit Menu: The Edit menu allows copy, paste, delete, undo and select all
operations for editing the commands in your test case.
Options Menu: The Options menu allows the changing of settings. You can set
the timeout value for certain commands, add user-defined user extensions to the
base set of Selenium commands, and specify the format (language) used when
saving your test cases.
D. Help Menu:
The command set is often called selenese. Selenium commands come in three “flavors”:
Actions, Accessory and Assertions.
2. Selecting items
b. Accessors: Accessors examine the state of the application and store the results in
variables, e.g. "storeTitle".
assert
verify
waitFor
verifyText - verifies expected text and it’s corresponding HTML tag are present on the page.
Wait For Page To Load -pauses execution until an expected new page loads. Called automatically
when clickAndWait is used.
Run a Test Case Click the Run button to run the currently displayed test case.
Run a Test Suite Click the Run All button to run all the test cases in the currently loaded
test suite.
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 continue click Resume.
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 Set/Clear Start Point.
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 Suit
A test suite is a collection of tests. Often one will run all the tests in a test suite as one
continuous batch-job.
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 row defines the file
system path to each test.
Using Firefox, first, download the IDE from the SeleniumHQ downloads page Firefox will
protect you from installing addons from unfamiliar locations, so you will need to click
‘Allow’ to proceed with the installation, as shown in the following screenshot.
SOFTWARE TESTING LABORATORY
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 bar,
and when the download is complete, displays the following.
Restart Firefox. After Firefox reboots you will find the Selenium-IDE listed under the
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 new test
cases.
Result:
Thus the automation testing approach is using selenium IDE is carried out.
Exercise Number: 2
Date:
Aim:
To write a test suite containing minimum four test cases using selenium IDE
1. Create more Tc’s save each Test Case with <.html> extension.
2. Open Firefox
Output:
Result:
Thus a test suite containing minimum four test cases using selenium IDE is created
successfully
Exercise Number: 3
Date:
TC#2:
Verify "Java” text is present anywhere in the search results: (Select and highlight
anywhere in the search results page)
Save the test case
Output:
Result:
Thus a test suite for any two web sites is created successfully.
Exercise Number: 4
Date:
Aim:
Procedure:
1. Go to URL – http://www.eclipse.org/downloads/
2. Select Eclipse IDE for Java Developers (Click on Windows 32 bit platform)
3. Click on OK button and save to a local drive (i.e. C: or D:, etc)
4. Unzip the downloaded zip file and rename that to Eclipse
5. Create one more folder “Eclipse-Workspace” (i.e. C:Eclipse-Workspace)in the
same drive where Eclipse is unzipped and renamed.
6. Create Eclipse desktop shortcut (go to C:Eclipse folder –> right click Eclipse.exe
and then click on “desktop create shortcut”) as demonstrated in the below
pictures.
Downloading and unzipping the files into a folder is done. We need to configure
the appropriate Selenium Client driver Jar file to the Eclipse.
1. Go to Eclipse –> Click File –> New –> Project (from various options need
to select just “project”)
2. In Select Wizard –> Click Java –> “Java Project” (demonstrated in the
below figure)
Selenium RC allows to write the automated tests in any language. Selenium Scripts can
be written in various ways:
1. Extending the Selenese Test Case
2. Extending the TestCase-Junit and defining an object to the DefaultSelenium
Class
Before you start with your script, the following are the steps that should be
performed.
Method1: Extending the Selenese Test Case
Import com.thoughtworks.selenium.SeleneseTestCase;
public class SeleniumTest1 extends SeleneseTestCase { public
void setUp() throws Exception
{ setUp("http://www.hexbytes.com/", "*firefox");
}
public void testNew() throws
Exception{ selenium.open("/");
2. Click on the RunAs button and run the script as JUnit Test. If youdon’t find
the option Install the JUnit plug-in and run the script.
Output:
Result:
Thus the installation and demonstration of selenium server using a script in java/php
executed successfully.
Exercise Number: 5
Date:
Aim:
Procedure:
o Write the java script for creating a login page code in eclipse.
Program:
import com.thoughtworks.selenium.*;
@SuppressWarnings("deprecation")
public class login extends SeleneseTestCase {
}
public void testloginlogout()
selenium.setSpeed("2000"); selenium.open("/login.php");
selenium.windowMaximize(); selenium.type("//input[@name='username']", "mytest");
selenium.type("//input[@name='password']", "mytest");
selenium.click("//input[@type='button']"); selenium.waitForPageToLoad("50000");
}
}
Output:
Result:
Thus a login page for specific web page is created and tested successfully.
Exercise Number: 6
Date:
Procedure:
Write the java test code in eclipse. Since we are not using any Selenium object here
no need of selenium RC Server to run at the command prompt for this program.
This program will create an Excel file Student.xls under the desktop.
Since we are dealing with the excel, we need to add the external jar file jxl-2.6 in to
the java project.( download jxl-2.6 and Follow the same steps as we used to add
selenium server and selenium java driver to our java project refer page no 10 of this
manual.)
Program:
package Selenium;
import jxl.Cell;
import jxl.CellView;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.format.UnderlineStyle;
import jxl.read.biff.BiffException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Locale;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.Number;
import
jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import org.testng.annotations.*;
public class Ex6 {
@BeforeClass
public void setUp() throws Exception {}
@Test
public void testImportexport1() throws Exception
{ student_excel_write test = new
student_excel_write();
test.setOutputFile("D:/exp6.xls");
test.write();
System.out.println("created ");
checkExcelSheet();
System.out.println("checked");
}
// first code
private WritableCellFormat timesBoldUnderline;
Software Testing-16IT711 Page 26
SOFTWARE TESTING LABORATORY
private WritableCellFormat times;
UnderlineStyle.SINGLE);
timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
// Lets automatically wrap the cells
timesBoldUnderline.setWrap(true);
CellView cv = new CellView();
cv.setFormat(times);
cv.setFormat(timesBoldUnderline);
{
Label l1 = new Label(6, i, "pass");
ws.addCell(l1);
}
else
{
wwb.close();
}}
Output:
Result:
Thus the program to update 10 student records into table into Excelfile is tested
successfully.
Exercise Number: 7
Date:
Aim
:
To test the program to select the number of students who have scored more than
60 in any one subject ( or all subjects )
Procedure:
Write the java test code in eclipse. Since we are not using any Selenium object here no
need of selenium RC Server to run at the command prompt for this program.
This program reads an excel file so Create an Excel file Student.xls under the desktop
as follows.
Since we are dealing with the excel, we need to add the external jar file jxl-2.6 in to the
java project.( download jxl-2.6 and Follow the same steps as we used to add selenium
server and selenium java driver to our java project refer page no 10 of this manual.
Program:
package Selenium;
import jxl.Cell;
import jxl.CellView;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.format.UnderlineStyle;
import jxl.read.biff.BiffException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Locale;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.Number;
import
jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import org.testng.annotations.*;
public class Ex7 {
@BeforeClass
public void setUp() throws Exception {}
@Test
public void testImportexport1() throws Exception
{ student_excel_write test = new student_excel_write();
test.setOutputFile("D:/exp6.xls");
test.write();
System.out.println("created ");
checkExcelSheet();
System.out.println("checked");
}
// first code
Software Testing-16IT711 Page 36
SOFTWARE TESTING LABORATORY
wwb.close();
}
}
Output:
Result:
Thus the program to select the number of students who have scored more
than 60 in any one subject ( or all subjects ) created successfully.
Exercise Number: 8
Date:
Aim:
To test a program to provide total number of objects present / available on the page.
Procedure:
Before running this code makes sure your selenium RC server is running.
Program:
package Selenium;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
public class Ex8 {
public Selenium selenium;
public SeleniumServer seleniumserver;
@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox","http://");
seleniumserver.start();
selenium.start();
}
@Test
public void testDefaultTNG() throws Exception {
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();
System.out.println("TOTAL NO OF INPUT FIELDS="+fc.length);
}
@AfterClass
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();
}
}
Output:
Result:
Thus a program to provide total number of objects present / available on the page
executed successfully.
Exercise Number: 9
Date:
To test a program to get the number of list items in a list / combo box.
Procedure:
<html>
<body>
<select>
<option>Volvo</option>
<option>Express</option>
<option>Mercedes</option>
<option>RajaHamsa</option>
</select>
</body>
</html>
import com.thoughtworks.selenium.*;
public void
testloginlogout()
{ selenium.setSpeed("1
00 0");
selenium.open("file:///C:/Users/Savitha/Desktop/combocoun
t.html");
selenium.waitForPageToLoad("30000");
selenium.windowMaximize();
String[] selectelements = new
String[1000]; selectelements=
selenium.getSelectOptions("//select");
System.out.println("The number of options present in the given select box is "
+selectelements.length);
}
}
Output:
Result:
Thus the program to get the number of list items in a list / combo box executed
successfully.
Exercise Number: 10
Date:
Aim:
Procedure:
Write this java test code in eclipse. Since we are not using any Selenium object
here no need of selenium RC Server to run at the command prompt for this
program.
Write a visual basic script with the following code and save as count.vbs
under the desktop.
public class
desktop_item_count {
Runtime.getRuntime().exec("wscript C:/Users/Savitha/Desktop/count.vbs");
} catch
(IOException e) {
System.exit(0);
Note: Don’t forget to change the desktop file path for your system
Output:
Result:
Thus a program to count number of check boxes on the page checked and unchecked
count executed successfully.