You are on page 1of 37

Exp 2.

Using Selenium IDE, write a test suite containing minimum 4 test cases
<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()">
<input type="button" value="Subtract" onClick="sub()">
<input type="button" value="Multiply" onClick="mul()" >
<input type="button" value="Divide" onClick="divide()"><br><br>
<input type="reset"value="reset"><br>
<font color="red">Result is:
<input type="text" name="result" value=""></center></font>
</form>
</body>
</html>
Procedure –
1. Open the Firefox Browser
2. Click on File -> Open File
3. Locate the file to be tested. [For our example myform.html is selected]
4. Click on the Tools in the Firefox Browser, select and click on Selenium IDE
5. Selenium IDE window appears on the screen
6. For the purpose of TEST SUITE – we have used HTML file “myForm.html” which
performs basic mathematical operations – addition, subtraction, multiplication and
division. Each operation here acts as a test case. There are two textboxes where user can
input values to perform mathematical operations.
7. Selenium will be in default Record mode whenever opened first time.

Create First test case


1. In Selenium under File menu option – New test case option is selected; untitled test case
is displayed in the test case pane.
2. HTML file myform.html is opened in Firefox.
3. In Selenium IDE click on the Record button. Selenium will start recording commands
based on the user action
4. In Firefox, Input values are entered in the text box and then click on Add option to add
two numbers, result will be displayed in result textbox
5. In Selenium user actions are captured as commands under test case window, test case is
saved as add.html after stopping the record mode. This is our first test case
6. Steps from 4 is repeated for subtract option and the test case is saved as sub.html
7. Same operations are repeated for multiply and divide option and test cases are saved as
mul.html and div.html
8. We have created four test cases; now need to create a test suite.
9. All the four test cases are displayed in test case pane. From the menu option “Save test
suite” should be selected and test suite should be named as ts_math.html.
10. One more way of doing this is – From menu option select “New Test Suite” and then test
cases can be added to that.
11. Test Suite is ready; we can run the test suite by selecting “Play Entire Test Suite” from
toolbar. This will run all the test cases one by one.
Actual value and expected value are compared to conclude that web page is functioning
as per the expectation. In our case mathematical operations results are verified by
checking the values.
Students Note:
[Towards left side of the practical record, update the commands noted down in your
observation book]

Command Target Value


open file:///D:/html/myform.html
type n1 2
type n2 3
click //input[@value=’Add’] add()
Verify result 5
value

Repeat the same for remaining test cases.

Exp3. Install Selenium Server and demonstrate it using a script in JAVA/PHP


1. Selenium Server and Java Client driver should be downloaded from Selenium website
http://seleniumhq.org/download . Selenium Server downloaded will be in JAR format
whereas Java client driver is Zip file hence it should be extracted to get JAR file. Save
both the files under drive D: /Seleniumserver/

Downloaded Selenium server version is “selenium-server-standalone-2.28.0.jar”.


Downloaded Selenium Java driver is “selenium-java-2.28.0.zip”

2. In Eclipse IDE need to create a new Java Project. Name the Java Project say – Labthree.
In Eclipse we can see “src” folder and “JRE System Library”. Since we need to write
Java Code where Selenium has to be recognised we need to include server and client
JAR file.
Procedure to include JAR file –
 Right click on the Java Project created, select Build path. In that select Configure
Build Path. New window gets opened where we can see different tabs – Source,
Projects, Libraries, Order and Export. Select Tab “Libraries”. We can see only
JRE System Library.
 Select Button “Add External JARs”. Browse and select Selenium Server Jar file
we can see a new entry along with JRE System Library.
 Select Button “Add External JARs” again, browse and select selenium Java driver
Jar file.
 We can see both Selenium server and Java driver JAR file.

3. Need to write script code in Java. In Eclipse IDE under “src” folder, right click and select
class – Give name to class say Google. In Eclipse we can see a new Google.java file
opened. Write below code –

import junit.framework.*;

import com.thoughtworks.selenium.DefaultSelenium;

public class DefaultSelenium1 extends TestCase

private DefaultSelenium selenium;

public void testing()

selenium=new

DefaultSelenium("localhost",4444,"*iexplore","http://hexbytes.com");

selenium.start();

selenium.open("/");

selenium.type("searchbox", "selenium rc");

selenium.click("css=input[type='submit'][value='Search']");

selenium.waitForPageToLoad("30000");

Assert.assertTrue(selenium.isTextPresent("selenium rc"));

}
}
(OR)
import com.thoughtworks.selenium.DefaultSelenium ;
public class Google {
public static void main(String[] args)
{
String sServerHost = "localhost" ;
int iServerport = 4444 ;
String sBrowserType = "*iexplore" ;
String sBaseUrl = "http://in.yahoo.com/?p=us" ;
// create new selenium server object
DefaultSelenium oDefaultSel = new DefaultSelenium(sServerHost,iServerport,
sBrowserType, sBaseUrl );
oDefaultSel.start() ;
oDefaultSel.windowMaximize();
oDefaultSel.setSpeed("3000") ;
oDefaultSel.open("/" ) ;
oDefaultSel.type("id=p_13838465-p", "selenium rc");
oDefaultSel.click("id=search-submit");
oDefaultSel.waitForPageToLoad("5000") ;
try {
Thread.sleep(3000) ;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
oDefaultSel.stop() ;
System.out.println("Opened yahoo website") ;
}
}
4. In case we don’t add External JARs then selenium will not be recognized. This can be
checked once by removing external JARs.
5. Script code is ready, now need to start server. Go to command prompt; in command
prompt go to the folder where server JAR resides. In our case server is in
D: /Seleniumserver/ Go to that particular path and then start server by executing below
command
Java –jar selenium-server-standalone-2.28.0.jar 4444
Here 4444 refers to the port number where server listens to client request
6. In Eclipse IDE run the source code. We can see Mozilla Firefox getting opened and
displays yahoo page. Later in search box “selenium rc” gets displayed. Then a new page
gets loaded based on search element.

About :Selenium Remote Control (RC) is a test tool that allows writing 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 favorite computer language.
Here is a simplified architectural representation....

Selenium Remote Control is great for testing complex AJAX-based web user interfaces under a
Continuous Integration system.

Eclipse has to be installed since we are going to write Java programs


Download selenium 2.28.0 version from website
http://Seleniumhq.org/download
From same website we need to download Java web driver.
Downloaded selenium server version is –
“selenium-server-standalone-2.28.0.jar”. This is a jar file.
Java web driver downloaded is “selenium-java-2.28.0.zip”. As this is a zip file this should be
extracted. When we extract this file, we get “selenium-java-2.28.0.jar” JAR file. This is an
executable file. So we have both server and also web driver JAR files.
We need to run server before writing any script code. Assume we have server under directory
C:\Seleniumserver\ then we need to go to command prompt and then go to respective folder
where Seleniumserver is located. Execute the following command to start server –
Java –jar selenium-server-standalone-2.28.0.jar 4444
Here 4444 refers to the port number where the server is listening.
4.Conduct Test Suite for any two web sites

Test Suite done for the following web sites


1. Acharya
2. Yahoo

Acharya
Command Target
open http://acharyaexports.com/
clickAndWait name=Image22
clickAndWait name=Image20
click link=acharyas@vsnl.com

Yahoo
http://in.yahoo.com/
Command Target
open /?p=us
assertTitle Yahoo! India
click //div[@id='u_2588582-y']/div/button
clickAndWait css=#pa-u_93109-bd > a > span.vital.small
clickAndWait css=a[title="Mutual Funds"] > span
clickAndWait link=BSE Sensex

Procedure –
1. Open the Firefox Browser
2. Type the following URL “http://acharyaexports.com/” in url edit box
3. Click on the Tools in the Firefox Browser, select and click on Selenium IDE
4. Selenium IDE window appears on the screen
5. Selenium will be in default Record mode whenever opened first time.

Create First Test Case for Acharya website -


6. Copy URL from the Firefox URL and paste it in the base url edit box of Selenium IDE
7. Select any functional link on Acharya website and view that particular link
8. For every operation performed on the website there will be a command inserted in the
Selenium IDE.
9. Right click on the web page and we can see all the supported selenium commands. There
are Assert commands where we can verify the title page opened.
10. Once recording is done, Record button should be stopped
11. Test case should be saved as tc_acharya.html.

Second Test Case for Yahoo Website


12.Select New Test Case in Selenium IDE
13. In Firefox browser, type www.yahoo.com in URL editbox
14. In Selenium click on recording
14. Perform any operation on the web site, respective command will be
displayed in the test case pane of the Selenium.
15. Once recording is done, Record button should be stopped
16. Test case should be saved as tc_yahoo.html.
Test Suite Creation and Execution
17. Once the test cases are ready. Test cases should be saved as Test Suite.
In Selenium IDE select “Save Test Suite” and save the test cases as
ts_website.html.
18. From the Toolbar, first set speed to Slow and then run the Test Suite by
Selecting toolbar option “Play entire test suite”.
19. All the test cases grouped under test suite will be played back.

Actual value and expected value are compared to conclude that web page is functioning
as per the expectation.
5. Write and test a program to login a specific web page
1. In Eclipse IDE need to create a new Java Project. Name the Java Project say – Labfive.
In Eclipse we can see “src” folder and “JRE System Library”. Since we need to write
Java Code where Selenium has to be recognised we need to include server and client JAR
file.
Procedure to include JAR file –
 Right click on the Java Project created, select Build path. In that select Configure
Build Path. New window gets opened where we can see different tabs – Source,
Projects, Libraries, Order and Export. Select Tab “Libraries”. We can see only
JRE System Library.
 Select Button “Add External JARs”. Browse and select Selenium Server Jar file
we can see a new entry along with JRE System Library.
 Select Button “Add External JARs” again, browse and select selenium Java driver
Jar file.
 We can see both Selenium server and Java driver JAR file.

2. Need to write script code in Java. In Eclipse IDE under “src” folder, right click and select
class – Give name to class say Google. In Eclipse we can see a new Google.java file
opened. Write below code –

import com.thoughtworks.selenium.*;
public class Mail extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://php.thedemosite.co.uk/","*iexplore");
}
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");
}
}

3. In case we don’t add External JARs then selenium will not be recognized. This can be
checked once by removing external JARs.
4. Script code is ready, now need to start server. Go to command prompt; in command
prompt go to the folder where server JAR resides. In our case server is in
D: /Seleniumserver/ Go to that particular path and then start server by executing below
command
Java –jar selenium-server-standalone-2.28.0.jar 4444
Here 4444 refers to the port number where server listens to client request
5. In Eclipse IDE run the source code. We can see Mozilla Firefox getting opened and
displays “http://php.thedemosite.co.uk/” page. Slowly in login page username and
password will be entered, if login and password are correct then user can view successful
login.
6. Write and test a program to get the number of list items in a list / combo box

1. In Eclipse IDE need to create a new Java Project. Name the Java Project say –
Labsix. In Eclipse we can see “src” folder and “JRE System Library”. Since we need
to write Java code where Selenium has to be recognised we need to include server
and client JAR file.
Procedure to include JAR file –
 Right click on the Java Project created, select Build path. In that select Configure
Build Path. New window gets opened where we can see different tabs – Source,
Projects, Libraries, Order and Export. Select Tab “Libraries”. We can see only
JRE System Library.
 Select Button “Add External JARs”. Browse and select Selenium Server Jar file
we can see a new entry along with JRE System Library.
 Select Button “Add External JARs” again, browse and select selenium Java driver
Jar file.
 We can see both Selenium server and Java driver JAR file.
2. We need to create an html file “Combocount.html” which will have a combo box and
write java program to read that html file to get the number of items present in the
combobox. Below is HTML code –
<html>
<body>
<select>
<option>Volvo</option>
<option>Express</option>
<option>Mercedes</option>
<option>RajaHamsa</option>
</select>
</body>
</html>

3. Need to write script code in Java. In Eclipse IDE under “src” folder, right click and select
class – Give name to class say ListItmCnt. In Eclipse we can see a new ListItmCnt.java
file opened. Write below code –

import com.thoughtworks.selenium.DefaultSelenium ;

public class ListItmCnt {


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

String sServerHost = "localhost" ;


int iServerport = 4444 ;

String sBrowserType = "*firefox" ;


// path where the file resides
String sBaseUrl = "file:///C:/Selenium/Combocount.html" ;

// create new selenium server object


DefaultSelenium sel = new DefaultSelenium(sServerHost,
iServerport, sBrowserType, sBaseUrl );
sel.start() ;
sel.windowMaximize();
sel.setSpeed("1000");
sel.open(sBaseUrl) ;
sel.waitForPageToLoad("1000");
String[] selectelements = new String[10];
selectelements= sel.getSelectOptions("//select");
System.out.println("The number of items present in the given combo box
is " +selectelements.length);
}

}
4. Script code is ready, now need to start server. Go to command prompt; in command
prompt go to the folder where server JAR resides. In our case server is in
D: /Seleniumserver/ Go to that particular path and then start server by executing below
command
Java –jar selenium-server-standalone-2.28.0.jar 4444
Here 4444 refers to the port number where server listens to client request
5. In Eclipse IDE run the source code. We can see Mozilla Firefox getting opened and
displays “Combocount” HTML page. The number of “P” tags used in that webpage will
be displayed in Eclipse console window.
7. Write and test a program to count number of items present on a desktop

1. To get the number of items present on the desktop VB Script code has to be written.
Below is the code –

Set fso = createobject("Scripting.FileSystemObject")


DesktopPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
'Files count
msgbox "The number of files on the desktop is : "
&fso.GetFolder(DesktopPath).Files.Count
'Folders count
msgbox "The number of folders on the desktop is : "
&fso.GetFolder(DesktopPath).SubFolders.Count

Above code should be saved as “count.vbs”


2. In Eclipse IDE need to create a new Java Project. Name the Java Project say – LabTen.
In Eclipse we can see “src” folder and “JRE System Library”.
3. Need to write script code in Java. In Eclipse IDE under “src” folder, right click and select
class – Give name to class say DeskItmCnt. In Eclipse we can see a new
DeskItmCnt.java file opened. Write below code –

import java.io.*;

public class DeskItmCnt {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Runtime.getRuntime().exec("wscript C:/Selenium/count.vbs");
} catch (IOException e) {
System.exit(0);
}
}
}

4. Script code is ready. Need to execute code, on execution VB Script “count.vbs” gets
executed and the number of files and folders present on the desktop gets displayed as
window on eclipse IDE.
8. Write and test a program to update 10 student records into table into Excel
file
For this program we need to interact with Microsoft excel and hence jxl.jar file should be
downloaded from the net. After downloading jxl jar file. It should be included as a
external jar file in Eclipse IDE.

1. In Eclipse IDE need to create a new Java Project. Name the Java Project say – LabSix. In
Eclipse we can see “src” folder and “JRE System Library”.
Right click on the Java Project created, select Build path. In that select Configure
Build Path. New window gets opened where we can see different tabs – Source, Projects,
Libraries, Order and Export. Select Tab “Libraries”. We can see only JRE System
Library.
 Select Button “Add External JARs”. Browse and select Jxl Jar file we can see a
new entry along with JRE System Library.
2. Need to create an excel file which acts as an input file for modification. Create an excel
file “STUD.xls” in C: folder under directory Selenium. Following data should be entered
in the excel file. There should be 10 rows in the file.

rollno NAMES JAVA BMSIC WP TOTAL


1 EEE 45 32 99 176
2 DDD 40 77 88 205
3 VV 65 77 88 230
4 VVVV 66 56 67 189

3. Need to write script code in Java. In Eclipse IDE under “src” folder, right click and select
class – Give name to class say sixth. In Eclipse we can see a new sixth.java file opened.
Write below code –

import java.io.*;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.*;
public class Lovely {

public static void main(String[] args) throws BiffException,


IOException, WriteException {
// TODO Auto-generated method stub

int iNoOfRows = 0, iNoOfCols = 0 ;


File file = new File("C:/Selenium/Student1.xls");
FileInputStream fi = new FileInputStream(file);
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
FileOutputStream fo = new
FileOutputStream("C:/Selenium/Result.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("result", 0);

iNoOfRows = s.getRows() ;
iNoOfCols = s.getColumns() ;

for (int i = 0; i < iNoOfRows; i++)


for (int j = 0; j < iNoOfCols; j++)
{
a[i][j] = s.getCell(j, i).getContents();
Label l2 = new Label(j, i, a[i][j]);
ws.addCell(l2);
Label l1 = new Label(6, 0, "Result");
ws.addCell(l1);

}
for (int i = 1; i < iNoOfRows; i++) {
for (int j = 2; j < iNoOfCols; j++)
{
a[i][j] = s.getCell(j, i).getContents();
int x = Integer.parseInt(a[i][j]);
if(x > 35)
{
Label l1 = new Label(6, i, "pass");
ws.addCell(l1);
}
else
{
Label l1 = new Label(6, i, "fail");
ws.addCell(l1);
break;
}
}
}
wwb.write();
wwb.close();
}
}

1. Script code is ready; Program will read the input file and create a new output file
“Result.xls” to which the input file data are copied. New Column “result” is created.
Each student’s marks are checked, based on the marks scored result status “pass/fail” is
updated under result column.
2. In Eclipse IDE run the source code. We can see a file “Result” generated under C drive
inside folder Selenium.
Input file to be read –

Output file generated –


9. Write and test a program to select the number of students who have scored more
than 60 in any one subject (or all subjects).
For this program we need to interact with Microsoft excel and hence jxl.jar file should be
downloaded from the net. After downloading jxl jar file. It should be included as a
external jar file in Eclipse IDE.

1. In Eclipse IDE need to create a new Java Project. Name the Java Project say – LabSix. In
Eclipse we can see “src” folder and “JRE System Library”.
Right click on the Java Project created, select Build path. In that select Configure
Build Path. New window gets opened where we can see different tabs – Source, Projects,
Libraries, Order and Export. Select Tab “Libraries”. We can see only JRE System
Library.
 Select Button “Add External JARs”. Browse and select Jxl Jar file we can see a
new entry along with JRE System Library.
2. Need to create an excel file which acts as an input file for modification. Create an excel
file “STUD.xls” in C: folder under directory Selenium. Following data should be entered
in the excel file. There should be 10 rows in the file.

rollno NAMES JAVA BMSIC WP TOTAL


1 EEE 45 32 99 176
2 DDD 40 77 88 205
3 VV 65 77 88 230
4 VVVV 66 56 67 189

3. Need to write script code in Java. In Eclipse IDE under “src” folder, right click and select
class – Give name to class say sixth. In Eclipse we can see a new sixth.java file opened.
Write below code –

import java.io.*;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.*;
public class Lovely {

public static void main(String[] args) throws BiffException,


IOException, WriteException {
// TODO Auto-generated method stub

int iNoOfRows = 0, iNoOfCols = 0 ;


File file = new File("C:/Selenium/Student1.xls");
FileInputStream fi = new FileInputStream(file);
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
FileOutputStream fo = new
FileOutputStream("C:/Selenium/Result.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("result", 0);

iNoOfRows = s.getRows() ;
iNoOfCols = s.getColumns() ;

for (int i = 0; i < iNoOfRows; i++)


for (int j = 0; j < iNoOfCols; j++)
{
a[i][j] = s.getCell(j, i).getContents();
Label l2 = new Label(j, i, a[i][j]);
ws.addCell(l2);
Label l1 = new Label(6, 0, "Result");
ws.addCell(l1);

}
for (int i = 1; i < iNoOfRows; i++) {
for (int j = 2; j < iNoOfCols; j++)
{
a[i][j] = s.getCell(j, i).getContents();
int x = Integer.parseInt(a[i][j]);
if(x > 60)
{
Label l1 = new Label(6,i, "above 60");
ws.addCell(l1);
}

}
}
wwb.write();
wwb.close();
}
}

1. Script code is ready; Program will read the input file and create a new output file
“Result.xls” to which the input file data are copied. New Column “result” is created.
Each student’s marks are checked, based on the marks scored result status “above 60” is
updated under result column.
2. In Eclipse IDE run the source code. We can see a file “Result” generated under C drive
inside folder Selenium.

Output file
Make the 10 student record
10. Understanding Test Automation, Using selenium writ test script to validate each field of
registration page (Eg. Gmail/Yahoomail).

Procedure –

1. Open the Firefox Browser


2. Type the following URL “http://gmail.com/” in url edit box
3. Click on the Tools in the Firefox Browser, select and click on Selenium IDE
4. Selenium IDE window appears on the screen
5. Selenium will be in default Record mode whenever opened first time.

Create Test Case for Gmail website -

6. Copy URL from the Firefox URL and paste it in the base url edit box of Selenium IDE
7. Go to Create Account link & enter your personal details.
8. For every operation performed on the website there will be a command inserted in the
Selenium IDE.
9. Once recording is done, Record button should be stopped
10. Test case should be saved as registration.html.
11. Close all the tabs, reopen Mozilla browser , select tools, Selenium IDE. Open the saved test case
registration.html and click on play button on Selenium IDE.
11. Write and test a program to find out list of employees having salary
greater than Rs 50000 and age between 30 to 40 years.

For this program we need to interact with Microsoft excel and hence jxl.jar file
should be downloaded from the net. After downloading jxl jar file. It should be
included as a external jar file in Eclipse IDE.

1. In Eclipse IDE need to create a new Java Project. Name the Java Project say –
Labeleven. In Eclipse we can see “src” folder and “JRE System Library”.
Right click on the Java Project created, select Build path. In that select
Configure Build Path. New window gets opened where we can see different
tabs – Source, Projects, Libraries, Order and Export. Select Tab “Libraries”. We
can see only JRE System Library.
 Select Button “Add External JARs”. Browse and select Jxl Jar file we
can see a new entry along with JRE System Library.
2. Need to create an excel file which acts as an input file for modification. Create
an excel file “employee.xls” in C: folder under directory Selenium. Following
data should be entered in the excel file. There should be 10 rows in the file.

Name Age Salary


Rahul 34 51000
Tarun 41 35000
Deepak 24 26000

3. Need to write script code in Java. In Eclipse IDE under “src” folder, right click
and select class – Give name to class say eleven. In Eclipse we can see a new
eleven.java file opened. Write below code –

4. Script code is ready; Program will read the input file and create a new output
file “Result.xls” to which the input file data are copied. New Column “result”
is created. Each employee age and salary are checked, based on the comparison
status “Matched/Not Matched” is updated under result column.

5. In Eclipse IDE run the source code. We can see a file “Result” generated under
C drive inside folder Selenium.

import java.io.*;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.*;
public class Shah {

public static void main(String[] args) throws BiffException, IOException,


WriteException {
// TODO Auto-generated method stub
int iNoOfRows = 0, iNoOfCols = 0 ;
File file = new File("D:/College/form.xls");
FileInputStream fi = new FileInputStream(file);
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
FileOutputStream fo = new FileOutputStream("D:/College/Result.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("result", 0);
iNoOfRows = s.getRows() ;
iNoOfCols = s.getColumns() ;
for (int i = 0; i < iNoOfRows; i++)
for (int j = 0; j < iNoOfCols; j++)
{
a[i][j] = s.getCell(j, i).getContents();
Label l2 = new Label(j, i, a[i][j]);
ws.addCell(l2);
Label l1 = new Label(3, 0, "Result");
ws.addCell(l1);
}
int age=0,sal=0;
for (int i = 1; i < iNoOfRows; i++) {
for (int j = 1; j < iNoOfCols; j++)
{
if(j==1)
age = Integer.parseInt(a[i][j]);
else
sal=Integer.parseInt(a[i][j]);
}
if( sal > 50000 && age > 30 && age <40)
{
Label l1 = new Label(3,i, "Match");
ws.addCell(l1);
}
}
wwb.write();
wwb.close();
}
}
12.Write and test a program to provide total number of objects present /

available on the page

1. In Eclipse IDE need to create a new Java Project. Name the Java Project say – LabEight.
In Eclipse we can see “src” folder and “JRE System Library”. Since we need to write
Java Code where Selenium has to be recognised we need to include server and client
JAR file.
Procedure to include JAR file –
 Right click on the Java Project created, select Build path. In that select Configure
Build Path. New window gets opened where we can see different tabs – Source,
Projects, Libraries, Order and Export. Select Tab “Libraries”. We can see only
JRE System Library.
 Select Button “Add External JARs”. Browse and select Selenium Server Jar file
we can see a new entry along with JRE System Library.
 Select Button “Add External JARs” again, browse and select selenium Java driver
Jar file.
 We can see both Selenium server and Java driver JAR file.

2. Need to write script code in Java. In Eclipse IDE under “src” folder, right click and select
class – Give name to class say ObjCnt. In Eclipse we can see a new ObjCnt.java file
opened. Write below code –

import com.thoughtworks.selenium.*;

public class ObjCnt {

public static void main( String[] args)

String sServerHost = "localhost" ;

int iServerport = 4444 ;

String sBrowserType = "*firefox" ;

String sBaseUrl = "http://in.rediff.com//" ;

// create new selenium server object

DefaultSelenium sel = new DefaultSelenium(sServerHost,

iServerport, sBrowserType, sBaseUrl );


sel.start() ;

sel.windowMaximize();

sel.setSpeed("1000");

sel.open("/") ;

sel.waitForPageToLoad("3000");

int num = sel.getXpathCount("//p").intValue();

System.out.println("The number of p objects present are " +num);

// TODO Auto-generated method stub

3. Script code is ready, now need to start server. Go to command prompt; in command
prompt go to the folder where server JAR resides. In our case server is in
D: /Seleniumserver/ Go to that particular path and then start server by executing below
command
Java –jar selenium-server-standalone-2.28.0.jar 4444

Here 4444 refers to the port number where server listens to client request

4. In Eclipse IDE run the source code. We can see Mozilla Firefox getting opened and
displays “Rediffmail” page. The number of “P” tags used in that webpage will be
displayed in Eclipse console window.

Output –

Rediffmail Web page opened

Selenium Command history


Bugzilla Tutorial – Bug Tracking Tool

In software development process, getting and tracking bug, defect and error
is a very common process and then documenting those bugs with a proper
description in the word document is a general practice. What would happen
if the document is erased or data got corrupted? So, in order to get rid of all
this unwanted and unavoidable condition we use bug tracking tools for
tracking the bugs, defects and error found during the software development
process. Now a day there are many bug tracking tools are available in the
market like- Axosoft, Jira, Planio and much more. Maximum of the bug
trackers are available in paid versions and very few are free. Among all
these bug trackers, bug tracker Bugzilla, one of the tool which is absolutely
free and very user – friendly.
Bugzilla is a web-based general bug tracker and testing tool. It is a server
software which is designed to help in managing the software development
process. It was released as an open-source software by Netscape
Communications in 1998. Bugzilla is used as a bug tracking system for both
free and open-source software and proprietary projects and products.
Bugzilla is used among others, by Mozilla Foundation, Linux kernel, GNOME,
KDE, Apache, Redhat, FreeBSD, Eclipse, WebKit, and LibreOffice. Topics
covered in this Bugzilla Tutorial Series:

Features of Bugzilla
Bugzilla has many features for both User and Administrator. Bugzilla
features for users

 Search Capability is of advanced level: Bugzilla provides 2 type of


search
Basic search that is simple for users and can search for full text.
Advance search system where a user can create the search using
some filter.
 Email Notification: A user will receive email notification for any
updations done for any bug or defect.
 Multi format bug listing: When searching for any bug, the search
result can be found in different formats. Such as a long, printable
report format containing all the bug details, a CSV format for
importing into spreadsheets, and XML formats.
 Bug Reports and Chart: It has an advanced reporting system. For
the bug reports, you can create a table using any two fields as the X
and Y axis, and use any search criteria to limit the bugs you want
information on.
 Detect duplicate bug automatically: Bugzilla will automatically look
for similar bugs in the system and allow the user to add themselves to
the CC list of one of those bugs instead of filing a new one.
 Bug updates using email: Any specific bug or defect can be modified
or edited simply by sending an email to Bugzilla.
 Time Tracker: There is a time tracking facility available, from where
we can check the time required for bug fixing and can also set a
deadline by when the bug is to be complete.
 Request System: Request System is a method of asking other users
to do something with a particular bug or attachment. That other user
can either grant the request or can deny the request and everything
get a track in Bugzilla.
 Attachment and Comments can be made private: If working on a
project in a group, then we can make some attachment or comment
marked as private, which will not be visible to other users in the
group.
 Patch Viewer: It gives you a nice, colorful view of any patch attached
to a bug.

Other than all these there are many other features of Bugzilla from the user
perspective.

Few Features for Administrator

 Security is excellent: Security is a serious factor Bugzilla. Bugzilla


runs under Perl’s “taint” mode to prevent SQL Injection and has a very
careful system in place to prevent Cross-Site Scripting.
 Field Customization: Bugzilla supports different types of custom
fields and can even display them based on the value of another field,
to only use them when they are relevant. Also support adding custom
fields to the bug database, to capture and search data that is unique
to the company.
 Custom Workflow: Bugzilla is built with a default list of bug status
and default workflow. But it can be further edited to better meet the
project requirement.
 Full support for Unicode: Bugzilla greatly supports Unicode and data
can be entered in Unicode and can be correctly searched and sorted.
 Localization: Administrators can configure the installations and
automatically serve correct, localized content to users.
 Control bug visibility and editing to a group: The control is too
advance, and it allows specific groups of the user to edit and the bugs.
 Sanity Check: Bugzilla’s Sanity Check scans your database for
inconsistencies. It reports errors and either offer to fix them
automatically or gives you links to help you fix the problem.

How Bugzilla Works

1. Login/Registration

 Use the following link: https://landfill.bugzilla.org/bugzilla-5.0-branch/


For creating a new account in Bugzilla go to the New Account option in
the main menu and to get login click on the login option in the main
menu.

 For Log in: The user just needs to enter the registered Email Address
and the Password and click on the Log in button. The user will be
directed to the Bugzilla- main Page.

 For creating the new account, Click on New Account & Enter a valid
Email Address.
 The user will receive an email to the entered email address and user
needs to click on the registration link for proceeding further for
registration.

 After clicking on the registration link in the email, the user will be
directed to the registration page, where need to fill the Real Name,
Password and Confirm Password. After that user needs to click on
Create button.
 Bugzilla also provides an option to cancel the account by providing a
Cancel button at the bottom left of the screen.
 After successful registration is done, the user will be redirected to the
Bugzilla- Main Page. The user can view the logged in user name in the
Main Page.

2. Creating a New Bug in Bugzilla

 For creating a new bug in Bugzilla, a user needs to click on the New
tab in the Main Page. The user can also report a bug from the File a
Bug option.

 After that user needs to select the specific product category from the
listing for which the bug is to be created or reported. The product is to
be added by the administrator.
 After selecting the desired category, the user will be redirected to the
bug reporting page which is referred as Bugzilla- Enter Bug Page. If
notice at the page label, then it can be seen that the product name is
also added, which signifies that the bug is reported for that specific
product.

In Bugzilla, enter Bug Page, the user can view the following bugs during
reporting bugs:

 Product: The product name will get pre-populated based on the


product selected on the previous product category page.
 Reporter: The reported field will also get pre-populated with the
logged in user email address/user name.
 Components: Components are second- level categories, each belongs
to a particular product. The user needs to select a component from the
list.
 Versions: The version field defines the particular version of the
software or product, where the defect is found.
 Severity: The severity field explains the level of severity of the bug,
that how severe the bugs is. It offers the following options in the drop-
down blocker, critical, normal, major, minor, trivial and enhancement.
 Hardware: The hardware field specifies the hardware used by the
device where the bug is found.
 OS: It defines the different operating system versions where the bug
was found like- Windows 10, Windows 8, Linux. Mac OS X 10.1, etc
 Summary: Summary is a short description of the bug which defines
what the bug is all about. One important feature of the summary
section is the duplicate check. A list of similar bug details will display in
the listing based on the entered text and user can identify if the bug is
reported earlier or not.
 Description: Bug description is the detail description of the bug
found. It may include the steps to reproduce, the bug actual behavior,
expected behavior and so on.
 Attachment: User can also attach screenshots or videos of the bug,
which helps it easier to replicate the bug. A user needs to upload the
file and give the description for the file uploaded.

 After entering all the details click on Submit Bug button. The bug will
get added to that project.
 The fields marked with red asterisks (*) are the mandatory fields.All
the above-mentioned field may vary based on the customization done
on Bugzilla.
 After the bug is created, a random Id (for example 44877 ) is assigned
to the bug.
 A user can also add additional information to the bug which will be
helpful in giving more detailed information about the created bug. Few
of the extra information are- URL, WhiteBoard, Keywords, Personal
tags, Depends On, Large Text Box, Blocks, Date Time, Bug ID Field
and so on.
 The user can also add the time estimation required for the bug to fix
and also the deadline for the bug. Also, can change the status of the
bug from Status drop down the list. Deadline in Bugzilla usually gives
the time-limit to resolve the bug in given time frame.
Exp 14: Open Ended Experiment- Mini Project (Not for Exam)
 Test Cases for Software Applications (Websites)
 Run through Selenium IDE
 Run through Eclipse

 Run through Selenium IDE:


How to add Selenium IDE in Mozilla Firefox (version 54)
1. Go to Tools from Menu Bar of Mozilla Firefox browser.
2. Click Add-ons and type Selenium IDE in search box.
3. Install the Selenium IDE. Selenium IDE will be added in your Tool Bar menu.

Procedure:
1. Open the Firefox Browser.
2. Type the following URL “https://www.microsoft.com/en-in/” in url edit box.
3. Click on the Tools in the Firefox Browser, select and click on Selenium IDE.
4. Selenium IDE window appears on the screen.
5. Selenium will be in default Record mode whenever opened first time.
6. Copy URL from the Firefox URL and paste it in the base url edit box of Selenium IDE.
7. Select any functional link on Microsoft website and view that particular link.
8. For every operation performed on the website there will be a command inserted in the
Selenium IDE.
9. Right click on the web page and we can see all the supported selenium commands. There are
Assert commands where we can verify the title page opened.
10. Once recording is done, Record button should be stopped.
11. Test case should be saved as microsoft.html.
 Run through Eclipse:
About Selenium Remote Control (RC) is a test tool that allows writing 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 favorite computer language.

Here is a simplified architectural representation....

Selenium Remote Control is great for testing complex AJAX-based web user interfaces under a
Continuous Integration system.
Eclipse has to be installed since we are going to write Java programs

Download selenium 2.28.0 version from website

http://Seleniumhq.org/download

From same website we need to download Java web driver.

Downloaded selenium server version is –

“selenium-server-standalone-2.28.0.jar”. This is a jar file.


Java web driver downloaded is “selenium-java-2.28.0.zip”. As this is a zip file this should be extracted.
When we extract this file, we get “selenium-java-2.28.0.jar” JAR file. This is an executable file. So we
have both server and also web driver JAR files.

We need to run server before writing any script code. Assume we have server under directory
C:\Seleniumserver\ then we need to go to command prompt and then go to respective folder where
Seleniumserver is located. Execute the following command to start server –

Java –jar selenium-server-standalone-2.28.0.jar 4444

Here 4444 refers to the port number where the server is listening.

How to use Selenium server & Java client Driver


Selenium Server and Java Client driver should be downloaded from Selenium website
http://seleniumhq.org/download . Selenium Server downloaded will be in JAR format whereas
Java client driver is Zip file hence it should be extracted to get JAR file. Save both the files under
drive D: /Seleniumserver.
Downloaded Selenium server version is “selenium-server-standalone-2.28.0.jar”.
Downloaded Selenium Java driver is “selenium-java-2.28.0.zip”

1. In Eclipse IDE need to create a new Java Project. Name the Java Project say – Myproject.
In Eclipse we can see “src” folder and “JRE System Library”. Since we need to write Java
Code where Selenium has to be recognised we need to include server and client JAR
file.
Procedure to include JAR file –
 Right click on the Java Project created, select Build path. In that select Configure
Build Path. New window gets opened where we can see different tabs – Source,
Projects, Libraries, Order and Export. Select Tab “Libraries”. We can see only JRE
System Library.
 Select Button “Add External JARs”. Browse and select Selenium Server Jar file we
can see a new entry along with JRE System Library.
 Select Button “Add External JARs” again, browse and select selenium Java driver
Jar file.
 We can see both Selenium server and Java driver JAR file.
2. Need to write script code in Java. In Eclipse IDE under “src” folder, right click and select
class – Give name to class say Google. In Eclipse we can see a new Demo.java file opened. Write
below code –

import junit.framework.*;
import com.thoughtworks.selenium.DefaultSelenium;
public class Demo extends TestCase
{
private DefaultSelenium selenium;
public void testing()
{
selenium=new
DefaultSelenium("localhost",4444,"*iexplore"," https://www.microsoft.com/en-in/” ");
selenium.start();
selenium.open("/");
selenium.waitForPageToLoad("30000");
}
}

2. In case we don’t add External JARs then selenium will not be recognized. This can be
checked once by removing external JARs.

3. Script code is ready, now need to start server. Go to command prompt; in command
prompt go to the folder where server JAR resides. In our case server is in
D: /Seleniumserver/ Go to that particular path and then start server by executing below
command

Java –jar selenium-server-standalone-2.28.0.jar 4444

Here 4444 refers to the port number where server listens to client request

You might also like