Forum Posts

musaib.ahmed.2230
Feb 16, 2022
In Thread Discussions
Innsire class package DellPack; 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.Parameters; import org.testng.annotations.Test; public class firstTest { WebDriver driver; @BeforeMethod public void setup() throws InterruptedException, IOException { System.setProperty("webdriver.chrome.driver", "C:\\Users\\ahmed\\OneDrive\\Desktop\\Automation\\All jar\\All Jars\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().deleteAllCookies(); driver.manage().window().maximize(); driver.get("https://innsire.com/"); Thread.sleep(2000); this.takeSnapShot(driver, "C:\\Users\\ahmed\\OneDrive\\Desktop\\QA\\Screenshot//in.png"); } @Parameters({"url"}) @Test(priority=3) public void Innsire(String urlName) throws IOException { driver.get(urlName); System.out.println("Testing Innsire Website"); System.out.println(driver.getTitle()); this.takeSnapShot(driver, "C:\\Users\\ahmed\\OneDrive\\Desktop\\QA\\Screenshot//in1.png"); } @Parameters({"url", "userName", "password"}) @Test(priority=4) public void InnsireLogIn(String urlName, String username, String password) throws InterruptedException, IOException { driver.get(urlName); //Verify Login from .Com In driver.findElement(By.xpath("//*[@id=\"nav-menu-item-6544\"]/a")).click(); System.out.println("Verify log in for Inssire"); this.takeSnapShot(driver, "C:\\Users\\ahmed\\OneDrive\\Desktop\\QA\\Screenshot//in2.png"); //Verify Login to My Account Page driver.findElement(By.xpath("//*[@id=\"comp-kxjz98eb\"]/a/div/span[1]")).click(); Thread.sleep(2000); System.out.println("Verify My account Page open"); this.takeSnapShot(driver, "C:\\Users\\ahmed\\OneDrive\\Desktop\\QA\\Screenshot//in3.png"); //Click On Login Button driver.findElement(By.xpath("//*[@id=\"SM_ROOT_COMP5\"]/div[1]/div/button")).click(); Thread.sleep(2000); System.out.println("Verify Login Button"); //Verify UserName driver.findElement(By.id("input_input_emailInput_SM_ROOT_COMP6")).click(); driver.findElement(By.id("input_input_emailInput_SM_ROOT_COMP6")).clear(); driver.findElement(By.id("input_input_emailInput_SM_ROOT_COMP6")).sendKeys(username); Thread.sleep(2000); System.out.println("Verify username for Innsire"); this.takeSnapShot(driver, "C:\\Users\\ahmed\\OneDrive\\Desktop\\QA\\Screenshot//in4.png"); //Verify Password driver.findElement(By.id("input_input_passwordInput_SM_ROOT_COMP6")).click(); driver.findElement(By.id("input_input_passwordInput_SM_ROOT_COMP6")).clear(); driver.findElement(By.id("input_input_passwordInput_SM_ROOT_COMP6")).sendKeys(password); Thread.sleep(2000); System.out.println("Verify password for Innsire"); this.takeSnapShot(driver, "C:\\Users\\ahmed\\OneDrive\\Desktop\\QA\\Screenshot//in5.png"); } public static void takeSnapShot(WebDriver webDriver, String fileWithPath) throws IOException { //Convert webdriver Object to Take ScreenShot TakesScreenshot scrShot= ((TakesScreenshot)webDriver); //Call getScreenshot as method to create image file File SrcFile=scrShot.getScreenshotAs(OutputType.FILE); //Move Image file to new Destination File destFile = new File(fileWithPath); //Copy file at destination FileUtils.copyFile(SrcFile, destFile); } @AfterMethod public void close() { driver.close(); } } Google clas package DellPack; 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.Parameters; import org.testng.annotations.Test; import com.beust.jcommander.Parameter; public class secondTest { WebDriver driver; @BeforeMethod public void setup() throws InterruptedException, IOException { System.setProperty("webdriver.chrome.driver", "C:\\Users\\ahmed\\OneDrive\\Desktop\\Automation\\All jar\\All Jars\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().deleteAllCookies(); driver.manage().window().maximize(); driver.get("https://google.com"); Thread.sleep(2000); this.takeSnapShot(driver, "C:\\Users\\ahmed\\OneDrive\\Desktop\\QA\\Screenshot//test.png"); } @Parameters({"URL"}) @Test(priority=1) public void Google(String urlName) throws IOException { driver.get(urlName); System.out.println("Testing Google Website"); System.out.println(driver.getTitle()); this.takeSnapShot(driver, "C:\\Users\\ahmed\\OneDrive\\Desktop\\QA\\Screenshot//test1.png"); } @Parameters({ "URL", "Username", "Password"}) @Test(priority=2) public void GoogleLogIn(String urlname, String username, String password) throws InterruptedException, IOException { driver.get(urlname); Thread.sleep(2000); //Verify Sign In driver.findElement(By.xpath("//*[@id=\"gb\"]/div/div[2]/a")).click(); System.out.println("Verify sign in for Google"); //Verify Sign In driver.findElement(By.id("identifierId")).click(); driver.findElement(By.id("identifierId")).clear(); driver.findElement(By.id("identifierId")).sendKeys(username); Thread.sleep(2000); System.out.println("Verify username for Google"); this.takeSnapShot(driver, "C:\\Users\\ahmed\\OneDrive\\Desktop\\QA\\Screenshot//test2.png"); //Click Next Button driver.findElement(By.xpath("//*[@id=\"identifierNext\"]/div/button/span")).click(); Thread.sleep(2000); System.out.println("Verify Next Button"); //Verify Password driver.findElement(By.name("password")).click(); driver.findElement(By.name("password")).clear(); driver.findElement(By.name("password")).sendKeys(password); Thread.sleep(2000); System.out.println("Verify password for Google"); this.takeSnapShot(driver, "C:\\Users\\ahmed\\OneDrive\\Desktop\\QA\\Screenshot//test3.png"); } public static void takeSnapShot(WebDriver webDriver, String fileWithPath) throws IOException { //Convert webdriver Object to Take ScreenShot TakesScreenshot scrShot= ((TakesScreenshot)webDriver); //Call getScreenshot as method to create image file File SrcFile=scrShot.getScreenshotAs(OutputType.FILE); //Move Image file to new Destination File destFile = new File(fileWithPath); //Copy file at destination FileUtils.copyFile(SrcFile, destFile); } @AfterMethod public void close() { driver.close(); } } XML for both <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> <suite name="Automation practice" parallel="tests" thread-count="2"> <listeners> <listener class-name="DellPack.listeners"/> </listeners> <test thread-count="5" name="Innsire"> <parameter name= "url" value= "https://innsire.com/"/> <parameter name= "userName" value= "musaib"/> <parameter name= "password" value= "12345678"/> <classes> <class name="DellPack.firstTest"/> </classes> </test> <!-- Test --> <test thread-count="5" name="Google"> <parameter name= "URL" value= "https://google.com"/> <parameter name= "Username" value= "musaib"/> <parameter name= "Password" value= "12345678"/> <classes> <class name="DellPack.secondTest"/> </classes> </test> <!-- Test --> </suite> <!-- Suite -->
0
0
5
musaib.ahmed.2230
Feb 09, 2022
In Thread Discussions
package DellPack; 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 dellData { WebDriver driver; @BeforeMethod public void setup() { System.setProperty("webdriver.chrome.driver", "C:\\Users\\ahmed\\OneDrive\\Desktop\\Automation\\All jar\\All Jars\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().deleteAllCookies(); driver.manage().window().maximize(); } @Test(dataProvider="getData") public void test(String username, String password) throws InterruptedException { driver.get("https://www.dell.com/en-us"); Thread.sleep(2000); System.out.println("Open chrome browser with dell.com website"); driver.findElement(By.id("um-si-label")).click(); Thread.sleep(2000); System.out.println("Hover over sign in button"); driver.findElement(By.xpath("//a[@class=\"mh-btn mh-btn-primary navigate\"]")).click(); Thread.sleep(2000); System.out.println("Clicked on sign in button"); driver.findElement(By.id("EmailAddress")).sendKeys(username); Thread.sleep(2000); System.out.println("Email is: " + username); driver.findElement(By.id("Password")).sendKeys(password); Thread.sleep(2000); System.out.println("Password is: " + password); driver.findElement(By.id("sign-in-button")).click(); Thread.sleep(2000); System.out.println("Clicked on sign in button"); } @DataProvider public Object[][] getData() { Object[][] data = new Object[2][2]; data[0][0]="musaib.ahmed24@gmail.com"; data[0][1]="123456"; data[1][0]="musaib.ahmed22@gmail.com"; data[1][1]="123456"; return data; } @AfterMethod public void close() { driver.close(); } }
0
0
4

musaib.ahmed.2230

More actions

IT Consulting, Training and Job Placement services