0% found this document useful (0 votes)
38 views

Module 3 - Assignment

Uploaded by

priyanka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Module 3 - Assignment

Uploaded by

priyanka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Selenium Module 3

Assignment Submitted By-Priyanka Yadav (26 May Weekday Batch)

Assignment -1(TestNG):

➤ url : https://demo.guru99.com/test/login.html

➤ Using TestNG Annotaions to complete this assignment

➤ In Before test annotation must have the initialize the drivers

➤ In Test annotation we have to enter the username and password

➤ In After annotation must have the close() to close the application

package TestNg;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

public class Assignment1 {

WebDriver driver;

@BeforeMethod

public void browserSetup() {

System.out.println("Browser and App setup");

driver=new ChromeDriver();

driver.get("https://demo.guru99.com/test/login.html");

@Test

public void validateLogin() {

driver.findElement(By.xpath("//input[@id=\"email\"]")).sendKeys("Admi
n");

driver.findElement(By.name("passwd")).sendKeys("admin123");
driver.findElement(By.name("SubmitLogin")).click();

@AfterMethod

public void closeSetup() {

System.out.println("Close the browser");

driver.close();

Assignment -2(TestNG):

➤ url : https://demo.guru99.com/test/login.html

➤ Using TestNG Annotaions to complete this assignment

➤ In Before test annotation must have the initialize the drivers

➤ In Test annotation we have to enter the username and password

➤ You need to take the data(username and password) from datadriven method

➤ In After annotation must have the close() to close the application

package TestNg;

import java.io.IOException;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;

public class Assignment2 {


WebDriver driver;

@BeforeMethod

public void browserSetup() {

System.out.println("Browser and App setup");

driver=new ChromeDriver();

driver.get("https://demo.guru99.com/test/login.html");

@Test(dataProvider = "getLoginDataFromExcel")

public void Login(String username, String password) {

System.out.println(username);

System.out.println(password);

@DataProvider

public Object[][] getLoginDataFromExcel() throws IOException {

ExcelReaderDemo obj = new ExcelReaderDemo();

return obj.getData();

@AfterMethod

public void closeSetup() {

System.out.println("Close the browser");

driver.close();

}
(ExcelReaderDemo File)
package TestNg;

import java.io.IOException;

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

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

public class ExcelReaderDemo {

public Object[][] getData() throws IOException {

String filePath="./src/test/java/TestNg/TestData.xlsx";

XSSFWorkbook wb= new XSSFWorkbook(filePath);

XSSFSheet sheet=wb.getSheet("data");

int rowcount=sheet.getPhysicalNumberOfRows();

int colcount= sheet.getRow(0).getLastCellNum();

System.out.println(sheet.getPhysicalNumberOfRows());

System.out.println(sheet.getRow(0).getLastCellNum());

Object[][] data = new Object[rowcount][colcount];

for (int row = 0; row < rowcount; row++) {

for (int col = 0; col < colcount; col++) {

data[row][col] = sheet.getRow(row).getCell(col).getStringCellValue();

System.out.println(sheet.getRow(row).getCell(col).getStringCellValue());

return data;

}
}

Assignment -3(TestNG):

➤ url : https://demoqa.com/

➤ Click on Forms

➤ Click on Practise Form

➤ Make above two actions in group as smoke test

➤ Then fill the entire form group name will be regression

➤ Enter Submit

package TestNg;

import java.awt.AWTException;

import java.awt.Robot;

import java.awt.Toolkit;

import java.awt.datatransfer.StringSelection;

import java.awt.event.KeyEvent;

import java.time.Duration;

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.Keys;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.interactions.Actions;

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

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;
public class Assignment3 {

WebDriver driver;

@BeforeMethod

public void browserSetup() {

driver=new ChromeDriver();

System.out.println("Browser and App setup");

driver.manage().window().maximize();

driver.get("https://demoqa.com");

@Test(groups="smoke test",priority=1)

public void click_on_Form() throws InterruptedException {

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

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

Actions act= new Actions(driver);

act.scrollByAmount(0, 400).perform();

driver.findElement(By.xpath("//div[@id='app']/div/div/div[2]/div/div[2]")).
click();

Thread.sleep(2000);

@Test(groups="smoke test",priority=2)

public void click_on_Practice_Form() throws InterruptedException {

System.out.println(" Practice Form Method");

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

Actions act= new Actions(driver);

act.scrollByAmount(0, 400).perform();

driver.findElement(By.xpath("//div[@id='app']/div/div/div[2]/div/div[2]")).
click();

driver.findElement(By.xpath("//span[text()='Practice Form']")).click();

Thread.sleep(2000);

}
@Test(groups="regression")

void fill_Practice_Form() throws InterruptedException, AWTException {

Actions act= new Actions(driver);

act.scrollByAmount(0, 500).perform();

driver.findElement(By.xpath("//div[@id='app']/div/div/div[2]/div/div[2]")).
click();

driver.findElement(By.xpath("//span[text()='Practice Form']")).click();

Thread.sleep(2000);

driver.findElement(By.id("firstName")).sendKeys("Priyanka");

driver.findElement(By.id("lastName")).sendKeys("Yadav");

driver.findElement(By.id("userEmail")).sendKeys("[email protected]"
);

driver.findElement(By.xpath("//div[@id='genterWrapper']/child::div[2]/child
::div[2]/child::label[1]")).click();

Thread.sleep(2000);

driver.findElement(By.id("userNumber")).sendKeys("1234567898");

//to click on dateOfBirth text box

driver.findElement(By.xpath("//div[@class='react-datepicker__input-
container']")).click();

String expDay="24";

WebElement monthContainer=driver.findElement(By.xpath("//div[@class='react-
datepicker__header']/child::div[2]/child::div[1]/child::select"));

Select month=new Select(monthContainer);

month.selectByValue("5");

WebElement yearContainer=driver.findElement(By.xpath("//div[@class='react-
datepicker__header']/child::div[2]/child::div[2]/child::select"));

Select year=new Select(yearContainer);

year.selectByVisibleText("1987");

List<WebElement> days=driver.findElements(By.xpath("//div[@class='react-
datepicker__week']/child::div"));

for(WebElement day:days) {

String calDay=day.getText();

if(calDay.equalsIgnoreCase(expDay)) {
Thread.sleep(2000);

day.click();

break;

Thread.sleep(1000);

WebElement
subjectText=driver.findElement(By.xpath("//input[@id='subjectsInput']"));

subjectText.sendKeys("Maths");

subjectText.sendKeys(Keys.ENTER);

driver.findElement(By.xpath("//div[@id='hobbiesWrapper']/child::div[2]/chil
d::div[2]/child::label[1]")).click();

Thread.sleep(1000);

WebElement chooseFile=driver.findElement(By.xpath("//div[@class='practice-
form-
wrapper']/child::form[1]/child::div[8]/child::div[2]/child::div[1]/child::l
abel[1]"));

chooseFile.sendKeys("F:\\Assignments\\src\\test\\java\\TestNg\\TestData.xls
x");

chooseFile.click();

Thread.sleep(3000);

Robot robo=new Robot();

String
filePath="C:\\Users\\harsh\\OneDrive\\Pictures\\Screenshots\\AddCustomerFea
ture.png";

StringSelection str=new StringSelection(filePath);

Toolkit.getDefaultToolkit().getSystemClipboard().setContents(str, null);

robo.keyPress(KeyEvent.VK_CONTROL);

robo.keyPress(KeyEvent.VK_V);

robo.keyPress(KeyEvent.VK_ENTER);

Thread.sleep(3000);

robo.keyRelease(KeyEvent.VK_CONTROL);

robo.keyRelease(KeyEvent.VK_V);
robo.keyRelease(KeyEvent.VK_ENTER);

//Enter the Current Address in text area

driver.findElement(By.xpath("//div[@id='currentAddress-
wrapper']/child::div[2]/child::textarea[1]")).sendKeys("panvel");

WebElement stateElement=driver.findElement(By.xpath("//input[@id='react-
select-3-input']"));

stateElement.sendKeys("Haryana");

stateElement.sendKeys(Keys.ENTER);

WebElement submitBtn=driver.findElement(By.id("submit"));

submitBtn.sendKeys(Keys.ENTER);

Thread.sleep(2000);

System.out.println("Form submitted Successfully");

@AfterMethod

public void closeSetup() {

System.out.println("Close the browser");

driver.close();

(Testing.xml File)
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

<suite name="Suite">

<test thread-count="5" name="Test">

<groups>

<run>

<include name="smoke test" />

<include name="regression" />

</run>
</groups>

<classes>

<class name="TestNg.Assignment3"/>

</classes>

</test> <!-- Test -->

</suite> <!-- Suite -->

You might also like