Department of ISE,: I) Ii) Iii) Iv) V) I)
Department of ISE,: I) Ii) Iii) Iv) V) I)
Software Testing
1.using manual testing write a test case to check the Facebook login.
i) Do ... while
#include <stdio.h>
#include <stdlib.h>
void main()
{
//Range is taken as -10 to 10
int low=-10;
int high=10;
int i=-15;
do
{
if(i>=low && i<=high)
{
if(i<0)
printf("%d is a negative number ...\n",i);
else if(i>0)
printf("%d is a positive number ...\n",i);
}
else
printf("%d is out of range ...\n",i);
i+=1;
}while(i<=15);
}
Output:
#include <stdio.h>
#include <stdlib.h>
void main()
{
//Range is taken as -10 to 10
int low=-10;
int high=10;
int i=-15;
while(i<=15)
{
if(i>=low && i<=high)
{
if(i<0)
printf("%d is a negative number ...\n",i);
else
printf("%d is a positive number ...\n",i);
}
else
printf("%d is out of range ...\n",i);
i+=1;
}
}
Output:
#include <stdio.h>
#include <stdlib.h>
void main()
{
//Range is taken as -10 to 10
int low=-10;
int high=10;
int i=-15;
while(i<=15)
{
if(i>=low && i<=high)
{
if(i<0)
printf("%d is a negative number ...\n",i);
else
printf("%d is a positive number ...\n",i);
}
else
printf("%d is out of range ...\n",i);
i+=1;
}
}
Output:
#include <stdio.h>
#include <stdlib.h>
void main()
{
//Range is taken as -10 to 10
int low=-10;
int high=10;
int i=-15;
while(i<=15)
{
int value1,value2;
if(i>=low && i<=high)
value1=1;
else
value1=0;
switch(value1)
{
case 1:
if(i<0)
value2=1;
else
value2=0;
switch(value2)
{
case 1:
printf("%d is a negative number ...\n",i);
break;
case 0:
printf("%d is a positive number ...\n",i);
break;
}
break;
case 0:
printf("%d is Out of Range ... \n",i);
break;
}
i+=1;
}
}
Output:
-15 is Out of Range ...
-14 is Out of Range ...
-13 is Out of Range ...
-12 is Out of Range ...
-11 is Out of Range ...
-10 is a negative number
... -9 is a negative number
... -8 is a negative number
... -7 is a negative number
... -6 is a negative number
... -5 is a negative number
... -4 is a negative number
... -3 is a negative number
... -2 is a negative number
... -1 is a negative number
...
0 is a positive number ...
1 is a positive number ...
2 is a positive number ...
3 is a positive number ...
4 is a positive number ...
5 is a positive number ...
6 is a positive number ...
7 is a positive number ...
8 is a positive number ...
9 is a positive number ...
10 is a positive number
...
11 is Out of Range ...
12 is Out of Range ...
13 is Out of Range ...
14 is Out of Range ...
v)For Loop
#include <stdio.h>
#include <stdlib.h>
void main()
{
//Range is taken as -10 to 10
int low=-10;
int high=10;
int i;
for(i=-15;i<=15;i++)
{
if(i>=low && i<=high)
{
if(i<0)
printf("%d is a negative number ...\n",i);
else
printf("%d is a positive number ...\n",i);
}
else
printf("%d is Out of Range ...\n",i);
}
}
Output:
Test case no: 1 Test case name: Equal no.of rows & cols
Enter the Dimension of First Matrix : 2 2
Enter the Dimension of Second Matrix : 2 2
Enter the Elements of the First Matrix :
1
2
3
4
Enter the Elements of the Second Matrix :
4
5
6
7
Resultant Matrix :
16 19
36 43
Test case no: 2 Test case name: Cols of 1st matrix not equal to rows of 2nd
matrix
Enter the Dimension of First Matrix : 2 2
Enter the Dimension of Second Matrix : 3 3
Cannot Perform Matrix Multiplication
Test case no: 3 Test case name: Out of range values testing
Enter the Dimension of First Matrix : 11 11
Enter the Dimension of Second Matrix : 11 3
Values Our of Range
4. Unit test the given programs and write the test cases for (i) squaring a number (ii)
finding a count of a character 'a' or "A' in a word using JUnit.
Step 1. Create a new java project, SeleniumJavaAutomation and
package, Testing/SeleniumFirstClass.
Step 2 - Type the code for squaring and finding ‘A’ in a given string and save.
package SeleniumFirstClass;
import org.junit.Test;
public class MyJunitTest {
@Test
public int square(int x)
{
return x*x;
}
public int countA(String word) {
int count=0;
for(int i=0; i<word.length(); i++) { if(word.charAt(i)=='a'|| word.charAt(i)=='A')
{ count++;
}
}
return count++;}}
Click on Testing��New→ JUnit Test Case→ Name: squareTest→ Finish→ OK
3. Write the code to test the square of a number function in squareTest.java file package
SeleniumFirstClass;
import static org.junit.Assert.*;
import org.junit.Test;
public class squareTest {
@Test
public void test() {
MyJunitTest test = new MyJunitTest();int output = test.square(5);assertEquals(25,output);
}
}
5. Now let’s write a Test case to check the next code(counting the occurrence of a
character’a’ in a word):
package SeleniumFirstClass;
import static org.junit.Assert.*;
import org.junit.Test;
@Test
public void test() {
MyJunitTest test= new MyJunitTest();
int output = test.countA("alphabet");
assertEquals(2, output);
}
}
7. If we want to run all the test cases one after another in a single file. Go to Package
Explorer→ JUnitTest→ New→ Other→ [In selecta wizard]: Click Java→ JUnit→ JUnit
Test Suite→ Package: Testing→ finish
5. Boundary value testing- Triangle problem
Boundary value analysis program
Design and develop a program in a language of your choice to solve the triangle problem
defined as follows: Accept three integers which are supposed to be the three sides of triangle
and determine if the three values represent an equilateral triangle, isosceles triangle, scalene
triangle, or they do not form a triangle at all. Derive test cases for your program based on
boundary value analysis, execute the test cases and discuss the results
#include<stdio.h>
int main()
{
int a,b,c,c1,c2,c3;
char istriangle;
do {
printf("\nenter 3 integers which are sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
printf("\na=%d\tb=%d\tc=%d",a,b,c);
c1 = a>=1 && a<=10;
c2= b>=1 && b<=10;
c3= c>=1 && c<=10;
if (!c1)
printf("\n the value of a=%d is not the range of permitted value", a);
if (!c2)
printf("\nthe value of b=%d is not the range of permitted value", b);
if (!c3)
printf("\nthe value of c=%d is not the range of permitted value", c);
} while (! (c1 && c2 && c3));
Triangle Problem -Boundary value Test cases for 3 Enter min value for 2 1 2
input data: items and min+1 for any
Cas Description Input d one item
e
a b 4 Enter min value for 2 2 1
id
items and min+1 for any
one item
5 Enter normal value 5 5
for 2 items and 1 item
is min value
pass
6 Enter normal value 5 1
for 2 items and 1 item
is min value
pass
7 Enter normal value 1 5
for 2 items and 1 item
is min value
pass
8 Enter the normal value 5 5
for a, b, and c
pass
9 Enter the normal value 5 5
for 2 items and 1 item
is max value pass
pass
pass
pass
10 Enter the normal value 5 10 5 Not a triangle Not a
for 2 items and 1 item triangle
is max value
pass
pass
pass
pass
pass
Code snippet:
Checking boundary value for locks, stocks and barrels and commission
Input data Expected Actual output
output
Ca Descrip Tota Tota Tota Sal Comm Sal Comm Stat Com
se tio n l l l es iss ion es iss ion us me nt
id Loc stoc barre
ks ks ls
Cas Descri Tota Tota Total Sal Comm Sal Comm Stat Comm
e id pti on l l barre es iss ion es iss ion us ent
Loc stoc ls
ks ks
CODE:
#include<stdio.h>
int main()
{
int locks, stocks, barrels, tlocks, tstocks, tbarrels;
float lprice, sprice, bprice, sales, comm;
int c1,c2,c3,temp;
lprice=45.0;
sprice=30.0;
bprice=25.0;
tlocks=0;
tstocks=0;
tbarrels=0;
printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
scanf("%d",&locks);
while(locks!=-1)
{
c1=(locks<=0||locks>70);
printf("enter the number of stocks and barrels\n");
scanf("%d%d",&stocks,&barrels);
c2=(stocks<=0||stocks>80);
c3=(barrels<=0||barrels>90);
if(c1)
printf("value of locks not in the range 1..70 ");
else
{
temp=tlocks+locks;
if(temp>70)
printf("new total locks =%d not in the range 1..70 so old
",temp); else
tlocks=temp;
}
printf("total locks = %d\n",tlocks);
if(c2)
printf("value of stocks not in the range 1..80 ");
else
{
temp=tstocks+stocks;
if(temp>80)
printf("new total stocks =%d not in the range 1..80 so old ",temp);
else
tstocks=temp;
}
printf("total stocks=%d\n",tstocks);
if(c3)
printf("value of barrels not in the range 1..90 ");
else
{
temp=tbarrels+barrels;
if(temp>90)
printf("new total barrels =%d not in the range 1..90 so old ",temp);
else
tbarrels=temp;
}
printf("total barrel=%d",tbarrels);
printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
scanf("%d",&locks);
}
printf("\ntotal locks = %d\ntotal stocks =%d\ntotal barrels =%d\n",tlocks,tstocks,tbarrels);
sales = lprice*tlocks+sprice*tstocks+bprice*tbarrels;
printf("\nthe total sales=%f\n",sales);
if(tlocks>0&&tstocks>0&&tbarrels>0)
{
if(sales > 1800.0)
{
comm=0.10*1000.0;
comm=comm+0.15*800;
comm=comm+0.20*(sales-1800.0);
}
else if(sales > 1000)
{
comm =0.10*1000;
comm=comm+0.15*(sales-1000);
}
else
comm=0.10*sales;
printf("the commission is=%f\n",comm);
}
else
printf(" Commission cannot be calculated \n");
return 0;
}
7. Equivalence class – Triangle Problem
Design and develop a program in a language of your choice to solve the triangle problem
defined as follows: Accept three integers which are supposed to be the three sides of a
triangle and determine if the three values represent an equilateral triangle, isosceles triangle,
scalene triangle, or they do not form a triangle at all. Assume the upper limit for the size of
any side is 10. Derive test cases for your program based on equivalence class partitioning,
execute the test cases and discuss the results.
Code snippet:
do
{
printf("\nenter 3 integers which are sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
printf("\na=%d\tb=%d\tc=%d",a,b,c);
c1 = a>=1 && a<=10;
c2= b>=1 && b<=10;
c3= c>=1 && c<=10;
if (!c1)
printf("\n the value of a=%d is not the range of permitted value",a);
if (!c2)
printf("\n the value of b=%d is not the range of permitted value",b);
if (!c3)
printf("\n the value of c=%d is not the range of permitted value",c);
} while(!(c1 && c2 && c3));
// to check is it a triangle or not
if( a<b+c && b<a+c && c<a+b )
istriangle='y';
else
istriangle ='n';
if (istriangle=='y')
if ((a==b) && (b==c))
printf("equilateral triangle\n");
else if ((a!=b) && (a!=c) && (b!=c))
printf("scalene triangle\n");
else
printf("isosceles triangle\n");
else
printf("Not a triangle\n");
Triangle Problem -Equivalence Class Test cases for input data
Weak Normal Equivalence Class Testing
Case Description Input data Expected output Actual output Comm
id en ts
a b c
Code:
#include<stdio.h>
int main()
{
int a,b,c,c1,c2,c3;
char istriangle;
do
{
printf("\nenter 3 integers which are sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
printf("\na=%d\tb=%d\tc=%d",a,b,c);
c1 = a>=1 && a<=10;
c2= b>=1 && b<=10;
c3= c>=1 && c<=10;
if (!c1)
printf("\nthe value of a=%d is not the range of permitted
value",a); if (!c2)
printf("\nthe value of b=%d is not the range of permitted
value",b); if (!c3)
printf("\nthe value of c=%d is not the range of permitted
value",c); } while(!(c1 && c2 && c3));
// To check is it a triangle or not
if( a<b+c && b<a+c && c<a+b )
istriangle='y';
else
istriangle ='n';
// To check which type of triangle
if (istriangle=='y')
if ((a==b) && (b==c))
printf("equilateral triangle\n");
else if ((a!=b) && (a!=c) && (b!=c))
printf("scalene triangle\n");
else
printf("isosceles triangle\n");
else
printf("Not a triangle\n");
return 0;
}
Output:
8. Equivalence- Next Date
Design, develop, code and run the program in any suitable language to implement the Next
Date function. Analyse it from the perspective of equivalence class value testing, derive
different test cases, execute these test cases and discuss the test results.
Code snippets:
if(day<1 || day>31)
{
printf("value of day, not in the range 1...31\n");
flag='n';
}
if(month<1 || month>12)
{
printf("value of month, not in the range 1....12\n");
flag='n';
}
else if(check(day,month))
{
printf("value of day, not in the range day<=30");
flag='n';
}
………….
if(year<=1812 || year>2013)
{
printf("value of year, not in the range 1812...... 2013\n");
flag='n';
}
if(month==2)
{
if(isleap(year) && day>29)
{
printf("invalid date input for leap year");
flag='n';
}
else if(!(isleap(year))&& day>28)
{
printf("invalid date input for not a leap year");
flag='n';
}
}
………..
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:if(day<31)
tomm_day=day+1;
else
{
tomm_day=1;
tomm_month=month+1;
}
break;
case 4:
case 6:
case 9:
case 11: if(day<30)
tomm_day=day+1;
else
{
tomm_day=1;
tomm_month=month+1;
}
break;
case 12: if(day<31)
tomm_day=day+1;
else
{
tomm_day=1;
tomm_month=1;
if(year==2013)
{
printf("the next day is out of boundary value of year\n");
tomm_year=year+1;
}
else
tomm_year=year+1;
}
break;
case 2:
if(day<28)
tomm_day=day+1;
else if(isleap(year)&& day==28)
tomm_day=day+1;
else if(day==28 || day==29)
{
tomm_day=1;
tomm_month=3;
}
break;
}
// print the next date values as day, month, year format
Valid equivalence classes are:
Case Descripti Month Day Year Month Day Year Month Day Year Comment
id o
n
pass
2 Enter the -1 15 Value of month not in the range
M2 , D1 1 ... 12
and Y1
cases
3 Enter the 13 15 1912 Value of month Value of pass
M3 ,D1 not in the range month not in
and Y1 1 ... 12 the range
cases
1 ... 12
Case Descripti Month Day Year Month Day Year Month Da Year Comment
id o y
n
2 Enter the 6 -1 1912 Value of day not Value of day not pass
M1, D2 in the range 1 ... in the range 1 ...
and Y1 31 31
cases
3 Enter the 6 15 1811 Value of year not Value of year not pass
M1, D1 in the range in the range
and Y2 1812 ... 1812 ...
cases 2012 2012
4 Enter the -1 -1 1912 Value of month Value of month pass
M2 , D2 not in the range not in the range
and Y1 1 ... 12 1 ... 12
cases
Value of day not Value of day not
in the range 1 ... in the range 1 ...
31 31
5 Enter the 6 -1 1811 Value of day not Value of day not pass
M1, D2 in the range 1 ... in the range 1 ...
and Y2 31 31
cases
Value of year not Value of year not
in the range 1812 in the range 1812
... ...
2012 2012
Case Descripti Month Day Year Month Day Year Month Day Year Comment
id o
n
1 Enter the 12 31 1811 Value of year not Value of year not pass
M1 , D1 in the range 1812 in the range 1812
and Y2 ... ...
cases 2012 2012
and Y3
cases
Code:
#include<stdio.h>
int check(int day,int month)
{
if((month==4||month==6||month==9 ||month==11) && day==31)
return 1;
else
return 0;
}
int isleap(int year)
{
if((year%4==0 && year%100!=0) || year%400==0)
return 1;
else
return 0;
}
int main()
{
int day,month,year,tomm_day,tomm_month,tomm_year;
char flag;
do
{
flag='y';
printf("\nenter the today's date in the form of dd mm yyyy\n");
scanf("%d%d%d",&day,&month,&year);
tomm_month=month;
tomm_year= year;
if(day<1 || day>31)
{
printf("value of day, not in the range 1...31\n");
flag='n';
}
if(month<1 || month>12)
{
printf("value of month, not in the range 1....12\n");
flag='n';
}
else if(check(day,month))
{
printf("value of day, not in the range day<=30");
flag='n';
}
if(year<=1812 || year>2012)
{
printf("value of year, not in the range 1812...... 2012\n");
flag='n';
}
if(month==2)
{
if(isleap(year) && day>29)
{
printf("invalid date input for leap year");
flag='n';
}
else if(!(isleap(year))&& day>28)
{
printf("invalid date input for not a leap year");
flag='n';
}
}
}while(flag=='n');
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:if(day<31)
tomm_day=day+1;
else
{
tomm_day=1;
tomm_month=month+1;
}
break;
case 4:
case 6:
case 9:
case 11: if(day<30)
tomm_day=day+1;
else
{
tomm_day=1;
tomm_month=month+1;
}
break;
case 12: if(day<31)
tomm_day=day+1;
else
{
tomm_day=1;
tomm_month=1;
if(year==2012)
{
printf("the next day is out of boundary value of year\n");
tomm_year=year+1;
}
else
tomm_year=year+1;
}
break;
case 2:
if(day<28)
tomm_day=day+1;
else if(isleap(year)&& day==28)
tomm_day=day+1;
else if(day==28 || day==29)
{
tomm_day=1;
tomm_month=3;
}
break;
}
printf("next day is : %d %d %d",tomm_day,tomm_month,tomm_year);
return 0;
}
Output:
Dataflow testing
9) Write an application to calculate the bill of a cellular service customer depending
upon on his/her usage. The following calculates ‘Bill’ as per ‘Usage’ with the
following rules applicable. If ‘Bill’ is more than $100, 10% discount is given. Perform
data flow testing for all variables. Determine the output using test suite for variables.
Code:
#include<stdio.h>
void main()
{
float bill = 0.0;
int usage=0;
int c=1;
while(c!=-1)
{
printf("Enter usage:");
scanf("%d",&usage);
if(usage>0)
bill = 40;
if(usage > 100)
{
if(usage<=200)
bill = bill + (usage-100)*0.5;
else
{
bill = bill + 50+ (usage-200)*0.1;
if(bill>=100)
bill = bill*0.9;
}}
printf("\nBill: %f\n",bill);
printf("Continue?\n");
scanf("%d",&c);
}}
Output:
Strategy Bill Input Usage Expected Value Actual Output
Value
3->4->5->6 220 92 92
6->7 220 92 92
9->10 220 92 92
3->4->5->6 220 92 92
9->10 220 92 92
All p-use (APU) 1->2->3->4->5- 220 92 92
>6->7
3->4->5->6->7 220 92 92
6->7 220 92 92
3->4->5->6 220 92 92
3->4->5->9 170 75 75
9->10 170 75 75
3->4->5->6->7 220 92 92
6->7 220 92 92
9->10 170 75 75
6->7 220 92 92
3->4->5->9 170 75 75
10) For the code given below perform data flow testing for all variables. Determine
the output using test suite for variables.
Code:
import java.util.*;
public class computeStats {
public static void compute_Stats(int[] numbers)
{
int length = numbers.length;
double med=0.0, var=0.0, sd=0.0, mean=0.0, sum=0.0, varsum=0.0;
sum = 0.0;
// System.out.print(" 1 ");
int i =0;
// System.out.print(" 2 ");
// System.out.print(" 3 ");
// if(i<length)
// System.out.print(" 4 ");
for(i=0;i<length;i++)
{
sum +=numbers[i];
}
// System.out.print(" 5 ");
if(length>0)
{
med = numbers[length/2];
mean = sum / (double) length;
varsum = 0.0;
i=0;
// System.out.print(" 6 ");
// if(i<length)
// System.out.print(" 7 ");
for(i=0;i<length;i++)
{
varsum += (numbers[i]-mean) *(numbers[i]-mean);
}
// System.out.print(" 8 ");
if(length>1)
{
var = varsum/(length-1);
sd = Math.sqrt(var);
}
System.out.println();
System.out.println("length: "+length);
System.out.println("mean: "+mean);
System.out.println("median: "+med);
System.out.println("variance: "+var);
System.out.println("standard deviation: "+sd);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int l = 0;
int c = 1;
do
{
System.out.println("Enter the length:");
l = in.nextInt();
int[] arr= new int[l];
//System.out.print("Path:");
compute_Stats(arr);
Output:
Variable DU Path Input Expected Output Actual Output
1->2->3->5 [] 0 0 0 0 0 0 0 0 0 0
1->2->3->5- [] 0 0 0 0 0 0 0 0 0 0
>6- >7
Length 1->2->3->5 [] 0 0
1->2->3->4 [1,1,1,1] 4 1 1 0 0 4 1 1 0 0
1->2->3->5- [1,1,1,1] 4 1 1 0 0 4 1 1 0 0
>6- >7
1->2->3->5 [] 0 0 0 0 0 0 0 0 0 0
4->3->4 [1,1,1,1] 4 1 1 0 0 4 1 1 0 0
4->3->5 [1] 1 1 1 0 0 1 1 1 0 0
5->6->8 [] 0 0 0 0 0 0 0 0 0 0
5->6->8 [] 0 0 0 0 0 0 0 0 0 0
2->3->5 [] 0 0 0 0 0 0 0 0 0 0
4->3->5 [1] 1 1 1 0 0 1 1 1 0 0
5->6->8 [] 0 0 0 0 0 0 0 0 0 0
7->6->8 [1] 1 1 1 0 0 1 1 1 0 0
12.) The Calendar application has classes: CalendarUnit, testIT, Date, Day, Month,
Year. Perform object oriented integration testing.
CalendarUnit(){}
CalendarUnit(int p)
{
currentPos = p;
}
class: testIT
import java.util.*;
public class testIT {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the day, month, year: ");
int day = in.nextInt();
int month = in.nextInt();
int year = in.nextInt();
Year testYear = new Year(year);
Month testMonth = new Month(month, testYear);
Day testDay = new Day(day, testMonth);
Date testDate = new Date(testDay, testMonth, testYear);
testDate.increment();
testDate.printDate();
}
}class:Date
public class Date
{
private Day d;
private Month m;
private Year y;
Date(Day d1, Month m1, Year y1)
{
d = d1;
m = m1;
y = y1;
}
class: Day
public class Day extends CalendarUnit
{
Month m;
Day(int d, Month m1)
{
super();
setDay(d, m1);
}
public void setDay(int d, Month m1)
{
setCurrentPos(d);
m = m1;
}
public int getDay()
{
return currentPos;
}
class: Month
public class Month extends CalendarUnit
{
Year y;
private int[] sizeIndex = new int[] { 31,28,31,30,31,30,31,31,30,31,30,31};
Month(int m, Year y1)
{
setMonth(m, y1);
}
public void setMonth(int m, Year y1)
{
setCurrentPos(m);
y = y1;
}
public int getMonth()
{
return currentPos;
}
public int getMonthSize()
{
if(y.isleap())
sizeIndex[1] = 29;
else
sizeIndex[1] = 28;
return sizeIndex[currentPos-1];
}
public boolean increment()
{
currentPos = currentPos + 1;
if(currentPos>12)
return false;
else
return true;
}
}
class: Year
public class Year extends CalendarUnit
{
Year(int y1)
{
setCurrentPos(y1);
}
Output:
Selenium problem:
Give Project name as "selenium", leave the other fields unaltered and click on
"Finish" button.
It will launch the Properties window for our "selenium" Test Suite.
Click on "Java Build Path" option from the left hand side panel.
Switch to Libraries tab and click on "Add External JARs" button. Locate the directory where
you have downloaded the Selenium jar files, select the respective jars and click on "Open"
button. Repeat the same steps for the jars which are present under the "libs" folder. Open
"libs" folder, select all of the respective jar files and click on "Open" button. Once you get all
the Selenium jar files in your Libraries tab, click on Apply and Close button.
The following image shows the directory structure of our "selenium" test suite after adding
Selenium jars.
Hence, we have successfully configured Selenium WebDriver with Eclipse IDE. Now, we are
ready to write our test scripts in Eclipse and run it in WebDriver.
13) Configure Selenium WebDriver with Eclipse IDE and create Selenium Automation
Test script. Under this test, automate the following scenarios:
a. Invoke Google Chrome browser, Open URL: www.google.com, Click on the Google
Search text box, Type the value "BMS College of Engineering", Click on the Search button.
b. Invoke Google Chrome browser, Open URL: www.isearch123.com, Click on the Google
Search text box, Type the value "BMS College of Engineering", Click on the Search button.
c. Invoke Google Chrome browser, Open Indeed home page, https://www.indeed.co.uk/ ,
Find What field and enter Selenium.
Step1. Launch Eclipse IDE and open project "selenium" which we have created in the
previous section (Configure Selenium WebDriver) of this Tutorial. We will write our first
Selenium test script in the "SeleniumTest.class" file under the "selenium" test suite.
Step3. Click on the "ChromeDriver 2.41" link. It will redirect you to the directory of
ChromeDriver executables files. Download as per the operating system you are currently
on.
Step4. We would need a unique identification for the web elements like Google Search text
box and Search button in order to automate them through our test script. These unique
identifications are configured along with some Commands/Syntax to form Locators. Locators
help us to locate and identify a particular web element in context of a web application.
The method for finding a unique identification element involves inspection of HTML codes.
- Open URL: https://www.google.com in your Chrome browser.
Right click on the Google search text box and select Inspect Element
Code: (Uncomment and run the parts one by one)
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;;
public class First {
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\admin\\Downloads\\chrom
edriver_win32\\chromedriver.exe");
// driver.navigate().to("http://www.google.com/");
// driver.findElement(By.name("q")).sendKeys("BMS College of Engineering"); //
driver.findElement(By.name("btnK")).click();
// driver.navigate().to("http://www.isearch123.com/");
// driver.findElement(By.name("q")).sendKeys("VTU");
// driver.findElement(By.className("btn")).click();
// driver.navigate().to("https://www.indeed.co.uk/");
// driver.findElement(By.name("q")).sendKeys("Selinium"); //
driver.findElement(By.className("icl-Button icl-Button--primary icl-Button-- md
icl-WhatWhere-button")).click();
}
}
OUTPUT: (Demo_Test> src > > First.java > (Right Click) > Run As > Java Application
14)Create Selenium IDE Script to perform the following
processes: • Process #1: Recording a test script
• Process #2: Playing back / executing a test script
• Process #3: Saving a test script
Open “https://accounts.google.com”.
Enter a valid username and password and submit the details to login.
Step 1 – Launch the Firefox and open Selenium IDE from the menu bar. Click on “Create
a new project”. Enter project name.
Step 2 – Click on Record button. Enter the address of application under test
(“https://accounts.google.com”) inside the Base URL textbox. Click on Start
Recording.
“.side”.