SOFTWARE TESTING 2018
EXPT NO :-1
Understand The Automation Testing Approach (Theory Concept)
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.
Benefits of Automation
Fast
Reliable
Repeatable
Programmable
Reusable
Makes Regression testing easy
Enables 24*78 Testing
Robust verification.
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
KIRAN JAYARAM Page 1
SOFTWARE TESTING 2018
Frames
3. Selenium Components
– Selenium IDE
– Selenium Core
– Selenium RC
3.1 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
3.1.1 Overview of Selenium IDE:
A.Test Case Pane
B. Toolbar
C.Menu Bar
D.Log/Reference/UI-Element/Rollup Pane
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
newpage 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
HTMLtag, is present on the page.
verifyText - verifies expected text and it’s corresponding HTML tag are
present onthe page.
verifyTable - verifies a table’s expected contents.
Running Test Cases
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.
KIRAN JAYARAM Page 2
SOFTWARE TESTING 2018
Stop and StartThe 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.
Test Suite:A test suite is a collection of tests. Often one will run all the tests in a
test suite asone continuous batch-job.
EXPT NO:-2 Using Selenium IDE, Write a test suite containing minimum 4 test
cases.
TC’S #1: Manual Steps:
Open (Example : Type www.google.com)
Type “Brindavan college” in the Google Search Input Box
Click Search Button
Verify the Text Present as “Brindavan college”
Assert the Title as “BREC - Google Search”.
Save the file with all actions recorded.
TC’S #2: Manual Steps:
Open (Example : Type www.google.com)
Type “venkateswara college” in the Google Search Input Box
Click Search Button
Verify the Text Present as “venkateswara college”
Assert the Title as “svce - Google Search”.
Save the file with all actions recorded.
TC’S #3: Manual Steps:
Open (Example : Type www.google.com)
Type “visweswaraiah college” in the Google Search Input Box
Click Search Button
Verify the Text Present as “visweswaraiah college”
Assert the Title as “MVIT - Google Search”.
Save the file with all actions recorded.
TC’S #4: Manual Steps:
Open (Example : Type www.google.com)
Type “Ramaiah college” in the Google Search Input Box
Click Search Button
Verify the Text Present as “Ramaiahcollege”
Assert the Title as “MSR - Google Search”.
KIRAN JAYARAM Page 3
SOFTWARE TESTING 2018
Save the file with all actions recorded.
Steps for creating test suite:
1. Create more Tc’s .
2. Open Firefox
3. Open Tools à Selenium IDE
4. Open à new Test Suite
5. Open à Add Test cases
6. Add more test cases
7. Run the test suite.
8. We can run individual test cases or we can run test suite as a whole.
KIRAN JAYARAM Page 4
SOFTWARE TESTING 2018
EXPT NO:-5Conduct a test suite for nay two web sites.
TC’S #1: Manual Steps:
Open (Example : Type www.Flipkart.com)
Click some 3 items and do back button for each click
Save the file with all actions recorded.
TC’S #2: Manual Steps:
Open (Example : Type www.amazon.com)
Click some 3 items and do back button for each click
Save the file with all actions recorded.
Steps for creating test suite:
1. Create more Tc’s .
2. Open Firefox
3. Open Tools à Selenium IDE
4. Open à new Test Suite
5. Open à Add Test cases
6. Add more test cases
7. Run the test suite.
8. We can run individual test cases or we can run test suite as a whole.
KIRAN JAYARAM Page 5
SOFTWARE TESTING 2018
EXPT NO :-4 Install Selenium server and demonstrate it using a script in Java/PHP
Installation of Selenium RC and Eclipse
Download Eclipse
download Selenium RCserver 2.53 / client driver and configure that to
Eclipse
create new project
create new package
create new class
add external libraries, jars in Build path (add selenium client ,server 2.53
and jdk7,8 library files)
write a simple java script in eclipse and run.
Java program:
packagefirefoxdemo;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;
public class firefox
{
public static void main(String[] args)
{
int a=10,b=20;
System.out.println("hello first showing simple java script of adding 2
numbers");
System.out.println(a+b);
System.out.println("Selenium demo");
WebDriver driver=new FirefoxDriver();
driver.get("http://www.facebook.com");
System.out.println("facebook page opened successfully using java
script");
driver.manage().window().maximize();
System.out.println("Project is successful");
driver.quit(); //optional
}
} //note: students run the program ,take output snapshot and paste in the records.
KIRAN JAYARAM Page 6
SOFTWARE TESTING 2018
Expt6: write and test a program to login a specific web page
open workspace
create new java project
use default jre
new package
new class
write program
add external jar- selenium server 2.53 jar
add external jar for character set etc,,,, from jre 1.7
change java compiler- compliance level from 1.4 to 1.6 (this option present
in build path)
program:
packagefirefoxdemo;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;
public class loginpage {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
System.out.println("Selenium web driver ruuning please wait");
System.out.println();
System.out.println();
System.out.println();
driver.get("https://www.facebook.com/");
driver.findElement(By.id("email")).sendKeys("username");
driver.findElement(By.id("pass")).sendKeys("password");
driver.findElement(By.id("loginbutton")).click();
System.out.print("Login is successfull");
}
}
Run and take snapshots and paste output.
KIRAN JAYARAM Page 7
SOFTWARE TESTING 2018
Expt:3 validation of each field of registration page.
package facebooktest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class test {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
System.out.println("Selenium web driver ruuning please wait");
System.out.println();
System.out.println();
System.out.println();
//open amazon registration page
driver.get("write amazon registration page link ");
//identify field by name and give your name
driver.findElement(By.name("customerName")).sendKeys("kiran");
//identify mail field and give
driver.findElement(By.name("email")).sendKeys("
[email protected]");
//identify password field and give
driver.findElement(By.name("password")).sendKeys("9035240524");
//identify confirm password
driver.findElement(By.name("passwordCheck")).sendKeys("9035240524");
//click create account button
driver.findElement(By.id("continue")).click( );
System.out.print("Each field validation is successfull and registration will be
complete after enter verification code that sent for my mail id");
}
KIRAN JAYARAM Page 8
SOFTWARE TESTING 2018
expt:9 Write and test a program to update 10 students details into the xl file.
Download jxl-2.6.12.jar
jxl jar files download
add this jxl as external library
program:
package demo;
importjava.io.File;
importjava.io.IOException;
importjava.util.Locale;
importjxl.CellView;
importjxl.Workbook;
importjxl.WorkbookSettings;
importjxl.format.UnderlineStyle;
importjxl.write.*;
importjxl.write.Number;
importjxl.write.biff.RowsExceededException;
public class Student
{
privateWritableCellFormattimesBoldUnderline;
privateWritableCellFormat times;
private String inputFile;
public void setOutputFile(String inputFile)
{ this.inputFile = inputFile; }
public void write() throws IOException, WriteException
{
File file = new File(inputFile);
WorkbookSettingswbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings);
workbook.createSheet("Report", 0);
WritableSheetexcelSheet = workbook.getSheet(0);
createLabel(excelSheet);
createContent(excelSheet);
workbook.write();
workbook.close();
} //close write function
KIRAN JAYARAM Page 9
SOFTWARE TESTING 2018
private void createLabel(WritableSheet sheet) throws WriteException
{
// Lets create a times font
WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
// Define the cell format
times = new WritableCellFormat(times10pt);
// Lets automatically wrap the cells
times.setWrap(true);
// Create a bold font with underlines
WritableFont times10ptBoldUnderline = new WritableFont(
WritableFont.TIMES, 10, WritableFont.BOLD, false,
UnderlineStyle.SINGLE);
timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
// Lets automatically wrap the cells
timesBoldUnderline.setWrap(true);
CellView cv = new CellView();
cv.setFormat(times);
cv.setFormat(timesBoldUnderline);
// Write a few headers
addCaption(sheet, 0, 0, "Student Name");
addCaption(sheet, 1, 0, "Subject 1");
addCaption(sheet, 2, 0, "subject 2");
addCaption(sheet, 3, 0, "subject 3");
}
private void createContent(WritableSheet sheet) throws WriteException, RowsExceededException
{
// Write a few number
for (int i = 1; i <= 10; i++)
{
// First column
addLabel(sheet, 0, i, "Student " + i);
// Second column
addNumber(sheet, 1, i, (i+30));
addNumber(sheet, 2, i, (i+40));
addNumber(sheet, 3, i, (i+50));
}
}
private void addCaption(WritableSheet sheet, int column, int row, String s)
throwsRowsExceededException, WriteException
{
Label label;
label = new Label(column, row, s, timesBoldUnderline);
sheet.addCell(label);
}
KIRAN JAYARAM Page 10
SOFTWARE TESTING 2018
private void addNumber(WritableSheet sheet, int column, int row, int i) throws WriteException,
RowsExceededException
{
Number number;
number = new Number(column, row, i, times);
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, times);
sheet.addCell(label);
}
public static void main(String[] args) throws WriteException, IOException
{
Student test = new Student();
test.setOutputFile("D:/jk.xls");
test.write();
System.out.println("program runs successfully\n\n");
System.out.println("Please check the result file under D:/jk.xls ");
} //close main
} //close class
Run the program take snapshots and paste
KIRAN JAYARAM Page 11
SOFTWARE TESTING 2018
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 ).
package demo;
importjava.io.File;
importjava.io.IOException;
importjxl.*;
importjxl.read.biff.BiffException;
public class morethan60
{
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);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
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;
}
KIRAN JAYARAM Page 12
SOFTWARE TESTING 2018
}
}
}
System.out.println("Total number of students who scored more than 60 in one or more subjects is:" +count);
}
catch (BiffException e)
{
System.out.println("Eception Error occured");
}
} //close read function
public static void main(String[] args) throws IOException
{
morethan60 test = new morethan60 ( );
test.setInputFile("D:\\jk.xls");
test.read( );
} //close main
} //close class
Run and take snapshots and paste.
KIRAN JAYARAM Page 13
SOFTWARE TESTING 2018
8) write and test program to find out list of employees having salary greater than
50000 and age between 30 and 40 years.
package proj8;
import java.io.File;
import java.io.IOException;
import jxl.*;
import jxl.read.biff.BiffException;
public class Salary
{
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);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
for (int j = 0; j <sheet.getRows(); j++)
{
for (int i = 0; i <sheet.getColumns(); i++)
{
Cell cell1 = sheet.getCell(1, j);
Cell cell2 = sheet.getCell(2, j);
if (cell1.getType() == CellType.NUMBER && cell2.getType() == CellType.NUMBER )
{
if(Integer.parseInt(cell1.getContents())>40000 &&
(Integer.parseInt(cell2.getContents())>=30 &&Integer.parseInt(cell2.getContents())<=40))
{
flag = true;
if(flag == true)
{
count++;
flag=false;
}
break;
}
}
}
}
System.out.println("Total number of Employees whose salary more than 40000 and age between
30 and 40 is:" +count);
}
catch (BiffException e)
{
System.out.println("Eception Error occured");
}
} //close read function
KIRAN JAYARAM Page 14
SOFTWARE TESTING 2018
public static void main(String[] args) throws IOException
{
Salary test = new Salary ();
test.setInputFile("D:\\employee.xls");
test.read();
} //close main
} //close class
expt--11 //write and test the program to provide number of objects present on the page.
solution:
step 1: install selenium 2.53 server jar
step 2: select testNg library if not present install testNG libraries (goto ecclipse Help -->
install new software --> Add --> copy location address from testNG install plugin
(http://beust.com/eclipse) --> click finish )
step 3: Add new java project --> new package --> add new testNG class (students should
select other)
step 4: write the testNG class program
step 5: run testNG
program:
package object1;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
import org.testng.annotations.Test;
public class count
{
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 f( ) throws Exception
{
selenium.open("http://www.google.co.in/");
selenium.windowMaximize();
KIRAN JAYARAM Page 15
SOFTWARE TESTING 2018
String lc[ ]=selenium.getAllLinks();
System.out.println("Total links are="+lc.length);
String bc[ ]=selenium.getAllButtons();
System.out.println("Total buttons are="+bc.length);
String fc[ ]=selenium.getAllFields();
System.out.println("Total input fields are="+fc.length);
@AfterClass
public void tearDown( ) throws Exception
{
selenium.stop( );
seleniumserver.stop( );
}
KIRAN JAYARAM Page 16
SOFTWARE TESTING 2018
expt—12 : write and test program to get the number of list of items in a list / combo
box.
package list1;
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.*;
public class listitems
{
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 f( ) throws Exception
{
selenium.open("http://www.facebook.com");
selenium.waitForPageToLoad("3000");
String[ ] option=selenium.getSelectOptions("name=birthday_day");
File file=new File("C:\\Users\\KIRAN JAYARAM\\Desktop\\3.xls");
BufferedWriter out= new BufferedWriter(new FileWriter(file));
out.write("Options in the dropdown\n");
for(int i=0;i<option.length;i++)
{
System.out.println("OPtions:"+i+"is"+option[i]); //print options on console uotput screen
out.write(" "+option[i]); //to write into the the file
out.newLine( );
}
out.close( );
}
@AfterClass
public void tearDown( ) throws Exception{
selenium.stop( );
seleniumserver.stop( );
}
}
KIRAN JAYARAM Page 17
SOFTWARE TESTING 2018
Expt:13 Write and test program to get the number of items(files and folders) present
on the desktop.
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 in notepad with the following code and save as count.vbs
under the D Drive
count.vbs saved in D drive
Set fso = createobject("Scripting.FileSystemObject")
DesktopPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
msgbox "The number of files on the desktop is : " &fso.GetFolder(DesktopPath).Files.Count
'comment:Files count fso means file system object
msgbox "The number of folders on the desktop is : " &fso.GetFolder(DesktopPath).SubFolders.Count
'comment:Folders count
In eclipse write the following code in eclipse and run as normal.
package count;
import java.io.*;
public class count1
{
public static void main(String[] args)
{
try
{
Runtime.getRuntime().exec("wscript D:\\count.vbs");
}
catch (IOException e)
{
System.exit(0);
}
}
}
KIRAN JAYARAM Page 18
SOFTWARE TESTING 2018
2)
KIRAN JAYARAM Page 19
SOFTWARE TESTING 2018
3)
Console screenshot
4)
Web driver screenshot
Console screenshot
KIRAN JAYARAM Page 20
SOFTWARE TESTING 2018
5)
KIRAN JAYARAM Page 21
SOFTWARE TESTING 2018
6)
Web driver screenshot
Console screenshot
8)
XL sheet:
KIRAN JAYARAM Page 22
SOFTWARE TESTING 2018
Console output:
9)
XL sheet :
Console screenshot
KIRAN JAYARAM Page 23
SOFTWARE TESTING 2018
10)XL sheet :
Console screenshot
11)
KIRAN JAYARAM Page 24
SOFTWARE TESTING 2018
12)
(In the above XL sheet still contains numbers upto 31 -not shown)
13)
..
KIRAN JAYARAM Page 25