0% found this document useful (0 votes)
3 views

Software Testing Lab

The document outlines the Software Testing Laboratory course for the MCA II Semester, detailing the certification process and listing various laboratory programs related to Selenium IDE and Web Driver. It includes instructions for designing test cases, installing necessary software, and creating automation programs. The document serves as a comprehensive guide for students to complete their practical assignments in software testing.

Uploaded by

Sudha Mani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Software Testing Lab

The document outlines the Software Testing Laboratory course for the MCA II Semester, detailing the certification process and listing various laboratory programs related to Selenium IDE and Web Driver. It includes instructions for designing test cases, installing necessary software, and creating automation programs. The document serves as a comprehensive guide for students to complete their practical assignments in software testing.

Uploaded by

Sudha Mani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

2020-21 20MCAL29 INH20MC001

DEPARTMENT OF MCA

II SEMESTER

Software Testing Laboratory


(20MCAL29)

NAME
USN

2020-21

NHCE Page 1
2020-21 20MCAL29 INH20MC001

DEPARTMENT OF MCA

CERTIFICATE

This is to certify ________________________________________________, bearing USN

No. ___________________of MCA I SEMESTER has satisfactorily completed the

Laboratory Programs in Testing Lab, Subject Code – 20MCAL29 as prescribed by the

Syllabus during the year 2020-21.

---------------------------------------- --------------------------------------------

Signature of Course Co-ordinator Signature of Head of the Department

------------------------------------ --------------------------------------------

Internal Examiner External Examiner

Date of Examination:

NHCE Page 2
2020-21 20MCAL29 INH20MC001

INDEX

SOFTWARE TESTING LAB

Sl.
Program Date Page No.
No.

1. Designing and Recording test cases using 3-6


Selenium IDE

2. Designing and Recording test suites using 7-8


Selenium IDE

3. Installation of Selenium Web Driver 9-14

4. Automation program to login into a webpage 15-16

5. An automation program to test whether a test 17-18


case has passed or failed

A program to read the contents of an excel file


6. and printing the contents on the selenium output 19-20
console using jxl

7. Program to count the total number of hyperlink 21-22


objects present on a webpage

8. Program to count the total number of items in a 23-25


list (or) a combo box
Program to switch between web pages and
9 performing certain actions using Mozilla web 26-27
browser

10. A test program to automate the registration page 28-30


of any e-commerce website.

NHCE Page 3
2020-21 20MCAL29 INH20MC001

1. Designing and Recording Test Cases Using Selenium


IDE

✓ Open Firefox that has the IDE installed


✓ Open the base URL of the application to record
✓ Go To Tools Selenium IDE and the IDE will be opened
✓ Now perform the operations on the application as you are testing the
application
✓ Once you are done with the recording click on the stop recording button
save the test case through the file menu. By default it will be saved as a
Selenese script (.side format)

Command Table
Command: Command column describes name of command
Target: Target column describes Target element id or name or Xpath
Value: Value column describes Value of an element

NHCE Page 4
2020-21 20MCAL29 INH20MC001

Wait and wait for


✓ Selenium IDE will now automatically wait for you, at every command
✓ Every command will wait for the page to load
✓ Commands which take a locator will wait for the element to appear
✓ Hopefully this will eliminate the need for explicit waiting
✓ In case that is not enough, the pause command can be used instead

Recording
✓ During recording, Selenium-IDE will automatically insert commands into
your test case based on your actions
✓ Typically, this will include:
▪ clicking a link - click or click at commands
▪ entering values - type command
▪ selecting options from a drop-down listbox - select command
▪ clicking checkboxes or radio buttons - click command

Verifications and Asserts With the Context Menu

✓ While Recording Script, Right Click anywhere on the page


NHCE Page 5
2020-21 20MCAL29 INH20MC001

✓ You will see a context menu showing verify and/or assert commands

Editing
✓ Insert Command Right-click and select Insert Command
✓ Insert Comment Comments may be added to make your test case more
readable
✓ Edit a Command or Comment Select the line to be changed ,edit it using
the Command, Target, Value and Comment fields
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
✓ Pause and Star
The Pause button can be used to stop the test case while it is running
The icon of this button then changes to indicate the run is paused
To continue click it again, or click the Run button
✓ Stop in the Middle
-You can set a breakpoint in the test case to cause it to stop on a
particular command
-Select a command, right-click, and from the context menu select
Toggle Breakpoint
✓ Start from the Middle
-You can tell the IDE to begin running from a specific command in the

NHCE Page 6
2020-21 20MCAL29 INH20MC001

middle of the test case


- Select a command, right-click, and from the context menu click Play
from here
✓ Run Any Single Command
-Double-click any single command to run it by itself

Selenese
Selenium commands known as SELENESE Sequence of selenese forms test
script Types of Selenese Actions
• Commands that do user action like click, sendKeys Accesors
• Examine / access the current state of application-under test
Assertions
• Verify/validate the expected results
• Few commands comes with parameters (They are optional and
depends on the command)

NHCE Page 7
2020-21 20MCAL29 INH20MC001

2. Designing test suites using Selenium IDE

• Open
Opens a page using a URL
• Click
Performs a click operation, and optionally waits for a new page to load
• Verify Title/assert Title
Verifies an expected page title
• Verify Text Present
Verifies expected text is somewhere on the page
• Verify Element Present
Verifies an expected UI element, as defined by its HTML tag, is present on

from here
• Verify Text

NHCE Page 8
2020-21 20MCAL29 INH20MC001

Verifies expected text and its corresponding HTML tag are present on the
page
• Verify Table
Verifies a table’s expected contents
Test Scenario
✓ Launch way2sms
✓ Type Phone number
✓ Type Password
✓ Click Login
✓ After Page Load Verify text
✓ logout

Limitations of Selenium IDE


✓ Can run the test only on Firefox.Chrome
✓ No Programming login (like loops,conditional statements) can be applied
✓ Selenium IDE can execute scripts created in Selenese only
✓ It is difficult to use Selenium IDE for checking complex test cases

NHCE Page 9
2020-21 20MCAL29 INH20MC001

3. Installation of Selenium Web Driver


Establish Test Environment

JDK SETUP STEPS

➢ Check Computer OS bit Size Ex: 32bit or 64 bit?

32 bit (windows x86)

64 bit (windows x64)

Download JDK8 wrt the bit size of your OS

Click JDK Link wrt bit size of OS

Example : JDK x86 for 32bit

JDK x64 fro 64bit OS

Configuring Computer with Java

a) Goto JDK folder in C:\Programfiles\Java\JDK1.8.0

NHCE Page 10
2020-21 20MCAL29 INH20MC001

e) Copy Path of JDK Folder

f) Right Click on MyComputer Icon

g) Go to the Properties of your System

h) Advanced System Settings

i) Environment Variables

j) Click New for System Variables

Variable name: JAVA_HOME

Variable value: c:\programfiels\java\jdk18.0_20

OK Cancel

k) Click OK

l) Go to Path Variable->Select Path->Click Edit ->Without Disturbing Existing


Path

Paste

c:\programfiels\java\jdk18.0_20\bin;

To check JDK installed Properly or not?

a) Open Command prompt Type cmd in Start search

Enter Following Commands

C:\> D:

D:\> java

D:\> javac

u will be able to see www.oracle.com.............

ECLIPSE IDE Setup

NHCE Page 11
2020-21 20MCAL29 INH20MC001

a) Go to google Click next until Finish

b) Enter Eclipse Juno SR2 download

c) Click Search.

e) Go to Eclipse.org.site

f) Go to windows 32 bit or 64 bit

g) Click Download

h) Paste that download in Personal folder

g) Extract that download in Personal Folder

h) Open Eclipse Folder after Extract

i) You will find Eclipse Icon

j) Right click on Icon

k) Select Desktop (Create Short Cut)

l) Eclipse Ide will be visible on Desktop

m) Double click on Eclipse Icon

n) Then you will find for first time Workspace Option

o) Select your Personal Folder

p) To change workspace folder

q) Go to file menu in Eclipse

r) Switch to Workspace

s) Other

JAVA PROJECT CREATION IN ECLIPSE

NHCE Page 12
2020-21 20MCAL29 INH20MC001

a) Eclipse

b) File

c) New

d) Select Option Other

e) Choose Java Project

f) New Java Project

g) Project Name (Lowercase Only)

h) Place Tick on Default Location

i) Click Finish

j) Project Created

JAVA PROJECT CREATION IN ECLIPSE

Note:-

After Completion of Java Project Creation in Eclipse,

Check JRE Version(Run Time Version)

1. Right Click on Java Project

2. Properties

3. Java Compiler

4. Change to Latest Version (1.8)

Java Build Path

1. Libraries

NHCE Page 13
2020-21 20MCAL29 INH20MC001

2. Remove Lower Version JRE System-> Library

3. Click (Add Library)

4. Select JRE System Library as Latest (1.8)

5. Click Finish

6. Click Ok

JAVA PACKAGE CREATION

a) Right Click on Java Project File

b) New

c) Package

d) Enter name to Package(Lowercase)

e) Click Finish

CLASS CREATION IN JAVA PACKAGE

To Create a Class with main Method

a) Right Click on Package

b) New

c) Class

d) Enter Name to Class in Name Blank

e) Class name Starts with Uppercase(Ex: Test)

Note:Do Tick mark on Public Static void main(stringargs[]) Click Finish

f) Select main method option

g) Click Finish

Selenium Web Driver Setup in ECLIPSE

NHCE Page 14
2020-21 20MCAL29 INH20MC001

a) Goto Google

b) Enter Selenium Web Driver Download

c) Go to seleniumhq.org site

d) Click Download for Selenium Web Driver (Java Based)

e) Paste that Download in Personal Folder

f) Extract Download

g) Lib folder and one jar file Externally Available

h) Right Click on Project in Eclipse IDE

i) Properties

j) Java Build Path

k) Libraries

l) Add External Jars

m) Browse Selenium Web Driver Jars

Lib folder inside jars

Lib folder out side jars

n) click Ok

NHCE Page 15
2020-21 20MCAL29 INH20MC001

4. Automation Program to login into a webpage


package webdrivercommand;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Loginwebpage
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C://Selenium//chromedriver.exe");

WebDriver driver=new ChromeDriver();


driver.get("https://www.google.com/");

NHCE Page 16
2020-21 20MCAL29 INH20MC001

Thread.sleep(5000);
driver.close();
}
}

Output:

NHCE Page 17
2020-21 20MCAL29 INH20MC001

5. An automation program to check whether a test case


has passed or failed
package webdrivercommand;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
Public class Login
{
Public static void main(String[] args) throws InterruptedException
{

NHCE Page 18
2020-21 20MCAL29 INH20MC001

System.setProperty("webdriver.chrome.driver","C://Selenium//chromedriver.exe");

WebDriver driver=new ChromeDriver();


driver.get("http://www.way2sms.com/");
Thread.sleep(5000);
driver.findElement(By.id("mobileNo")).sendKeys("9700339582");
Thread.sleep(5000);
driver.findElement(By.name("password")).sendKeys("hanuman");
Thread.sleep(5000);
driver.findElement(By.xpath("//b[@id='mainErr']/following::*[5]")).click();
Thread.sleep(5000);
String o="http://www.way2sms.com/send-sms";
String z=driver.getCurrentUrl();
if(z.equals(o))
{
System.out.println("Login Sucessful_Test Passed");
}
else
{
System.out.println("Login UnSucessful_TestFailed");
}
driver.close();
}
}

OUTPUT

NHCE Page 19
2020-21 20MCAL29 INH20MC001

6. A program to read the contents of an excel file and


printing the contents on the selenium output
console using jxl

package Webdrivercommand;

import java.io.FileInputStream;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;

NHCE Page 20
2020-21 20MCAL29 INH20MC001

import jxl.read.biff.BiffException;
public class ReadExcelFile
{
public void readExcel() throws BiffException,IOException
{
String Filepath="C:\\Users\\Mamatha\\Desktop\\sampledoc1.xls";
FileInputStream fs=new FileInputStream(Filepath);
Workbook wb = Workbook.getWorkbook(fs);
Sheet sh=wb.getSheet("Sheet1");
int total_no_of_rows=sh.getRows();
int total_no_of_columns=sh.getColumns();
for(int row=0;row<total_no_of_rows;row++)
{
for(int col=0;col<total_no_of_columns;col++)
{
System.out.print(sh.getCell(col,row).getContents() +"\t");
}
System.out.println();
}
}
public static void main(String args[]) throws BiffException,IOException
{
ReadExcelFile DT=new ReadExcelFile();
DT.readExcel();
}

NHCE Page 21
2020-21 20MCAL29 INH20MC001

}
OUTPUT

7. Program to count the total number of hyperlink


objects present on a webpage
package webdrivercommand;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Totalnoofobjects
{

NHCE Page 22
2020-21 20MCAL29 INH20MC001

Public static void main(String[] args) throws InterruptedException


{
System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver.exe");

WebDriver driver = new ChromeDriver();


Thread.sleep(5000);
driver.get("http://demo.guru99.com/test/newtours//");
Thread.sleep(5000);
List<WebElement>e = driver.findElements(By.tagName("a"));
System.out.println(e.size());
for(inti=0; i<e.size(); i=i+1)
{
System.out.println(e.get(i).getText());
}
driver.close();
}
}
OUTPUT

NHCE Page 23
2020-21 20MCAL29 INH20MC001

NHCE Page 24
2020-21 20MCAL29 INH20MC001

8. Program to count the total number of objects


present in a list (or) combo box
package webdrivercommand;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class Totalnoofobjectscombobox
{
Public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C://Selenium//chromedriver.exe");

WebDriver driver=new ChromeDriver();


driver.get("http://demo.guru99.com/test/newtours//");
Thread.sleep(5000);
driver.findElement(By.linkText("REGISTER")).click();
Thread.sleep(5000);
driver.findElement(By.name("firstName")).sendKeys("Madhwaraj");
Thread.sleep(5000);
driver.findElement(By.name("lastName")).sendKeys("Prof");
Thread.sleep(5000);
driver.findElement(By.name("phone")).sendKeys("9703336699");
Thread.sleep(5000);

NHCE Page 25
2020-21 20MCAL29 INH20MC001

driver.findElement(By.id("userName")).sendKeys("[email protected]");
Thread.sleep(5000);
driver.findElement(By.name("address1")).sendKeys("chennaifasf");
Thread.sleep(5000);
driver.findElement(By.name("city")).sendKeys("chennai");
Thread.sleep(5000);
driver.findElement(By.name("state")).sendKeys("TN");
Thread.sleep(5000);
driver.findElement(By.name("postalCode")).sendKeys("5000221");
Thread.sleep(5000);
Select s=newSelect((driver.findElement(By.name("country"))));
List <WebElement>listOptionDropdown = s.getOptions();
Int dropdownCount = listOptionDropdown.size();
System.out.println("Total Number of item count in dropdown list = " +
dropdownCount);
s.selectByVisibleText("INDIA");
Thread.sleep(5000);
driver.findElement(By.id("email")).sendKeys("[email protected]");
Thread.sleep(5000);
driver.findElement(By.name("password")).sendKeys("Madhvaraj");
Thread.sleep(5000);
driver.findElement(By.name("confirmPassword")).sendKeys("Madhvaraj");
Thread.sleep(5000);
driver.close();
}

NHCE Page 26
2020-21 20MCAL29 INH20MC001

OUTPUT

NHCE Page 27
2020-21 20MCAL29 INH20MC001

9. Switching between web pages and performing


certain actions using Mozilla web browser
package Webdrivercommand;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Mozilla
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.gecko.driver","C://Madhwaraj//geckodriver.exe");

WebDriver driver=new FirefoxDriver();


driver.get("https://www.google.com/");
String baseurl=driver.getCurrentUrl();
System.out.println(baseurl);
Thread.sleep(5000);
driver.navigate().to("https://seleniummaster.com/llc/");
String tourl=driver.getCurrentUrl();
System.out.println(tourl);
Thread.sleep(5000);
driver.navigate().back();
String backurl=driver.getCurrentUrl();
System.out.println(backurl);
Thread.sleep(5000);
NHCE Page 28
2020-21 20MCAL29 INH20MC001

driver.navigate().refresh();
String refreshurl=driver.getCurrentUrl();
System.out.println(refreshurl);
Thread.sleep(5000);
driver.navigate().to("https://seleniummaster.com/llc/");
String tourl1=driver.getCurrentUrl();
System.out.println(tourl1);
Thread.sleep(5000);
driver.manage().window().maximize();
Thread.sleep(5000);
driver.close();
}
}
OUTPUT

NHCE Page 29
2020-21 20MCAL29 INH20MC001

10. A test program to automate the registration


page of any e-commerce website
package Webdrivercommand;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class Register_ecommerce
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C://Selenium//chromedriver.exe");

WebDriver driver=new ChromeDriver();


String URL="http://automationpractice.com/index.php";
driver.get(URL);
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.MILLISECONDS);
driver.manage().window().maximize();
driver.findElement(By.linkText("Sign in")).click();

NHCE Page 30
2020-21 20MCAL29 INH20MC001

driver.findElement(By.cssSelector("[name='email_create']")).sendKeys("mk34
[email protected]");
driver.findElement(By.xpath("//button[@name=\"SubmitCreate\"]")).click();
driver.findElement(By.xpath("//input[@id=\"id_gender1\"]")).click();
driver.findElement(By.name("customer_firstname")).sendKeys("Test User");
driver.findElement(By.name("customer_lastname")).sendKeys("Vsoft");
driver.findElement(By.id("passwd")).sendKeys("PKR@PKR");
driver.findElement(By.id("firstname")).sendKeys("Test User");
driver.findElement(By.id("lastname")).sendKeys("Vsoft");
driver.findElement(By.id("company")).sendKeys("Vsoft");
driver.findElement(By.id("address1")).sendKeys("Test 81/1,2nd cross");
driver.findElement(By.id("city")).sendKeys("XYZ");
WebElement statedropdown=driver.findElement(By.name("id_state"));
Select oSelect=new Select(statedropdown);
oSelect.selectByValue("4");
driver.findElement(By.name("postcode")).sendKeys("51838");
WebElement countrydropDown=driver.findElement(By.name("id_country"));
Select oSelectC=new Select(countrydropDown);
oSelectC.selectByVisibleText("United States");
driver.findElement(By.id("phone_mobile")).sendKeys("234567890");
driver.findElement(By.xpath("//input[@name=\"alias\"]")).clear();
driver.findElement(By.xpath("//input[@name=\"alias\"]")).sendKeys("Office")
;
driver.findElement(By.name("submitAccount")).click();

NHCE Page 31
2020-21 20MCAL29 INH20MC001

String
userText=driver.findElement(By.xpath("//*[@id=\"header\"]/div[2]/div/div/nav
/div[1]/a")).getText();
if(userText.contains("Vsoft"))
{
System.out.println("User Verified,Test case Passed");
}
else
{
System.out.println("User Verification Failed,Test case Failed");
}
}
}
OUTPUT

NHCE Page 32
2020-21 20MCAL29 INH20MC001

NHCE Page 33

You might also like