You are on page 1of 37

MCA52L Software Quality and Testing

Lab Program 1: Understand the concepts of Manual Testing - Login Page

Objective :

To understand the concepts involved in manual testing of any web page.

Test Purpose Pre- Input Excepted Actual


Case Conditi Outputs Output Result
ID ons
Test To test User Proper URL(https Gmail Home Pass
Case Credentials URl for ://ww.gma Home Page Page is
1 Gmail il.com) should Displayed
open
Test To check Give Username Wrong Wrong Pass
Case wrong User wrong =”exampl Username Username
2 name Userna e@”
me
Test To check Provide Password Wrong Logged Fail
Case wrong wrong =”abcd” Password into Gmail
3 Password Passwor
d
Test To check Provide Username Wrong Wrong pass
Case Correct Proper =example password Password
4 Username Userna @gmail.c
with wrong me and om
Password incorrec Password
t =”adbc12
Passwor 3”
d
Test Login with Proper Username Logged in Login into pass
Case proper usernam =example to Gmail Gmail
5 Credentials e and @gmail.c
passwor om
d Password
=”exampl
e123”

1|Page
MCA52L Software Quality and Testing

Test Case 1 : URL(“https://www.gmail.com”)

Test Case 2: To check for wrong username

2|Page
MCA52L Software Quality and Testing

Test Case 3: To check for wrong password

3|Page
MCA52L Software Quality and Testing

Lab Program 2: Understand Automation Testing Approaches

Introduction:
What is Automation?
- Automation is making a process automatic, eliminating the need for human
intervention.
- Is a self-controlling or self-moving process.
- Automation software offers automation wizard and commands of its own in
addition to providing task recording and re-play capabilities.
- Using these tools we can record the task
- Then if needed use the editor to edit the task, add new commands or using GUI
automation
wizards

Benefits of Automation
Fast: test automation runs faster than human users
Reliable: it performs precisely the same operations at each time elimination
human errors
Repeatable: It performs the same operation with different combination of data
in a less time
Programmable: We can use sophisticated tests that brings out hidden
information
Reusable: We can develop reusable components which can run on different
versions of application under test
Regression testing: easy to conduct regression test
Enabling 24*7 testing: test can be schedule and supports unattended recovery
Robust Verification: Support robust verification mechanism than any other
testing tools

Which tests should be Automated?


1. Tests executed for each software build
2. Tests which can be easily automated
3. Business critical tests
4. tests that are difficult to perform manually

Test artefacts (tools):


Requirements: the requirements that are being tested are stored into the
repository. This feature enables us to map the requirements to test cases and test
scripts.
Test Plan: Design the tests and build the test plan on it using the test
management tool.

4|Page
MCA52L Software Quality and Testing

The test plan will be maintained in a central repository. This will help to
produce reusable tests cases in future. The information is sharable and
preserved.
Test case: Contains description of test case and test steps.

Test script: Automated test script associated with each test case will be stored in
the quality center repository.

Test sets: This will be a set of selected test cases and associated test scripts. The
tests sets are executed from the quality center onto remote machines. The status
of each execution is stored in the respective test case execution status. The status
can be either pass/fail, it doesn’t maintain the exact details of the execution.

Test logs: The test script execution logs are stored in global repository. It contains
the status of each test case.

Reusable components: The repetitive functions that are invoked in most of the
functions are stored, which reduces the coding redundancies.

Object repository: contains the declaration of the application objects.

Data sheets: contains the test data used for execution. it can be populated by the
database or manually.

Automation Activity:
Record the application GUI
Write Script
Execute script
Review the script
Modify script if any changes.
Execute scripts on at least two machines
Store the script in central repository
Execute the script from central repository
Verify the execution status in central repository
Verify the test logs on common server
Prepare the test reports

5|Page
MCA52L Software Quality and Testing

Lab Program 3: 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
Thought works.
• 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 -
1. JavaScript
2. DHTML
3. Frames

3. Selenium Components
– Selenium IDE
– Selenium RC
– Selenium WebDriver
– Selenium Grid

Selenium IDE

✓ Selenium IDE is an integrated development environment for Selenium


tests.

✓ It is implemented as a Firefox extension, and allows you to record, edit,


and replay the test in Firefox.

✓ Selenium IDE allows you to save tests as HTML, Java, Ruby scripts, or
any other format

✓ It allows you to automatically add assertions to all the pages.

✓ Allows you to add Selenese commands as and when required

6|Page
MCA52L Software Quality and Testing

✓ It’s an easy-to-use Chrome and Firefox extension

✓ Record and Play back user action in WebApp

✓ It’s not Recommended for stable , long staying Test Suites

✓ Test only on Chrome, Firefox Browser

Installing the IDE

✓ Download the IDE using Chrome or Firefox

✓ Click on Add to Chrome or Add to Firefox.

✓ After Installation a button will appear on the right hand side of the
address bar.

Opening the IDE

✓ To run the Selenium IDE, simply click the button to the right of the
address bar.

✓ It opens as follows with an empty script-editing window and buttons to


open a project or save one.

7|Page
MCA52L Software Quality and Testing

Run Current Test Step

Run All: Speed Control

Pause/Resume
Navigation Panel Stop:

Test Case Panel

✓ Speed Control: controls how fast your test case runs.

✓ Run All: Runs the entire test suite when a test suite with multiple test
cases is loaded.

8|Page
MCA52L Software Quality and Testing

✓ Run: Runs the currently selected test. When only a single test is loaded
this button and the Run All button have the same effect.

✓ Pause/Resume: Allows pausing and resuming of the running test case.

✓ Stop: Stops the current running test case.

✓ Step: Allows you to “step” through a test case by running it one


command at a time. Use for debugging test cases.

✓ Record: Records the user’s browser actions.

9|Page
MCA52L Software Quality and Testing

Lab Program 4: Designing and Recording Test Cases

✓ 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
and 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

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.

10 | P a g e
MCA52L Software Quality and Testing

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.

✓ 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.

11 | P a g e
MCA52L Software Quality and Testing

✓ 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

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

12 | P a g e
MCA52L Software Quality and Testing

Assertions

• Verify/validate the expected results

• Few commands comes with parameters (They are optional and depends on

the command)

13 | P a g e
MCA52L Software Quality and Testing

Lab Program 5: Designing test suites using Selenese Commands

• Open

Opens a page using a URL.

• Click

Performs a click operation, and optionally waits for a new page to load.

• VerifyTitle/assertTitle

Verifies an expected page title.

• VerifyTextPresent

Verifies expected text is somewhere on the page.

• VerifyElementPresent

Verifies an expected UI element, as defined by its HTML tag, is present on


the page.

• VerifyText

Verifies expected text and its corresponding HTML tag are present on the
page.

• VerifyTable

Verifies a table’s expected contents.

Test Scenario

✓ Launch way2sms
✓ Type Phone number
✓ Type Password
✓ Click Login
✓ After Page Load Verify text
✓ logout

14 | P a g e
MCA52L Software Quality and Testing

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 .

15 | P a g e
MCA52L Software Quality and Testing

Lab Program 6: Installation of Selenium server - 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)

Now follow below Navigation to Download JDK8 wrt bit size of OS

a) Launch Google Browser .

b) Enter JDK8 Download

c) Click Search

d) goto Oracle.com.site

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-
downloads-2133151.html

Java SE Development Kit

e) Accept License Agreement RADIO BUTTON

f) Click JDK Link wrt bit size of OS

ex: JDK x86 for 32bit

JDK x64 fro 64bit OS

g) Paste that download in your selected folder

h) Create Personal Folder in your selected Drive

i) Paste that download into your Personal Folder without Space


EXAMPLE: Automation

Configuring Computer with Java

a) Open your Personal Folder and Double Click on Download Enter JDK8
Download

16 | P a g e
MCA52L Software Quality and Testing

b) Click next until Finish

c) After Installing check Java Folder in your C drive-programfiles-


javafolder-jdk

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

e) Copy Path of JDK Folder

f) Right Click on MyComputer Icon

g) Go to Properties

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) Goto Path Variable->Select Path->Click Edit ->Without Distrubing


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.............

17 | P a g e
MCA52L Software Quality and Testing

ECLIPSE IDE Setup

a) Goto 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) Goto file menu in Eclipse

r) Switch to Workspace

s) Other

JAVA PROJECT CREATION IN ECLIPSE

a) Eclipse

b) File

18 | P a g e
MCA52L Software Quality and Testing

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

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

19 | P a g e
MCA52L Software Quality and Testing

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

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

20 | P a g e
MCA52L Software Quality and Testing

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 outside jars

n) click Ok

21 | P a g e
MCA52L Software Quality and Testing

Lab Program 7: Write a program to login into a web page

package home;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class TC5_Way2smsLogin {

public static void main(String[] args) throws InterruptedException {


//Launch Chrome Browser

System.setProperty("webdriver.chrome.driver","D://SoftwareTesting//
chromedriver.exe");
WebDriver driver=new ChromeDriver();
//To navigate to URL
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);

//Verification Point
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");

}
//Close Site
driver.close();
}}

22 | P a g e
MCA52L Software Quality and Testing

Output:-

Starting ChromeDriver 2.40.565498


(ea082db3280dd6843ebfb08a625e3eb905c4f5ab) on port 45971
Only local connections are allowed.
Sep 21, 2018 10:23:47 PM org.openqa.selenium.remote.ProtocolHandshake
createSession
INFO: Detected dialect: OSS
Login Sucessful_Test Passed

23 | P a g e
MCA52L Software Quality and Testing

Lab Program 8: Write a program to update 10 students records into


student table

package home;
import java.io.File;
import java.io.IOException;
import jxl.CellView;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.format.UnderlineStyle;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class Student_excel_write {

private WritableCellFormat timesBoldUnderline;


private WritableCellFormat times;
private String inputFile;

public void setOutputFile(String inputFile) {


this.inputFile = inputFile;
}

public void write() throws IOException, WriteException {


File file = new File(inputFile);
WorkbookSettings wbSettings = new WorkbookSettings();
//wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(file,
wbSettings);
workbook.createSheet("Report", 0);
WritableSheet excelSheet = workbook.getSheet(0);
createLabel(excelSheet);
createContent(excelSheet);
workbook.write();
workbook.close();
}

24 | P a g e
MCA52L Software Quality and Testing

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);
//cv.setAutosize(true);
// 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*i)+10));
addNumber(sheet, 2, i, ((i*i)+4));
addNumber(sheet, 3, i, ((i*i)+3));
}
}

private void addCaption(WritableSheet sheet, int column, int row,


String s) throws RowsExceededException, WriteException
{

25 | P a g e
MCA52L Software Quality and Testing

Label label;
label = new Label(column, row, s, timesBoldUnderline);
sheet.addCell(label);
}
private void addNumber(WritableSheet sheet, int column, int row,
Integer integer) throws WriteException,
RowsExceededException{
Number number;
number = new Number(column, row, integer, 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_excel_write test = new Student_excel_write();

test.setOutputFile("D://SoftwareTesting//src//Firstpackage//Student.xls");
test.write();

System.out.println("Please check the result file under D:/NHCE/Student.xls ");


}
}

26 | P a g e
MCA52L Software Quality and Testing

Output:-

Please check the result file


underD://SoftwareTesting//src//FirstPackage//Student.xls

27 | P a g e
MCA52L Software Quality and Testing

Lab Program 9: Write a test program to provide the total number of


objects present on a webpage

package home;
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 TC6 {

public static void main(String[] args) throws InterruptedException {


// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","D://SoftwareTesting//chromedr
iver.exe");
WebDriver driver = new ChromeDriver();
Thread.sleep(5000);;
driver.get("http://newtours.demoaut.com/");
List<WebElement> e = driver.findElements(By.tagName("a"));
System.out.println(e.size());
for(int i=0; i<e.size(); i=i+1){
System.out.println(e.get(i).getText());
}
driver.close();
}

28 | P a g e
MCA52L Software Quality and Testing

Output:-

Starting ChromeDriver 2.40.565498


(ea082db3280dd6843ebfb08a625e3eb905c4f5ab) on port 45417
Only local connections are allowed.
Sep 21, 2018 10:36:24 PM org.openqa.selenium.remote.ProtocolHandshake
createSession
INFO: Detected dialect: OSS
16
Home
Flights
Hotels
Car Rentals
Cruises
Destinations
Vacations
SIGN-ON
REGISTER
SUPPORT
CONTACT
your destination
featured vacation destinations
Register here
Business Travel @ About.com
Salon Travel

29 | P a g e
MCA52L Software Quality and Testing

Lab Program 10: Write and test a program to get the number of items in a
list or a combo box

package home;

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 TC7 {

public static void main(String[] args) throws InterruptedException {


// TODO Auto-generated method stub
//Launch Chrome Browser

System.setProperty("webdriver.chrome.driver","D://SoftwareTesting//chromedr
iver.exe");
WebDriver driver=new ChromeDriver();
//To navigate to URL
driver.get("http://newtours.demoaut.com/");
Thread.sleep(5000);
//Syntax:

//objectName.Method(StaticClass.Locator("value")).OperationMethod();
//Click on Register Link

driver.findElement(By.linkText("REGISTER")).click();
Thread.sleep(5000);
//Pass text into Textbox for FirstName

driver.findElement(By.name("firstName")).sendKeys("Aarav");
Thread.sleep(5000);

driver.findElement(By.name("lastName")).sendKeys("Prof");
Thread.sleep(5000);

driver.findElement(By.name("phone")).sendKeys("9703336699");
Thread.sleep(5000);

30 | P a g e
MCA52L Software Quality and Testing

driver.findElement(By.id("userName")).sendKeys("abcd@gmail.com");
Thread.sleep(5000);

driver.findElement(By.name("address1")).sendKeys("chennai fasf");
Thread.sleep(5000);

driver.findElement(By.name("address2")).sendKeys("chennai hjgfhdfhfdg
fasf");
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 Class in SWD


Select s=new
Select((driver.findElement(By.name("country"))));

//Get all the option from dropdown list and assign into List
List<WebElement> listOptionDropdown = s.getOptions();

// Count the item dropdown list and assign into integer variable
int dropdownCount = listOptionDropdown.size();

//Print the total count of dropdown list using integer variable


System.out.println("Total Number of item count in dropdown
list = " + dropdownCount);

//selectByIndex();
//selectByVisibleText("INDIA");

s.selectByVisibleText("INDIA");

Thread.sleep(5000);

driver.findElement(By.id("email")).sendKeys("abcd@gmail.com");
Thread.sleep(5000);

31 | P a g e
MCA52L Software Quality and Testing

driver.findElement(By.name("password")).sendKeys("Madhvaraj");
Thread.sleep(5000);

driver.findElement(By.name("confirmPassword")).sendKeys("Madhvaraj
");
Thread.sleep(5000);

//Image Button
driver.findElement(By.name("register")).click();
Thread.sleep(5000);
//close browser
driver.close();
}

Output:-
Starting ChromeDriver 2.40.565498
(ea082db3280dd6843ebfb08a625e3eb905c4f5ab) on port 32545
Only local connections are allowed.
Sep 21, 2018 10:42:15 PM org.openqa.selenium.remote.ProtocolHandshake
createSession
INFO: Detected dialect: OSS
Total Number of item count in dropdown list = 264

32 | P a g e
MCA52L Software Quality and Testing

Lab Program 11: Write a test program to automate a webpage using JXL.

package firstPackage;

import java.io.File;

import java.io.IOException;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import jxl.Sheet;

import jxl.Workbook;

import jxl.read.biff.BiffException;

import jxl.write.Label;

import jxl.write.WritableSheet;

import jxl.write.WritableWorkbook;

import jxl.write.WriteException;

import jxl.write.biff.RowsExceededException;

public class Stu_excel_write

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


BiffException, IOException, RowsExceededException, WriteException {

//Open Excel File for Read and Write ,which we placed in same
package only

File f=new
File("E:\\AutomationProject\\src\\firstPackage\\TestData_Way2sms.xls");

33 | P a g e
MCA52L Software Quality and Testing

Workbook readwb=Workbook.getWorkbook(f);

Sheet readsht=readwb.getSheet(0);//0 means Sheet1

int numberofr=readsht.getRows();//Use the Row Count

//Open Excel Sheet for writing Following

WritableWorkbook
wwb=Workbook.createWorkbook(f,readwb);

WritableSheet wsh=wwb.getSheet(0);

for(int i=1;i<numberofr;i++)

String x=readsht.getCell(0,i).getContents();

String y=readsht.getCell(1,i).getContents();

//Launch Chrome Browser

System.setProperty("webdriver.chrome.driver","E://Madhwaraj//chromed
river.exe");

WebDriver driver=new ChromeDriver();

//To navigate to URL

driver.get("http://www.way2sms.com/");

Thread.sleep(5000);

driver.findElement(By.id("mobileNo")).sendKeys(x);

Thread.sleep(5000);

driver.findElement(By.name("password")).sendKeys(y);

Thread.sleep(5000);

driver.findElement(By.xpath("//b[@id='mainErr']/following::*[5]")).click();

Thread.sleep(5000);

34 | P a g e
MCA52L Software Quality and Testing

//Verification Point

String o="http://www.way2sms.com/send-sms";

String z=driver.getCurrentUrl();

if(z.equals(o))

System.out.println("Login Sucessful_Test Passed");

Label l=new Label(2,i,"TestPassed");

wsh.addCell(l);

else

System.out.println("Login UnSucessful_TestFailed");

Label l=new Label(2,i,"TestFailed");

wsh.addCell(l);

//Close Site

driver.close();

wwb.write();//Save Changes in Excel

wwb.close();

readwb.close();

}
}

35 | P a g e
MCA52L Software Quality and Testing

Output:-

Please check the result file underD://SoftwareTesting//src//home//Student.xls

36 | P a g e
MCA52L Software Quality and Testing

37 | P a g e

You might also like