top of page

Forum Posts

md.navedparvez2127
Feb 16, 2022
In Thread Discussions
data provider annotation class ------------------------------ package testtime; import java.io.File; import java.io.IOException; import org.openqa.selenium.By; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Parameters; import org.testng.annotations.Test; import org.apache.commons.io.FileUtils; public class dataproviderannotation { WebDriver driver; @BeforeMethod public void hplanding() { System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\Desktop\\QA testing\\All Jars\\chromedriver.exe"); driver= new ChromeDriver(); driver.manage().window().maximize(); driver.manage().deleteAllCookies(); } @Test (dataProvider="getdata") public void Siterun(String username, String password) throws InterruptedException, IOException { driver.get("https://www.hp.com/us-en/home.html"); Thread.sleep(4000); this.takeSnapshot(driver, "C:\\Users\\User\\Documents\\automation screenshot//test.jpeg"); System.out.println("site land it to hp.com"); driver.findElement(By.xpath("//*[@id=\"onetrust-close-btn-container\"]/button")).click(); Thread.sleep(4000); this.takeSnapshot(driver, "C:\\Users\\User\\Documents\\automation screenshot//test2.jpeg"); System.out.println("pop up box is closed down"); String naved = driver.getTitle(); System.out.println("Title is:" + naved); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"wpr-signin-tablet\"]/a/span/p")).click(); Thread.sleep(4000); this.takeSnapshot(driver, "C:\\Users\\User\\Documents\\automation screenshot//test3.jpeg"); System.out.println("successfully clicked sign in button"); driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/form/div[1]/div/input")).clear(); Thread.sleep(3000); driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/form/div[1]/div/input")).click(); Thread.sleep(3000); driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/form/div[1]/div/input")).sendKeys(username); Thread.sleep(2000); this.takeSnapshot(driver, "C:\\Users\\User\\Documents\\automation screenshot//test4.jpeg"); System.out.println("username is:" + username); driver.findElement(By.xpath("//button[@id='user-name-form-submit']")).click(); Thread.sleep(2000); driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/form/div[1]/div/div/input")).sendKeys(password); Thread.sleep(2000); this.takeSnapshot(driver, "C:\\Users\\User\\Documents\\automation screenshot//test5.jpeg"); System.out.println("password is:" + password); driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/form/div[2]/button")).click(); Thread.sleep(4000); driver.close(); } public static void takeSnapshot(WebDriver webdriver, String fileWithPath) throws IOException { TakesScreenshot snapshot= ((TakesScreenshot) webdriver); File SnapFile=snapshot.getScreenshotAs(OutputType.FILE); File DestFile= new File(fileWithPath); FileUtils.copyFile(SnapFile, DestFile); } @DataProvider public Object[] [] getdata() { Object[][] vipdata = new Object[3][2]; vipdata[0][0]="navedinnsire"; vipdata[0][1]= "parvez1234"; vipdata[1][0]="innsire2"; vipdata[1][1]="innsireagain345"; vipdata[2][0]="parvezinnsire3"; vipdata[2][1]="innsireagain678"; return vipdata; } } hpwebelement class ------------------------------ package testtime; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.By; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; 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 hpwebelement { WebDriver driver; @BeforeMethod public void hplanding() { System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\Desktop\\QA testing\\All Jars\\chromedriver.exe"); driver= new ChromeDriver(); driver.manage().window().maximize(); driver.manage().deleteAllCookies(); } @Test public void Siterun() throws InterruptedException, IOException { driver.get("https://www.hp.com/us-en/home.html"); Thread.sleep(4000); this.takeSnapshot2(driver, "C:\\Users\\User\\Documents\\automation screenshot//test11.jpeg"); System.out.println("site land it to hp.com"); driver.findElement(By.xpath("//*[@id=\"onetrust-close-btn-container\"]/button")).click(); Thread.sleep(4000); this.takeSnapshot2(driver, "C:\\Users\\User\\Documents\\automation screenshot//test12.jpeg"); System.out.println("pop up box is closed down"); String naved = driver.getTitle(); System.out.println("Title is:" + naved); Thread.sleep(2000); driver.findElement(By.xpath("/html/body/div[1]/div/section[2]/div/div[2]/nav/div[1]/div/div[1]/div/div/div[1]")).click(); Thread.sleep(4000); this.takeSnapshot2(driver, "C:\\Users\\User\\Documents\\automation screenshot//test13.jpeg"); System.out.println("successfully clicked Explore"); } @AfterMethod public void teardown() { driver.close(); System.out.println("driver closed"); } public static void takeSnapshot2(WebDriver webdriver, String fileWithPath) throws IOException { TakesScreenshot snapshot1= ((TakesScreenshot) webdriver); File SnapFile=snapshot1.getScreenshotAs(OutputType.FILE); File DestFile= new File(fileWithPath); FileUtils.copyFile(SnapFile, DestFile); } xml testng -------------------------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> <suite name="Suite" parallel= "tests" thread-count= "2" > <listeners> <listener class-name= "testtime.listeners"/> </listeners> <parameter name="URL" value= "https://www.hp.com/us-en/home.html"/> <parameter name="Username" value= "navedinnsire@gmail.com"/> <parameter name="password" value= "Passinssire123"/> <test thread-count="5" name="Test1"> <classes> <class name="testtime.hpwebelement"/> </classes> </test> <!-- Test --> <test thread-count="5" name="Test2"> <classes> <class name="testtime.dataproviderannotation"/> </classes> </test> <!-- Test --> </suite> <!-- Suite -->
0
0
8
md.navedparvez2127
Feb 08, 2022
In Thread Discussions
package testtime; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Parameters; import org.testng.annotations.Test; public class dataproviderannotation { WebDriver driver; @BeforeMethod public void hplanding() { System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\Desktop\\QA testing\\All Jars\\chromedriver.exe"); driver= new ChromeDriver(); driver.manage().window().maximize(); driver.manage().deleteAllCookies(); } @Test (dataProvider="getdata") public void Siterun(String username, String password) throws InterruptedException { driver.get("https://www.hp.com/us-en/home.html"); Thread.sleep(4000); System.out.println("site land it to hp.com"); driver.findElement(By.xpath("//*[@id=\"onetrust-close-btn-container\"]/button")).click(); Thread.sleep(4000); System.out.println("pop up box is closed down"); String naved = driver.getTitle(); System.out.println("Title is:" + naved); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"wpr-signin-tablet\"]/a/span/p")).click(); Thread.sleep(4000); System.out.println("successfully clicked sign in button"); driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/form/div[1]/div/input")).clear(); Thread.sleep(3000); driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/form/div[1]/div/input")).click(); Thread.sleep(3000); driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/form/div[1]/div/input")).sendKeys(username); Thread.sleep(2000); System.out.println("username is:" + username); driver.findElement(By.xpath("//button[@id='user-name-form-submit']")).click(); Thread.sleep(2000); driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/form/div[1]/div/div/input")).sendKeys(password); Thread.sleep(2000); System.out.println("password is:" + password); driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/form/div[2]/button")).click(); Thread.sleep(4000); driver.close(); } @DataProvider public Object[] [] getdata() { Object[][] vipdata = new Object[3][2]; vipdata[0][0]="navedinnsire"; vipdata[0][1]= "parvez1234"; vipdata[1][0]="innsire2"; vipdata[1][1]="innsireagain345"; vipdata[2][0]="parvezinnsire3"; vipdata[2][1]="innsireagain678"; return vipdata; } }
0
0
13

md.navedparvez2127

More actions

IT Consulting, Training and Job Placement services

bottom of page