Professional Documents
Culture Documents
: 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.
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.
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.
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
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.
9
Ajit Gupta Roll no.: 18
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;
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;
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
//System.setProperty("webdriver.gecko.driver","D:\\Selenium\\geckodriver.exe");
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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();
//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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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;
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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.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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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");
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();
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
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
wd.get("https://blazedemo.com/");
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
wd.get("E:\\MCA_SEM3\\Selenium\\Multi.html");
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>
<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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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
package day1;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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();
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;
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
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();
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….
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;
@Test
System.out.println("Test 1");
@BeforeMethod
System.out.println("Before Method");
@AfterMethod
System.out.println("After Method");
55
Ajit Gupta Roll no.: 18
@BeforeClass
System.out.println("Before Class");
@AfterClass
System.out.println("After Class");
@BeforeTest
System.out.println("Before Test");
@AfterTest
System.out.println("After Test");
@BeforeSuite
System.out.println("Before Suite");
@AfterSuite
56
Ajit Gupta Roll no.: 18
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;
@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;
@Test(dataProvider = "dp")
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromedriver.
exe");
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
60
Ajit Gupta Roll no.: 18
};
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;
@Test
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromedriver.
exe");
wd.get("http://frontaccounting.squadinfotech.in/index.php");
Assert.assertEquals(actualTitle, expectedTitle);
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromedriver.
exe");
wd.get("https://mail.rediff.com/cgi-bin/login.cgi");
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;
@Test(dataProvider = "dp")
@DataProvider
}}
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;
WebDriver wd;
@BeforeSuite
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
wd = new ChromeDriver();
@BeforeClass
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)
wd.findElement(By.id("menu_pim_viewMyDetails")).click();
@Test(priority = 1)
wd.findElement(By.id("menu_pim_viewPimModule")).click();
@AfterClass
wd.findElement(By.partialLinkText("Welcome")).click();//locator partiallinkText
Thread.sleep(2000);
wd.findElement(By.linkText("Logout")).click();//locator linkText
@AfterSuite
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;
71
Ajit Gupta Roll no.: 18
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
wd.get("https://opensource-demo.orangehrmlive.com/");
XSSFCell pw=rw.getCell(1);
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
wd.get("https://opensource-demo.orangehrmlive.com/");
74
Ajit Gupta Roll no.: 18
wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
XSSFCell pw=rw.getCell(1);
XSSFCell res=rw.createCell(2);
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();
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;
78
Ajit Gupta Roll no.: 18
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
wd.get("https://opensource-demo.orangehrmlive.com/");
XSSFCell pw=rw.getCell(1);
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;
@Test
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chrom
edriver.exe");
wd.get("http://frontaccounting.squadinfotech.in/index.php");
Assert.assertEquals(actualTitle, expectedTitle);
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;
System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32
\\chromedriver.exe");
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");
s.selectByVisibleText("Squad_MT_OL-50");
wd.findElement(By.name("SubmitUser")).click();
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();
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();
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.
84