45 Hrishikesh STQA

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 88

Hrishikesh Rane Roll no.

: 45

Practical No. 1
Aim: Take a review and write test cases for any known application.
Test Scenarios of Facebook
1.Verify that user can set profile pic uploaded from his or her
computer.
2.Verify that user can set profile pic uploaded from mobile.
3.Verify that uer can set profile pic from photos present on his facbook
account’s photo section.
4.Verify that user can set profile from webcam or mobile camera.
5.Verify that user can set cover pic uploaded from his or her computer.
6.Verify that user can set cover pic uploaded from mobile.
7.Verify that user can set cover pic from photos present on his facbook
account’s photo section.
8.Verify that user can set cover from webcam or mobile camera.
9.Verify that uploading image of unsupported type should lead to error
message.
10. Verify that uploading image of size exceeding maximum
allowed size should lead to error message.
11. Verify that uploading image of size less than the allowed
minimum size should lead to error message.
12. Verify that uploading image of larger dimension than permitted
should lead to error message.
13. Verify that uploading image of smaller dimension than
permitted should lead to error message.
14. Verify that change in profile pic should get reflected in each
post/comment of the user’s timeline.
15. Verify that user can add/edit their account information
displayed to other users.
16. Verify that users can post text in their timeline and the same
gets displyed to their friends.
17. Verify that users can post images in their timeline and the same
gets displyed to their friends.
18. Verify that users can post links with or without preview in their
timeline and the same gets displayed to their friends.
19. Verify that user can tag friends in their posts.
20. Verify that users can see the all the post in their timeline.

1
Hrishikesh Rane Roll no.: 45

21. Verify that users can see comments, likes and reactions in the
posts present in their timeline.
22. Verify that users can post comments, like and react to the posts
present in their timeline.

Test scenarios

1. Verify that users receive different notifications on facebook


‘Notifications’ icon.
2. Verify that users receive different notifications on email or cell
phone based on the settings chosen when not logged in to
Facebook.
3. Verify that users receive a notification when their friend request
gets approved.
4. Verify that users receive a notification when they get a friend
request.
5. Verify that users receive a notification when they get tagged by
someone on posts or comments.
6. Verify that users receive a notification when they get comments,
like or reactions on their posts.
7. Verify that users receive notification when someone posts on their
timeline.

2
Hrishikesh Rane Roll no.: 45

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
Hrishikesh Rane Roll no.: 45

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.

4
Hrishikesh Rane Roll no.: 45

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.

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
Hrishikesh Rane Roll no.: 45

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
Hrishikesh Rane Roll no.: 45

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
Hrishikesh Rane Roll no.: 45

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
Hrishikesh Rane Roll no.: 45

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
Hrishikesh Rane Roll no.: 45

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
Hrishikesh Rane Roll no.: 45

11
Hrishikesh Rane Roll no.: 45

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\\chromed
river.exe");
WebDriver wd=new ChromeDriver();
wd.get("https://www.google.com");
}
}
Output:

12
Hrishikesh Rane Roll no.: 45

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;

13
Hrishikesh Rane Roll no.: 45

default:

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

if(wd!=null)

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

Output:

14
Hrishikesh Rane Roll no.: 45

15
Hrishikesh Rane Roll no.: 45

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;

16
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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();

Output:

17
Hrishikesh Rane Roll no.: 45

18
Hrishikesh Rane Roll no.: 45

19
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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();

20
Hrishikesh Rane Roll no.: 45

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();

Output:

21
Hrishikesh Rane Roll no.: 45

22
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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();

23
Hrishikesh Rane Roll no.: 45

Output:

24
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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();

25
Hrishikesh Rane Roll no.: 45

Output:

26
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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")).sendKeys
("admin");

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

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

27
Hrishikesh Rane Roll no.: 45

Output:

28
Hrishikesh Rane Roll no.: 45

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

29
Hrishikesh Rane Roll no.: 45

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromedriver.ex
e");
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();
}

Output:

30
Hrishikesh Rane Roll no.: 45

Explicit wait
Program:
package day1;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

31
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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();

Output:

32
Hrishikesh Rane Roll no.: 45

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

33
Hrishikesh Rane Roll no.: 45

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\\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();

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();

Output:

34
Hrishikesh Rane Roll no.: 45

Practical No. 9
35
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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");

36
Hrishikesh Rane Roll no.: 45

Output:

37
Hrishikesh Rane Roll no.: 45

38
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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">

39
Hrishikesh Rane Roll no.: 45

<title>Multiple</title>

</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:

40
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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();

41
Hrishikesh Rane Roll no.: 45

Output:

42
Hrishikesh Rane Roll no.: 45

43
Hrishikesh Rane Roll no.: 45

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\\chromedriver.ex
e");
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>

44
Hrishikesh Rane Roll no.: 45

Output:

45
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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
Hrishikesh Rane Roll no.: 45

Output:

47
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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");

48
Hrishikesh Rane Roll no.: 45

Output:

49
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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();

50
Hrishikesh Rane Roll no.: 45

Output:

51
Hrishikesh Rane Roll no.: 45

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\\chromedriver.ex
e");

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
();

52
Hrishikesh Rane Roll no.: 45

Output:

53
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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();

54
Hrishikesh Rane Roll no.: 45

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();

Output:

55
Hrishikesh Rane Roll no.: 45

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.

56
Hrishikesh Rane Roll no.: 45

Click on install button

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");

57
Hrishikesh Rane Roll no.: 45

@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
Hrishikesh Rane Roll no.: 45

@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
Hrishikesh Rane Roll no.: 45

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;

60
Hrishikesh Rane Roll no.: 45

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");
}

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

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

@AfterSuite

61
Hrishikesh Rane Roll no.: 45

public void afterSuite()


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

}
Output:

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;

62
Hrishikesh Rane Roll no.: 45

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() {

return new Object[][] {

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

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

};

Output:

63
Hrishikesh Rane Roll no.: 45

64
Hrishikesh Rane Roll no.: 45

65
Hrishikesh Rane Roll no.: 45

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:

66
Hrishikesh Rane Roll no.: 45

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);

67
Hrishikesh Rane Roll no.: 45

Output:

68
Hrishikesh Rane Roll no.: 45

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:

69
Hrishikesh Rane Roll no.: 45

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

70
Hrishikesh Rane Roll no.: 45

@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();

71
Hrishikesh Rane Roll no.: 45

Output:

72
Hrishikesh Rane Roll no.: 45

73
Hrishikesh Rane Roll no.: 45

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

74
Hrishikesh Rane Roll no.: 45

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromedriver.
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();

75
Hrishikesh Rane Roll no.: 45

Output:

76
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
exe");

WebDriver wd= new ChromeDriver();

77
Hrishikesh Rane Roll no.: 45

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

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(); }

78
Hrishikesh Rane Roll no.: 45

Output:

79
Hrishikesh Rane Roll no.: 45

80
Hrishikesh Rane Roll no.: 45

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

81
Hrishikesh Rane Roll no.: 45

// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver","E:\\Software\\chromedriver_win32\\chromedriver.
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);

82
Hrishikesh Rane Roll no.: 45

Output:

83
Hrishikesh Rane Roll no.: 45

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\\chromedriver.
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:

84
Hrishikesh Rane Roll no.: 45

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/div
[2]/table/tbody/tr[1]/td/table/tbody/tr[2]/td[1]/a[1]")).click();

85
Hrishikesh Rane Roll no.: 45

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/div
[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);

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:

86
Hrishikesh Rane Roll no.: 45

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

87
Hrishikesh Rane Roll no.: 45

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.

88

You might also like