ST Lab Manual PDF
ST Lab Manual PDF
ST Lab Manual PDF
SOFTWARE TESTING
LAB MANUAL
RJS Polytechnic, Koramangala
Vinayaka V.M.
vmvinayaka@gmail.com
SOFTWARE TESTING LAB MANUAL
By
Mr. Vinayaka V.M. M.Tech.
EXERCISE 01
Introduction:
What is Automation?
- Automation is making a process automatic, eliminating the need for human intervention.
- Is a self-controlling or self-moving process.
- Automation software offers automation wizard and commands of its own in addition to
providing task recording and re-play capabilities.
- Using these tools we can record the task
- Then if needed use the editor to edit the task, add new commands or using GUI
automation wizards
Benefits of Automation
Reliable: It performs precisely the same operations at each time elimination human errors
Repeatable: It performs the same operation with different combination of data in a less time
Programmable: We can use sophisticated tests that brings out hidden information
Reusable: We can develop reusable components which can run on different versions of
application under test
Enabling 24*7 testing: test can be schedule and supports unattended recovery
Robust Verification: Support robust verification mechanism than any other testing tools
Test Plan: Design the tests and build the test plan on it using the test management tool. The
test plan will be maintained in a central repository. This will help to produce reusable tests
cases in future. The information is sharable and preserved.
Test script: Automated test script associated with each test case will be stored in the quality
centre repository.
Test sets: this will be a set of selected test cases and associated test scripts. The tests sets are
executed from the quality centre onto remote machines. The status of each execution is stored
in the respective test case execution status. The status can be either pass/fail, it doesn.t
maintain exact details of execution.
Test logs: The test script execution logs are stored in global repository. It contains the status
of each test case.
Reusable components: The repetitive functions that are invoked in most of the functions are
stored, which reduces the coding redundancies.
Object repository: contains the declaration of the application objects. Data sheets: contains
the test data used for execution. it can be populated by the database or manually.
Automation Activity:
Record the application GUI Write Script Execute script Review the script Modify script if
any changes. Execute scripts on at least two machines Store the script in central repository
Execute the script from central repository Verify the execution status in central repository
Verify the test logs on common server Prepare the test reports
INTRODUCTION TO SELENIUM
1. History of Selenium
• In 2004 invented by Jason R. Huggins and team.
• Original name is JavaScript Functional Tester [JSFT]
• Open source browser based integration test framework built originally by Thoughtworks.
• 100% JavaScript and HTML
• Web testing tool
• That supports testing Web 2.0 applications
• Supports for Cross-Browser Testing(ON Multiple Browsers)
• And multiple Operating Systems
• Cross browser – IE 6/7, Firefox .8+, Opera, Safari 2.0+
2. What is Selenium?
• Acceptance Testing tool for web-apps
• Tests run directly in browser
• Selenium can be deployed on Windows, Linux, and Macintosh.
• Implemented entirely using browser technologies -
- JavaScript
-DHTML
-Frames
3. Selenium Components
– Selenium IDE
– Selenium Core
– Selenium RC
– Selenium Grid
Selenium IDE
• The Selenium-IDE (Integrated Development Environment) is the tool you use to develop
your Selenium test cases.
• 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:
A.Test Case Pane
B.Toolbar
C.Menu Bar
D.Log/Reference/UI-Element/Rollup Pane
B. Toolbar:
The toolbar contains buttons for controlling the execution of your test cases.
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:
It has help information.
NOTE:
1. When an "assert" fails, the test is aborted.
2. When a "verify" fails, the test will continue execution
3. "waitFor" commands wait for some condition to become true
Commonly Used Selenium Commands
These are probably the most commonly used commands for building test.
open - opens a page using a URL.
click/clickAndWait - performs a click operation, and optionally waits for a new page to load.
verifyTitle/assertTitle - verifies an expected page title.
verifyTextPresent- verifies expected text is somewhere on the page.
verifyElementPresent -verifies an expected UI element, as defined by its HTML tag, is
present on the page.
verifyText - verifies expected text and it’s corresponding HTML tag are present on the page.
verifyTable - verifies a table’s expected contents.
waitForPageToLoad - pauses execution until an expected new page loads. Called
automatically when clickAndWait is used.
waitForElementPresent -pauses execution until an expected UI element, as defined by its
HTML tag, is present on the page.
EXCERCISE 02
2. Using Selenium IDE, Write a test suite containing minimum 4 test cases.
Requirements
• Download Selenium IDE 1.5 or above addon for firefox from http://seleniumhq.org/download/
Or http://addons.mozilla.org/ from firefox browser.
• The webpage used in this example is a java Script program ‘Menu Driven Arithmetic Operations’
• A java Script for Arithmetic operation.
Procedure:-
Java script to develop a web page for Arithmetic Operations. Save this file on desktop and
save as arithmetic.html
<html>
<head>
<title> Arithmatic Operation </title>
<script type="text/javascript">
var n1,n2,r;
function add()
{
n1=document.myform.n1.value;
n2=document.myform.n2.value;
n1=parseFloat(n1);
n2=parseFloat(n2);
r=n1+n2;
document.myform.result.value=r;
}
function sub()
{
n1=document.myform.n1.value;
n2=document.myform.n2.value;
n1=parseFloat(n1);
n2=parseFloat(n2);
r=n1-n2;
document.myform.result.value=r;
}
function mul()
{
n1=document.myform.n1.value;
n2=document.myform.n2.value;
n1=parseFloat(n1);
n2=parseFloat(n2);
r=n1*n2;
document.myform.result.value=r;
}
function divide()
{
n1=document.myform.n1.value;
n2=document.myform.n2.value;
n1=parseFloat(n1);
n2=parseFloat(n2);
r=n1/n2;
document.myform.result.value=r;
}
</script>
</head>
<body>
<form name="myform">
<h1 align="center"> Arithmatic Operations</h1> <hr color="red"> <center>
<u>Enter a number in each text box </u>
<br><br>
Number 1:<input type="text" name="n1" value="">
<br><br>
Number 2:<input type="text" name="n2" value="">
<br><br>
<input type="button" value="Add" onClick="add()">
OUTPUT:
EXERCISE 03
3.Understanding Test Automation. Using Selenium write a simple test script to validate
each field of the registration page ( Eg: Face book Registration Page)
Requirements:
• Download Selenium IDE 1.5 or above from http://seleniumhq.org/download/ from
Firefox browser.
• A html Script for Registration form.
• Firefox version 10.0.
Procedure:-
Type this code in notepad and save on desktop
<html>
<body>
<form tag="Create Logon">
<div align="center">
Username *: <input type="username" name="username" /><br />
Password *: <input type="password" name="pwd" /><br />
Surname *: <input type="surname" name="surname" /><br />
Other Names *: <input type="other names" name="names" /><br />
Date of Birth *: <input type="date of birth" name="dob" /><br />
Email *: <input type="email" name="email" /><br />
Telephone: <input type="telephone" name="tel" /><br />
Address *: <input type="address" name="add" /><br />
Post Code *: <input type="postcode" name="ptc" /><br />
<input type="submit" value="Submit" />
</div>
</form>
<p>Note: Please make sure your details are correct before submitting form and that all fields marked with *
are completed!.</p>
</body>
</html>
Test program to be typed in selenium IDE: Select source tab in selenium and type
<tbody>
<tr>
<td>open</td>
<td>file:///C:/Users/RJSPL112/Desktop/reg.html</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>name=username</td>
<td>Vinayaka</td>
</tr>
<tr>
<td>type</td>
<td>name=pwd</td>
<td>vinaaa</td>
</tr>
<tr>
<td>type</td>
<td>name=surname</td>
<td>vm</td>
</tr>
<tr>
<td>type</td>
<td>name=names</td>
<td>vinay</td>
</tr>
<tr>
<td>type</td>
<td>name=dob</td>
<td>24-08-1985</td>
</tr>
<tr>
<td>type</td>
<td>name=email</td>
<td>vinayakavm@gmail.com</td>
</tr>
<tr>
<td>type</td>
<td>name=tel</td>
<td>9191919191</td>
</tr>
<tr>
<td>type</td>
<td>name=add</td>
<td>villa 4th cross venkatapura</td>
</tr>
<tr>
<td>type</td>
<td>name=ptc</td>
<td>560034</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=input[type="submit"]</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
EXERCISE 04
4. Install Selenium server and demonstrate it using a script in Java/PHP.
Requirements:
• Download the following :
Procedure:-
• Type the html code in the notepad and save that as GCD.html
• Open eclipse application give the folder name where you want to store your files. the
default will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window , Name the project to st click finish. Double
click on the new project st on the package explorer you will get src folder and JRE
System Library
• Right click on the src foldergo to newclick on the class you will get new java class
window name the class as Gcd click finish. After writing this code if u get red lines
under the selenium then include the selenium-server-standalone-2.32.0.jar and selenium-
java-clientdriver.jar files
• The steps are :
• Right click on the st folder click on properties click on Java Build path then
select the libraries tab click on Add External JARs browse for selenium-
serverstandalone-2.32.0.jar click open again click on Add External JARs
browse for selenium-java-clientdriver.jar click open click ok.
• To run the above program
First open the command prompt, go to the C:\Program Files (x86)\java\jdk1.6.0_25\bin
folder ->run/write the command java –jar selenium-server-standalone-2.32.0.jar 4444
• Click on run button in eclipse the output will be displayed the console.
Java script to develop a web page which calculates the GCD of 2 numbers. Save this file on desktop and
save as GCD.html
<html>
<head>
<script type="text/javascript">
function gcd()
{
var x,y;
x=parseInt(document.myform.n1.value);
y=parseInt(document.myform.n2.value);
while(x!=y)
{
if(x>y)
x=x-y;
else
y=y-x;
}
document.myform.result.value=x;
}
</script>
</head>
<body>
<h1 align="center"> Program to calculate gcd of two numbers </h1> <hr color="red">
<center> Enter two numbers : <form name="myform">
Number 1 : <input type="text" name="n1" value=""> <br> <br>
Number 2 : <input type="text" name="n2" value=""> <br> <br>
<input type="button" value="Get GCD" onClick="gcd()"> <br> <br>
GCD is : <input type="text" name="result" value="">
</form>
</body>
</html>
Java test script for testing the GCD webpage. (write this code in eclipse environment).
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@SuppressWarnings("deprecation")
Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 20
SOFTWARE TESTING LAB MANUAL
@Test
public void testGcd() throws Exception {
selenium.setSpeed("2000");
selenium.open("file:///C:/Users/RJSP/Desktop/GCD.html");
selenium.windowMaximize();
selenium.type("name=n1", "5");
selenium.type("name=n2", "6");
selenium.click("css=input[type=\"button\"]");
String result = selenium.getValue("name=result");
System.out.println("the gcd is : " +result);
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
• Open eclipse application-> give the folder name where you want to store your files. the default will be
‘ workspace ‘
• You will get Create java project window , Name the project to st click finish.
• you will get new java class window, name the class as GcdTest
• click finish.
Note: Make sure that the path of your GCD.html file must be correct , in this example it is
file:///C:/Users/RJSP/Desktop/GCD.html
After writing this code if you get red lines under the selenium then include the selenium-server-standalone-2.32.0.jar
and selenium-java-clientdriver.jar files.
The steps are : Right click on the st folder click on propertiesclick on Java Build path then select the libraries
tab click on Add External JARs browse for
selenium-server-standalone-2.32.0 click open again click on Add External JARs browse for
selenium-java-clientdriver click open click ok.
To run the above program
EXERCISE 05
5. Conduct a test suite for any two web sites.
Requirements:
Procedure:-
• Open firefox browser-> select tools->web developer->selenium IDE.
• Click on Start recording ->minimize the selenium window.
• Visit any website save testcase
• Create new testcase visit another website save testcase.
• Click on play entire test suite button in the selenium IDE.
TC#2:
1: Open Firefox Web Browser
2: In the address bar, Type http://www.sretravels.com
3: Close advertisementselect source and destination cities
4: Click on the date select today’s date click on search button
5: Wait for Search Results to come
6: Stop recording.
7. Save the test case as sretravels.
EXERCISE 06
Procedure:-
• Open eclipse application give the folder name where you want to store your files. the
default will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window , Name the project to st click finish.
• Double click on the new project st on the package explorer you will get src folder
and JRE System Library
• Right click on the src foldergo to newclick on the class you will get new java
class window name the class as Login click finish.
import com.thoughtworks.selenium.*;
@SuppressWarnings("deprecation")
public class login extends SeleneseTestCase
{
public void setUp() throws Exception
{
setUp("http://php.thedemosite.co.uk/","*firefox");
}
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:
EXERCISE 06
06.Write test cases to validate a mobile number using one-time pin identification
(OTP)
Requirements :
5) Verify that once expired, it should not be used for any authentication.
8) Verify that once user resent the OTP, the old one should be of no use.
10) Provide an invalid Phone Number or E-Mail address and submit the OTP. Check the validation.
9191919191
5. Verify your phone number by entering in the six-digit code Google sent you.
8. Now open firefox 10.0 start selenium ide … by default recording will be on.
9. Open gmail.com input phone number in the text box present for entering email id / phone number.
10. Click next
11. Enter password
12. Click next
13. Now system will ask to enter an OTP which is sent to your mobile number.
14. See the message you got to your mobile and enter the OTP in the text box.
15. Uncheck the check box button for remember this computer.
16. Click next
17. Now click on signout
18. Stop recording.
19. Now play the test case.
20. You should get a failure because OTP can be used only one time.
EXERCISE 08
8. Write and Test a program to find out list of employees having salary greater than
₹ 50,000 and age between 30 to 40 years.
Requirements:
• 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.
• 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.jar and past it in C:\Program Files (x86)\java\jdk1.6.0_25\bin and
Follow the same steps as we used to add selenium server and selenium java driver to our
java project.
Procedure:-
• Create the Microsoft excel document containing the name of employees and their salary
details in the Microsoft excel and save that file as Emp.xls
• Open eclipse application give the folder name where you want to store your files. The
default workspace will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window, Name the project to st click finish. Double
click on the new project st on the package explorer you will get src folder and JRE
System Library
• Right click on the src foldergo to newclick on the class you will get new java
class window name the class as Emp click finish.
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class Emp
{
private String inputFile;
public void setInputFile(String inputFile)
{
this.inputFile = inputFile;
}
public void read() throws IOException
{
File inputWorkbook = new File(inputFile);
Workbook w;
boolean flag=false;
boolean flag2=false;
int count=0;
try
{
w = Workbook.getWorkbook(inputWorkbook);
Sheet sheet = w.getSheet(0);
for (int j = 0; j < sheet.getRows(); j++)
{
for (int i = 0; i < sheet.getColumns(); i++)
{
Cell cell = sheet.getCell(i, j);
if (cell.getType() == CellType.NUMBER)
{
if(Integer.parseInt(cell.getContents())>50000)
{
flag = true;
}
}
if (cell.getType() == CellType.NUMBER)
{
if(Integer.parseInt(cell.getContents())>30 && Integer.parseInt(cell.getContents())< 40)
{
flag2 = true;
if(flag == true && flag2==true)
{
count++;
}
break;
}
}
}
}
System.out.println("Total number of employees having salary greater than ₹ 50,000 and age between 30 to
40 years: " +count);
}
catch (BiffException e)
{
e.printStackTrace();
}
}
public static void main(String[ ] args) throws IOException
{
Emp test = new Emp();
test.setInputFile("C:/Users/RJSP/Desktop/Emp.xls");
test.read();
}
}
OUTPUT:
EXERCISE 09
9. Write and test a program to update 10 student records into table into Excel file.
• 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.
• 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.
Procedure:-
• Create the blank excel document in the Microsoft excel and save that file as Student.xls
• Open eclipse application give the folder name where you want to store your files. The
default will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window , Name the project to st click finish. Double
click on the new project st on the package explorer you will get src folder and JRE
System Library
• Right click on the src foldergo to newclick on the class you will get new java
class window name the class as Student click finish.
import java.io.File;
import java.io.IOException;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class Stdrec
{
private String inputFile;
public void setOutputFile(String inputFile)
{
this.inputFile = inputFile;
}
public void write() throws IOException, WriteException
{
File file = new File(inputFile);
WritableWorkbook workbook = Workbook.createWorkbook(file);
workbook.createSheet("Report", 0);
WritableSheet excelSheet = workbook.getSheet(0);
createLabel(excelSheet);
createContent(excelSheet);
workbook.write();
workbook.close();
}
addNumber(sheet, 3, i, ((i*i)+8));
}
}
private void addCaption(WritableSheet sheet, int column, int row, String s) throws
RowsExceededException, WriteException
{
Label label;
label = new Label(column, row, s);
sheet.addCell(label);
}
private void addNumber(WritableSheet sheet, int column, int row,Integer integer) throws
WriteException, RowsExceededException
{
Number number;
number = new Number(column, row, integer);
sheet.addCell(number);
}
private void addLabel(WritableSheet sheet, int column, int row, String s) throws WriteException,
RowsExceededException
{
Label label;
label = new Label(column, row, s);
sheet.addCell(label);
}
public static void main(String[ ] args) throws WriteException, IOException {
Stdrec test = new Stdrec();
test.setOutputFile("C:/Users/RJSP/Desktop/Student.xls");
test.write();
System.out.println("Please check the result file under C:/Users/RJSP/Desktop/Student.xls");
}
}
OUTPUT:
EXERCISE 10
10.Write and test a program to select the number of students who have scored more
than 60 in any one subject (or all subjects).
Requirements :
• 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.
• 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.
Procedure:
• Create the excel document containing the details about the students and their marks in
the Microsoft excel and save that file as Student.xls
• Open eclipse application give the folder name where you want to store your files. the
default will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window , Name the project to st click finish. Double
click on the new project st on the package explorer you will get src folder and JRE
System Library
• Right click on the src foldergo to newclick on the class you will get new java
class window name the class as Student click finish.
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class student_excel_read
{
private String inputFile;
public void setInputFile(String inputFile)
{
this.inputFile = inputFile;
}
public void read() throws IOException
{
File inputWorkbook = new File(inputFile);
Workbook w;
boolean flag=false;
int count=0;
try
{
w = Workbook.getWorkbook(inputWorkbook);
Sheet sheet = w.getSheet(0);
for (int j = 0; j < sheet.getRows(); j++)
{
for (int i = 0; i < sheet.getColumns(); i++)
{
Cell cell = sheet.getCell(i, j);
if (cell.getType() == CellType.NUMBER)
{
if(Integer.parseInt(cell.getContents())>60)
{
flag = true;
if(flag == true)
{
count++;
flag=false;
} break;
}
}
}
}
System.out.println("Total number of students who scored more than 60 in one or
more subjects is: " +count);
}
catch (BiffException e)
{
e.printStackTrace();
}
}
public static void main(String[ ] args) throws IOException
{ student_excel_read test = new student_excel_read();
test.setInputFile("C:/Users/vmvin/Desktop/Student.xls");
test.read();
}
}
INPUT:
OUTPUT :
EXERCISE 11
11. Write and test a program to provide total number of objects present / available on
the page.
Requirements:
• Write this java test code in eclipse. before running this code makes sure your selenium
RC server is running
• Firefox version 10.0 required.
• Internet access required.
Procedure:-
• Write the Above code in eclipse by following the below steps
• Open eclipse application give the folder name where you want to store your files
the default will be ‘workspace ‘Then go to filenewjava project.
• You will get Create java project window Name the project to st click finish.
• Double click on the new project st on the package explorer you will get src folder and
JRE System Library
• Right click on the src foldergo to newclick on the class you will get new java
class window name the class as Obj click finish.
• After writing this code if u get red lines under the selenium then include the selenium
server and selenium java driver jar file. The steps are:
• Right click on the st folderclick on properties click on Java Build paththen select
the tab libraries click on Add External JARsbrowse for
selenium-serverstandalone-2.32.0Click open again click on Add External JARs
browse for selenium-java-clientdriver
• click open-> click ok->To run the above program
• First open the command prompt-> go to the C:\Program Files (x86)\java\jdk1.6.0_26\bin
folder run/write the command java –jar selenium-server-standalone-2.32.0.jar 4444
• The number of objects available on the web page will be displayed as output in the
console when you click run button in eclipse.
import com.thoughtworks.selenium.*;
@SuppressWarnings("deprecation")
public class objectcount extends SeleneseTestCase
{
public void setUp() throws Exception {
setUp("http://www.wikipedia.org/","*firefox");
}
public void testloginlogout()
{
selenium.setSpeed("1000");
selenium.open("www.wikipedia.org/Gmail");
selenium.waitForPageToLoad("30000");
selenium.windowMaximize();
int num = selenium.getXpathCount("//p").intValue();
System.out.println("The number of option elements present are " +num);
}
}
OUTPUT:
EXERCISE 11
11. Write and test a program to get the number of list items in a list / combo box.
Requirements:
• Write this java test code in eclipse. before running this code makes sure your selenium
RC server is running)
• Write Combocount.html as shown below and save under desktop.
Procedure:-
• Type the html code in notepad and save that as combo.html
• Open eclipse application give the folder name where you want to store your files. The
default will be ‘ workspace ‘
• Then go to filenewjava project.
• You will get Create java project window , Name the project to st click finish. Double
click on the new project st on the package explorer you will get src folder and JRE
System Library
• right click on the src foldergo to newclick on the class you will get new java class
window name the class as Comboitemcount click finish.
<html>
<body>
<select>
<option>Volvo</option>
<option>Express</option>
<option>Mercedes</option>
<option>Lamborghini</option>
Department of Computer Science and Engineering, RJS Polytechnic, Koramangala, Bengaluru 50
SOFTWARE TESTING LAB MANUAL
</select>
</body>
</html>
import com.thoughtworks.selenium.*;
public class Comboitemcount extends SeleneseTestCase
{
public void setUp() throws Exception
{
selenium = new DefaultSelenium("localhost", 4444,
"*chrome","file:///C:/combocount.html");
selenium.start();
}
public void testloginlogout()
{
selenium.setSpeed("1000");
selenium.open("file:///C:/combo.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:
EXERCISE 13
13. Write and test a program to count number of items present on a desktop.
Requirements:
• 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.
Procedure:-
• Type the visual basics code in the notepad and save that as count.vbs
• Write the Above code in eclipse by following the below steps
• Open eclipse application give the folder name where you want to store your files-the
default will be ‘workspace ‘Then go to filenewjava project.
• You will get Create java project window Name the project to st click finish.
• Double click on the new project st on the package explorer you will get src folder and
JRE System Library
• Right click on the src foldergo to newclick on the class you will get new java
class window name the class as desktop_item_count click finish.
• Click on run button in eclipse, the output will be displayed in an alert box.
import java.io.*;
public class desktop_item_count
{
public static void main(String[ ] args)
{
try
{
Runtime.getRuntime().exec("wscript C:/Users/vmvin/count.vbs");
}
catch (IOException e)
{
System.exit(0);
}
}
}