ST Lab Manual Updated
ST Lab Manual Updated
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
Frames
3. Selenium Components
– Selenium IDE
– Selenium Core
– Selenium RC
These are probably the most commonly used commands for building test.
Run a Test Case Click the Run button to run the currently displayed test case.
Run a Test Suite Click the Run All button to run all the test cases in the currently
loaded test suite.
Stop and 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.
EXPT NO :-4 Install Selenium server and demonstrate it using a script in Java/PHP
packagefirefoxdemo;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;
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");
System.out.println("Project is successful");
driver.quit(); //optional
}
} //note: students run the program ,take output snapshot and paste in the records.
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 {
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.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
System.out.println();
System.out.println();
System.out.println();
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;
workbook.write();
workbook.close();
} //close write function
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);
}
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
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;
try
{
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
catch (BiffException e)
{
System.out.println("Eception Error occured");
}
} //close read function
} //close class
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;
try
{
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
catch (BiffException e)
{
System.out.println("Eception Error occured");
}
} //close read function
} //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;
@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();
@AfterClass
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.*;
@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");
for(int i=0;i<option.length;i++)
{
System.out.println("OPtions:"+i+"is"+option[i]); //print options on console uotput screen
}
out.close( );
}
@AfterClass
public void tearDown( ) throws Exception{
selenium.stop( );
seleniumserver.stop( );
}
}
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
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);
}
}
}
2)
3)
Console screenshot
4)
Web driver screenshot
Console screenshot
5)
6)
Web driver screenshot
Console screenshot
8)
XL sheet:
Console output:
9)
XL sheet :
Console screenshot
10)XL sheet :
Console screenshot
11)
12)
(In the above XL sheet still contains numbers upto 31 -not shown)
13)
..