You are on page 1of 84

Ajit Gupta Roll no.

: 18

Practical No. 1
Aim: Take a review and write test cases for any known application.
Test Scenarios of YouTube
1. Verify that user can upload single video or allowed format and size
successfuly.
2. Verify that while uploading user should select the video license and
type of video along with its attributes like- name, artsist name,
company etc.
3. Verify the maximum size of video that is permitted to upload and
check that any attempt to upload video of size greater than the
allowed value results in an error message.
4. Verify if there is any minimum size of video that is permitted to upload
and any attempt to upload file size less than specified results in error
message.
5. Verify all the video formats that are allowed to upload – .mp4, .3gp,
.avi etc and check that uploading file formats other that alllowed
results in error message.
6. Verify that uploading blank file should result in error message.
7. Verify that user can upload multiple videos or allowed format and sie
successfuly.
8. Verify that upladers get notification of comments posted on the videos
uploaded by them.
9. Verify that user can view likes, dislikes and comments for their videos.
10. Verify that user can reply to the comments posted in their videos.

Test scenarios for Video Viewing Functionality

1. Verify that video page can be opened by direct link to a video.


2. Verify that on cliking the video play icon over the video, the video
should play.
3. Verify all the video player controls- play, pause, volume, mute etc.
4. Verify that user can select the allowed video quality for playing the
video.
5. Verify that once the video is complete, user can replay the video using
‘replay’ icon.
6. Verify that video should be searchable by name, displaying the most
relevant video on the top in search results.

1
Ajit Gupta Roll no.: 18

7. Verify that other attributes of video like artist name, description should
also be searchable.
8. Verify that user should get auto suggestions while searching for videos
in the youtube search bar.
9. Verify that search results should display information like video name,
thumbnail, video length, view counts etc.
10. Verify that clicking the video thumbnails in the search results should
lead to video page.
11. Verify that video filtering and sorting option while searching for video
like – sort be view count, like, upload date etc.
12. Verify that user can view ‘view count’, ‘comments’, ‘like’ and ‘dislikes’
for a video.
13. Verify that with each view the ‘view count’ increases by one.
14. Verify that user can like or dislike a video and the corresponding count
should increase by one.
15. Verify that user can comment in the comments section.
16. Verify that user should be presented with related videos in the sidebar
section.
17. Verify that the related videos are related to the current video or is
based on the past viewing history of user.
18. Verify that clicking rleated video thumbnail should open the video.
19. Verify that for age restricted video, user is asked to login to youtube
account.
20. Verify that logged-in user should see there history as well as
recommended videos in the home page.
21. Verify that every video viewed goes to history for logged in user..
22. Verify that user can view or delete history items.

2
Ajit Gupta Roll no.: 18

Practical No. 2
Aim: Implement Web Drivers on Chrome & Firefox Browsers.
Selenium Installation
Go to the Java Downloads Page and click on the option for Java Platform (JDK).

In the next page, select the Accept License Agreement radio button, accept it and click the
download link against your matching system configuration.

You can run the installer once the download is over and follow onscreen instructions.
o Go to start and search for ‘System’
o Click on ‘System’
o Click on ‘Advanced system settings’
o Click on ‘Environment Variables’ under ‘Advanced’ tab as shown below:

3
Ajit Gupta Roll no.: 18

Next, under system variables choose new and enter the variable name as ‘JAVA_HOME’ and
the full path to Java installation directory as per your system as shown below:

Below figure depicts the configuration of environment variable name and value.

Next thing that you have to do is to configure your environment variables. Let’s see how to do
that. Here, you have to edit the path of the system variable as shown below.

4
Ajit Gupta Roll no.: 18

Under ‘Variable value’, at the end of the line, enter the following path
– %JAVA_HOME%bin;
Now, you can click ‘OK’ and you are done.

Now to cross-check the installation, just run following command in cmd – java -version. It
should display the installed version of Java in your system.

Install Eclipse
Navigate to the following URL – https://www.eclipse.org/downloads/ and select the
download link depending on your system architecture – (32 Bit or 64 Bit) and download it.

5
Ajit Gupta Roll no.: 18

Once the download is over, extract the zipped file and save it to any directory. The root folder
is the eclipse.

Open the folder and launch eclipse.exe.

6
Ajit Gupta Roll no.: 18

Now, the last step is to install Selenium. Let’s see how to install selenium and configure it in
your system.

Install Selenium Web Driver

▪ Open the browser and navigate to http://www.seleniumhq.org.


▪ Click ‘Download’ menu and choose ‘Download version’. i.e. x.y.z

The download should get started for ‘selenium-server-standalone-x.y.z.jar’. Save this JAR in
“C:Selenium”.

Next, you have to download Selenium Java Client. In the same downloads page, scroll down
and you will find a section called Selenium Client and WebDriver Language. Now, click on
Download link under Java as shown below.

7
Ajit Gupta Roll no.: 18

Extract the zip file and save it in your selenium folder.

Next, you have to download Chrome Driver for Google Chrome and Gecko Driver if you are
using Mozilla Firefox.

In the same downloads page, scroll further down and you will find third-party drivers section.
There you will find options for downloading gecko driver and chrome driver as shown in the
below figure.

In the next page, you will find the latest version available. You can choose that and download
based on your system configuration. You can refer the below image for your OS configuration.

8
Ajit Gupta Roll no.: 18

You can simply download the driver, extract the zip file and save it in any location. Similarly,
you can download the latest version of gecko driver and save it if you are using the Mozilla
browser.

Next, you can simply create a new project in Eclipse IDE and add all the external selenium jar
files from selenium lib directory.

First, launch Eclipse and create new project as shown below.

Next, specify the name of the project and create a class

9
Ajit Gupta Roll no.: 18

Let’s create a class file and give public access modifier

Next, you should add referenced libraries to your project. Click on your project -> Build Path
-> Configure Build Path and add external JARs as shown in the figure.

10
Ajit Gupta Roll no.: 18

11
Ajit Gupta Roll no.: 18

Program:
package day1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class DemoLaunch {

public static void main(String[] args) {


// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\c
hromedriver.exe");
WebDriver wd=new ChromeDriver();
wd.get("https://www.google.com");
}
}
Output:

12
Ajit Gupta Roll no.: 18

Practical No. 3
Aim: Demonstrate handling multiple frames in selenium
Program:
package day1;

import java.util.Scanner;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class ChooseBrowser {

static WebDriver wd;

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner sc=new Scanner(System.in);

System.out.println("1. ChromeBrowser 2. Firefox");

System.out.println("Choice");

int ch=sc.nextInt();

sc.close();

switch(ch)

case 1:

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_
win32\\chromedriver.exe");

wd=new ChromeDriver();

break;

case 2:

System.setProperty("webdriver.gecko.driver","E:\\Software\\geckodriver-
v0.30.0-win64\\geckodriver.exe");

wd=new FirefoxDriver();

break;

default:

System.out.println("Invalid Browser");

13
Ajit Gupta Roll no.: 18

if(wd!=null)

wd.get("http://google.com");

Output:

14
Ajit Gupta Roll no.: 18

15
Ajit Gupta Roll no.: 18

Practical No. 4
Aim: Implement Browser command and navigation Commands.
Program:

package day2;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class DemoNavigation {

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

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

//System.setProperty("webdriver.gecko.driver","D:\\Selenium\\geckodriver.exe");

//WebDriver wd=new FirefoxDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.findElement(By.id("txtUsername")).sendKeys("admin");

wd.findElement(By.id("txtPassword")).sendKeys("admin123");

wd.findElement(By.xpath("//*[@id=\"btnLogin\"]")).click();

Thread.sleep(2000);

wd.navigate().back();

Thread.sleep(2000);

wd.navigate().forward();

wd.navigate().to("https://opensource-demo.orangehrmlive.com/");

wd.navigate().refresh();

16
Ajit Gupta Roll no.: 18

Output:

17
Ajit Gupta Roll no.: 18

18
Ajit Gupta Roll no.: 18

Practical No. 5
Aim: Implement the find element command
Program:
package day1;

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.interactions.Actions;

public class DemoAction2 {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.findElement(By.id("txtUsername")).sendKeys("admin");

wd.findElement(By.name("txtPassword")).sendKeys("admin123");

wd.findElement(By.className("button")).click();

Actions act=new Actions(wd);

//act.moveToElement(wd.findElement(By.className("firstLevelMenu"))).perform();

//act.moveToElement(wd.findElement(By.id("menu_recruitment_viewRecruitmentModule")
)).perform();

List<WebElement> menu=wd.findElements(By.className("firstLevelMenu"));

19
Ajit Gupta Roll no.: 18

for(int i=0;i<=menu.size()-1;i++)

System.out.println(menu.get(i).getText());

act.moveToElement(menu.get(i)).perform();

wd.findElement(By.partialLinkText("Welcome")).click();

wd.findElement(By.linkText("Logout")).click();

wd.close();

Output:

20
Ajit Gupta Roll no.: 18

21
Ajit Gupta Roll no.: 18

Practical No. 6
Aim: Demonstrate the Locator(id,css selector, path)
1. Id
Program:

package day1;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class DemoLocator

public static void main(String[] args) throws Exception

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.findElement(By.id("txtUsername")).sendKeys("admin");

wd.findElement(By.name("txtPassword")).sendKeys("admin123");

wd.findElement(By.className("button")).click();

wd.findElement(By.linkText("Welcome Palak")).click();

Thread.sleep(2000);

wd.findElement(By.linkText("Logout")).click();

22
Ajit Gupta Roll no.: 18

Output:

23
Ajit Gupta Roll no.: 18

2. CSS Selector

Program:

package day1;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class DemoCssSelector

public static void main(String[] args)

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.findElement(By.cssSelector("input#txtUsername")).sendKeys("admin");

wd.findElement(By.cssSelector("input[type=Password]")).sendKeys("admin123");

wd.findElement(By.cssSelector("input.button")).click();

24
Ajit Gupta Roll no.: 18

Output:

25
Ajit Gupta Roll no.: 18

3. Path
Program:
package day1;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class DemoXpath {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.findElement(By.xpath("/html/body/div[1]/div/div[3]/div[2]/div[2]/form/div[2]/input")).s
endKeys("admin");

wd.findElement(By.xpath("//*[@id=\"txtPassword\"]")).sendKeys("admin123");

wd.findElement(By.className("button")).click();

26
Ajit Gupta Roll no.: 18

Output:

27
Ajit Gupta Roll no.: 18

Practical No. 7
Aim: Demonstrate synchronization in selenium.
Implicit wait
Program:
package day1;

import java.util.concurrent.TimeUnit;

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

public class DemoImplicitWait {

public static void main(String[] args) {


// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromed
river.exe");
WebDriver wd=new ChromeDriver();
wd.get("https://opensource-demo.orangehrmlive.com/");
wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
wd.findElement(By.id("txtUsername")).sendKeys("admin");
wd.findElement(By.name("txtPassword")).sendKeys("admin123");
wd.findElement(By.className("button")).click();
wd.findElement(By.partialLinkText("Welcome")).click();
wd.findElement(By.linkText("Logout")).click();
}

28
Ajit Gupta Roll no.: 18

Output:

29
Ajit Gupta Roll no.: 18

Explicit wait
Program:
package day1;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.WebDriverWait;

public class DemoExplicitWait {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

WebDriverWait wt=new WebDriverWait(wd,10);

wd.findElement(By.id("txtUsername")).sendKeys("admin");

wd.findElement(By.name("txtPassword")).sendKeys("admin123");

wd.findElement(By.className("button")).click();

wd.findElement(By.partialLinkText("Welcome Paul")).click();

wt.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Logout")));

wd.findElement(By.linkText("Logout")).click();

30
Ajit Gupta Roll no.: 18

Output:

31
Ajit Gupta Roll no.: 18

Practical No. 8
Aim: Demonstrate different types of alerts
Program:
package day1;

import org.openqa.selenium.Alert;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

public class DemoAlert {

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

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("http://frontaccounting.squadinfotech.in/index.php");

wd.findElement(By.name("user_name_entry_field")).sendKeys("frontuser1");

wd.findElement(By.name("password")).sendKeys("frontuser1");

Select s=new Select(wd.findElement(By.name("company_login_name")));

s.selectByVisibleText("Squad_MT_OL-50");

wd.findElement(By.name("SubmitUser")).click();

wd.findElement(By.linkText("Direct Delivery")).click();

wd.findElement(By.id("CancelOrder")).click();

//Thread.sleep(2000);

Alert alt=wd.switchTo().alert();

System.out.println("Text Of Alert "+ alt.getText());

alt.accept();

//alt.dismiss();

32
Ajit Gupta Roll no.: 18

Output:

33
Ajit Gupta Roll no.: 18

Practical No. 9
Aim:
Demonstrate:
a) Handling Drop Down,
b) List Boxes

a) Handling Drop Down


Program:

package day1;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

public class DemoDropDown {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://blazedemo.com/");

Select s=new Select(wd.findElement(By.name("fromPort")));

s.selectByIndex(1);

s.selectByValue("Boston");

s.selectByVisibleText("San Diego");

34
Ajit Gupta Roll no.: 18

Output:

35
Ajit Gupta Roll no.: 18

36
Ajit Gupta Roll no.: 18

b) List Boxes
Program:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

public class DemoMultiSelect {

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

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("E:\\MCA_SEM3\\Selenium\\Multi.html");

Select s=new Select(wd.findElement(By.id("car")));

if(s.isMultiple())

s.selectByIndex(1);

s.selectByValue("3");

s.selectByVisibleText("Ferrari");

Thread.sleep(2000);

s.deselectAll();

Multi.html

<!DOCTYPE html>

<html>

<head>

<meta charset="ISO-8859-1">

<title>Multiple</title>

37
Ajit Gupta Roll no.: 18

</head>

<body>

<h1>Demo MultiSelect</h1>

<select id="car" name="Car" multiple>

<option value="1">Ford</option>

<option value="2">Audi</option>

<option value="3">Bugatti</option>

<option value="4">Ferrari</option>

</select>

</body>

</html>

Output:

38
Ajit Gupta Roll no.: 18

Practical No. 10
Aim:
Demonstrate:
1. Command Button,
2. Radio buttons & text boxes.
3. Waits command in selenium

1. Command Button
Program:
package day1;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class DemoLocator {

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

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.findElement(By.id("txtUsername")).sendKeys("admin");

wd.findElement(By.name("txtPassword")).sendKeys("admin123");

wd.findElement(By.className("button")).click();

wd.findElement(By.linkText("Welcome Palak")).click();

Thread.sleep(2000);

wd.findElement(By.linkText("Logout")).click();

39
Ajit Gupta Roll no.: 18

Output:

40
Ajit Gupta Roll no.: 18

41
Ajit Gupta Roll no.: 18

2. Radio buttons & text boxes.


Program:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class DemoRadio {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromed
river.exe");
WebDriver wd= new ChromeDriver();
wd.get("C:\\Users\\ajitg\\eclipse-workspace\\WebProgram\\src\\day2\\radio.html");
wd.findElement(By.xpath("//input[@value='Mr']")).click();
}

Radio.html
<html>
<head>
<body>
<input type="radio" name'"group1" value="Mr">Mr<tr>
<input type="radio" name'"group1" value="Miss">Miss<tr>
<input type="radio" name'"group1" value="Mrs">Mrs
</body>
</html>

42
Ajit Gupta Roll no.: 18

Output:

43
Ajit Gupta Roll no.: 18

Textbox.java

package day1;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class DemoLocators

public static void main(String[] args) throws Exception

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.findElement(By.id("txtUsername")).sendKeys("admin");

wd.findElement(By.name("txtPassword")).sendKeys("admin123");

44
Ajit Gupta Roll no.: 18

Output:

45
Ajit Gupta Roll no.: 18

3. Waits command in selenium

package day1;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class DemoLocators

public static void main(String[] args) throws Exception

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.findElement(By.id("txtUsername")).sendKeys("admin");

wd.findElement(By.name("txtPassword")).sendKeys("admin123");

46
Ajit Gupta Roll no.: 18

Output:

47
Ajit Gupta Roll no.: 18

Practical No. 11
Aim: Demonstrate action classes in Selenium
Program:
package day1;

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.interactions.Actions;

public class DemoAction {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://www.saucedemo.com/");

wd.findElement(By.id("user-name")).sendKeys("standard_user");

wd.findElement(By.id("password")).sendKeys("secret_sauce");

wd.findElement(By.id("login-button")).click();

wd.findElement(By.id("react-burger-menu-btn")).click();

Actions act=new Actions(wd);

List<WebElement> menu=wd.findElements(By.className("bm-item menu-item"));

for(int i=0;i<=menu.size()-1;i++)

System.out.println(menu.get(i).getText());

act.moveToElement(menu.get(i)).perform();

//wd.close();

48
Ajit Gupta Roll no.: 18

Output:

49
Ajit Gupta Roll no.: 18

Program:

package day1;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class DemoAction1


{

public static void main(String[] args)


{

// TODO Auto-generated method stub


System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromed
river.exe");

WebDriver wd=new ChromeDriver();


wd.get("https://opensource-demo.orangehrmlive.com/");
wd.findElement(By.id("txtUsername")).sendKeys("admin");
wd.findElement(By.name("txtPassword")).sendKeys("admin123");
wd.findElement(By.className("button")).click();
Actions act=new Actions(wd);

act.moveToElement(wd.findElement(By.id("menu_recruitment_viewRecruitmentModule"))).
perform();

50
Ajit Gupta Roll no.: 18

Output:

51
Ajit Gupta Roll no.: 18

Program:
package day1;

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.interactions.Actions;

public class DemoAction2 {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.findElement(By.id("txtUsername")).sendKeys("admin");

wd.findElement(By.name("txtPassword")).sendKeys("admin123");

wd.findElement(By.className("button")).click();

Actions act=new Actions(wd);

List<WebElement> menu=wd.findElements(By.className("firstLevelMenu"));

for(int i=0;i<=menu.size()-1;i++)

System.out.println(menu.get(i).getText());

act.moveToElement(menu.get(i)).perform();

wd.findElement(By.partialLinkText("Welcome")).click();

wd.findElement(By.linkText("Logout")).click();

wd.close();

52
Ajit Gupta Roll no.: 18

Output:

53
Ajit Gupta Roll no.: 18

Practical No. 12
Aim: Installation of TestNg , running testNg and TestNg annotations
Installtion TestNg
Go to Eclipse click on Help Menu
And Choose Eclipse Marketplace….

In a Search box Search TestNg and then click Go button.

Click on install button

54
Ajit Gupta Roll no.: 18

Program:
DemoAnnotations

package TestNG;

import org.testng.annotations.Test;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeSuite;

import org.testng.annotations.AfterSuite;

public class DataAnnotation {

@Test

public void f()

System.out.println("Test 1");

@BeforeMethod

public void beforeMethod()

System.out.println("Before Method");

@AfterMethod

public void afterMethod()

System.out.println("After Method");

55
Ajit Gupta Roll no.: 18

@BeforeClass

public void beforeClass()

System.out.println("Before Class");

@AfterClass

public void afterClass()

System.out.println("After Class");

@BeforeTest

public void beforeTest()

System.out.println("Before Test");

@AfterTest

public void afterTest()

System.out.println("After Test");

@BeforeSuite

public void beforeSuite()

System.out.println("Before Suite");

@AfterSuite

56
Ajit Gupta Roll no.: 18

public void afterSuite()

System.out.println("After Suite");

Output:

57
Ajit Gupta Roll no.: 18

DemoAnnotations1

package TestNG;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite;

public class DataAnnotation {


@Test
public void f()
{
System.out.println("Test 1");
}
@Test
public void f1()
{
System.out.println("Test 2");
}

@BeforeMethod
public void beforeMethod()
{
System.out.println("Before Method");
}

@AfterMethod
public void afterMethod()
{
System.out.println("After Method");
}

@BeforeClass
public void beforeClass()
{
System.out.println("Before Class");
}

@AfterClass
public void afterClass()
{
System.out.println("After Class");
}

@BeforeTest
public void beforeTest()
{
System.out.println("Before Test");

58
Ajit Gupta Roll no.: 18

@AfterTest
public void afterTest()
{
System.out.println("After Test");
}

@BeforeSuite
public void beforeSuite()
{
System.out.println("Before Suite");
}

@AfterSuite
public void afterSuite()
{
System.out.println("After Suite");
}

}
Output:

59
Ajit Gupta Roll no.: 18

DataOHM

package TestNG;

import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.DataProvider;

public class DataOHM {

@Test(dataProvider = "dp")

public void f(String u, String p)

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromedriver.
exe");

WebDriver wd= new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

wd.findElement(By.id("txtUsername")).sendKeys(u);//locator id

wd.findElement(By.name("txtPassword")).sendKeys(p);//locater name

wd.findElement(By.className("button")).click();//locator className

try {

wd.findElement(By.partialLinkText("Welcome")).click();//locator
partiallinkText

wd.findElement(By.linkText("Logout")).click();//locator linkText

System.out.println("Pass");

} catch (Exception e) {

System.out.println("Fail");

@DataProvider

public Object[][] dp() {

60
Ajit Gupta Roll no.: 18

return new Object[][] {

new Object[] { "admin", "admin123" },

new Object[] { "add", "b" },

};

Output:

61
Ajit Gupta Roll no.: 18

62
Ajit Gupta Roll no.: 18

DemoAssertFA

package TestNG;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.Assert;

import org.testng.annotations.Test;

public class DemoAssertFA {

@Test

public void frontAccounting()

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromedriver.
exe");

WebDriver wd = new ChromeDriver();

wd.get("http://frontaccounting.squadinfotech.in/index.php");

//FrontAccounting 2.4.8 - Login //valid title

String expectedTitle = "FrontAccounting 2.4.8 - Login";//if title is not matching


execution will be fail

String actualTitle =wd.getTitle();

Assert.assertEquals(actualTitle, expectedTitle);

System.out.println("Title of Webpage=====> " + actualTitle);

Output:

63
Ajit Gupta Roll no.: 18

DemoCheck

package TestNG;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.Assert;

import org.testng.annotations.Test;

public class DemoCheck

@Test(description="Checking status of checkbox")

public void ChekBox()

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromedriver.
exe");

WebDriver wd = new ChromeDriver();

wd.get("https://mail.rediff.com/cgi-bin/login.cgi");

boolean sts = wd.findElement(By.name("remember")).isSelected();

Assert.assertTrue(sts);

64
Ajit Gupta Roll no.: 18

Output:

65
Ajit Gupta Roll no.: 18

DemoDataProvider
package TestNG;

import org.testng.annotations.Test;

import org.testng.annotations.DataProvider;

public class DemoDataProvider {

@Test(dataProvider = "dp")

public void f(Integer n, String s)

System.out.println(n + " " + s);

@DataProvider

public Object[][] dp()

return new Object[][]

new Object[] { 1, "a" },

new Object[] { 2, "b" },

new Object[] {3, "c"} };

}}

Output:

66
Ajit Gupta Roll no.: 18

DemoOHM

package TestNG;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterClass;

import org.testng.annotations.AfterSuite;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.BeforeSuite;

import org.testng.annotations.Test;

public class DemoOHM

WebDriver wd;

@BeforeSuite

public void openBrowser()

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

wd = new ChromeDriver();

@BeforeClass

public void loginOHM()

wd.get("https://opensource-demo.orangehrmlive.com/");

wd.findElement(By.id("txtUsername")).sendKeys("admin");//locator id

wd.findElement(By.name("txtPassword")).sendKeys("admin123");//locater name

wd.findElement(By.className("button")).click();//locator className

67
Ajit Gupta Roll no.: 18

@Test(priority = 2)

public void myInfo()

wd.findElement(By.id("menu_pim_viewMyDetails")).click();

@Test(priority = 1)

public void pim()

wd.findElement(By.id("menu_pim_viewPimModule")).click();

@AfterClass

public void logoutOHM() throws Exception

wd.findElement(By.partialLinkText("Welcome")).click();//locator partiallinkText

Thread.sleep(2000);

wd.findElement(By.linkText("Logout")).click();//locator linkText

@AfterSuite

public void closeBrowser()

wd.quit();

68
Ajit Gupta Roll no.: 18

Output:

69
Ajit Gupta Roll no.: 18

70
Ajit Gupta Roll no.: 18

Practical No. 13
Aim: Demonstrate data driven Framework.
First Create DemoExcel (.xlsx) in selenium folder
Give Sheet name WriteOHM and write username and password

Program:
WriteData
package day2;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class WriteData {

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

// TODO Auto-generated method stub

71
Ajit Gupta Roll no.: 18

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd= new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

FileInputStream fis= new


FileInputStream("E:\\MCA_SEM3\\Selenium\\DemoExcel.xlsx");

XSSFWorkbook wb = new XSSFWorkbook(fis);

XSSFSheet sh= wb.getSheet("ReadData");

for(int i=1; i<=sh.getLastRowNum();i++)

XSSFRow rw= sh.getRow(i);

XSSFCell un= rw.getCell(0);

XSSFCell pw=rw.getCell(1);

System.out.println("username........>" +un + "Password.......>"+pw);

wd.findElement(By.id("txtUsername")).sendKeys(un.toString());

wd.findElement(By.id("txtPassword")).sendKeys(pw.toString());

wd.findElement(By.id("btnLogin")).click();

wd.findElement(By.linkText("Welcome shruti")).click();

Thread.sleep(2000);

wd.findElement(By.linkText("Logout")).click();

72
Ajit Gupta Roll no.: 18

Output:

73
Ajit Gupta Roll no.: 18

ValidData
In that DemoExcel File add new Sheet
Give name WriteDataOHM and
Add Wrong username and password and
Put empty result Column

Program:
package day2;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.util.concurrent.TimeUnit;

import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class ValidData {

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

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd= new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

74
Ajit Gupta Roll no.: 18

wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

FileInputStream fis= new


FileInputStream("E:\\MCA_SEM3\\Selenium\\DemoExcel.xlsx");

XSSFWorkbook wb = new XSSFWorkbook(fis);

XSSFSheet sh= wb.getSheet("WriteDataOHM");

for(int i=1; i<=sh.getLastRowNum();i++)

XSSFRow rw= sh.getRow(i);

XSSFCell un= rw.getCell(0);

XSSFCell pw=rw.getCell(1);

XSSFCell res=rw.createCell(2);

System.out.println("username........>" +un + "Password.......>"+pw);

wd.findElement(By.id("txtUsername")).sendKeys(un.toString());

wd.findElement(By.id("txtPassword")).sendKeys(pw.toString());

wd.findElement(By.id("btnLogin")).click();

try {

wd.findElement(By.partialLinkText("Welcome shruti")).click();

wd.findElement(By.linkText("Logout")).click();

System.out.println("Logged in successfully");

res.setCellValue("Valid");

} catch(Exception e) {

System.out.println("logged in Fail");

res.setCellValue("Invalid");

fis.close();

FileOutputStream fos = new


FileOutputStream("E:\\MCA_SEM3\\Selenium\\DemoExcel.xlsx");

wb.write(fos);

wd.close(); }

75
Ajit Gupta Roll no.: 18

Output:

76
Ajit Gupta Roll no.: 18

77
Ajit Gupta Roll no.: 18

Practical No. 14
Aim: Demonstrate Validation testing
First Create DemoExcel (.xlsx) in selenium folder
Give Sheet name WriteOHM and write username and password

Program:
import java.io.FileInputStream;

import java.io.FileNotFoundException;

import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class WriteData

public static void main(String[] args) throws Exception

78
Ajit Gupta Roll no.: 18

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd= new ChromeDriver();

wd.get("https://opensource-demo.orangehrmlive.com/");

FileInputStream fis= new


FileInputStream("E:\\MCA_SEM3\\Selenium\\DemoExcel.xlsx");

XSSFWorkbook wb = new XSSFWorkbook(fis);

XSSFSheet sh= wb.getSheet("ReadData");

for(int i=1; i<=sh.getLastRowNum();i++)

XSSFRow rw= sh.getRow(i);

XSSFCell un= rw.getCell(0);

XSSFCell pw=rw.getCell(1);

System.out.println("username........>" +un + "Password.......>"+pw);

79
Ajit Gupta Roll no.: 18

Output:

80
Ajit Gupta Roll no.: 18

DemoAssert
Program:
package TestNG;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.Assert;

import org.testng.annotations.Test;

public class DemoAssert {

@Test

public void frontAccounting()

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");

WebDriver wd=new ChromeDriver();

wd.get("http://frontaccounting.squadinfotech.in/index.php");

//FrontAccounting 2.4.8 - Login //valid title

String expectedTitle = "FrontAccounting";//if title is not matching execution will be


fail

String actualTitle =wd.getTitle();

Assert.assertEquals(actualTitle, expectedTitle);

System.out.println("Title of Webpage=====> " + actualTitle);

Output:

81
Ajit Gupta Roll no.: 18

DemoWindowHandling
Program:

package day1;

import java.util.Set;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

public class DemoWindowHandling {

public static void main(String[] args) {

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32
\\chromedriver.exe");

WebDriver wd= new ChromeDriver();

wd.get("http://frontaccounting.squadinfotech.in/index.php");

wd.findElement(By.name("user_name_entry_field")).sendKeys("frontuser1");

wd.findElement(By.name("password")).sendKeys("frontuser1");

Select s = new Select(wd.findElement(By.name("company_login_name")));

s.selectByVisibleText("Squad_MT_OL-50");

wd.findElement(By.name("SubmitUser")).click();

//sales quotation entry

wd.findElement(By.xpath("/html/body/table[1]/tbody/tr/td/table[1]/tbody/tr/td/di
v[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td[1]/a[1]")).click();

String Pid = wd.getWindowHandle();//getting id of current page

System.out.println("Parent Window----> " + Pid);

wd.findElement(By.xpath("/html/body/table[1]/tbody/tr/td/table[1]/tbody/tr/td/di
v[2]/form/center[1]/table/tbody/tr/td[2]/table/tbody/tr[1]/td[2]/a")).click();

Set<String> allwin = wd.getWindowHandles();//getting id of all opened win

for(String W:allwin)

wd.switchTo().window(W);

82
Ajit Gupta Roll no.: 18

System.out.println(wd.getTitle());

if(!(W.equals(Pid)))

Select ss = new
Select(wd.findElement(By.id("customer_id")));

ss.selectByIndex(0);

wd.manage().window().maximize();

wd.close();

wd.switchTo().window(Pid);

wd.findElement(By.linkText("Logout")).click();

wd.close();

Output:

83
Ajit Gupta Roll no.: 18

Practical No. 15
Aim: Perform regression testing
Theory:
What is Regression Testing?
REGRESSION TESTING is defined as a type of software testing to confirm that a
recent program or code change has not adversely affected existing features.

Regression Testing is nothing but a full or partial selection of already executed test
cases which are re-executed to ensure existing functionalities work fine.

This testing is done to make sure that new code changes should not have side effects
on the existing functionalities. It ensures that the old code still works once the latest code
changes are done.

Need of Regression Testing


The Need of Regression Testing mainly arises whenever there is requirement to
change the code and we need to test whether the modified code affects the other part of
software application or not. Moreover, regression testing is needed, when a new feature is
added to the software application and for defect fixing as well as performance issue fixing.
How to do Regression Testing
In order to do Regression Testing process, we need to first debug the code to identify
the bugs. Once the bugs are identified, required changes are made to fix it, then the regression
testing is done by selecting relevant test cases from the test suite that covers both modified
and affected parts of the code.
Software maintenance is an activity which includes enhancements, error corrections,
optimization and deletion of existing features. These modifications may cause the system to
work incorrectly. Therefore, Regression Testing becomes necessary.

Regression Test Selection


Regression Test Selection is a technique in which some selected test cases from test
suite are executed to test whether the modified code affects the software application or not.
Test cases are categorized into two parts, reusable test cases which can be used in further
regression cycles and obsolete test cases which can not be used in succeeding cycles.

84

You might also like