|
| 1 | +package com.lambdatest; |
| 2 | + |
| 3 | +import org.openqa.selenium.By; |
| 4 | +import org.openqa.selenium.remote.DesiredCapabilities; |
| 5 | +import org.openqa.selenium.remote.RemoteWebDriver; |
| 6 | +import org.openqa.selenium.support.ui.ExpectedConditions; |
| 7 | +import org.openqa.selenium.support.ui.WebDriverWait; |
| 8 | +import org.testng.Assert; |
| 9 | +import org.testng.ITestContext; |
| 10 | +import org.testng.annotations.AfterMethod; |
| 11 | +import org.testng.annotations.BeforeMethod; |
| 12 | +import org.testng.annotations.Test; |
| 13 | + |
| 14 | +import java.lang.reflect.Method; |
| 15 | +import java.net.MalformedURLException; |
| 16 | +import java.net.URL; |
| 17 | + |
| 18 | +public class SampleAutomation { |
| 19 | + |
| 20 | + private RemoteWebDriver driver; |
| 21 | + private String Status = "failed"; |
| 22 | + |
| 23 | + @BeforeMethod |
| 24 | + public void setup(Method m, ITestContext ctx) throws MalformedURLException { |
| 25 | +// String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME"); |
| 26 | + String username = System.getProperty("LT_USERNAME"); |
| 27 | +// String authKey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY"); |
| 28 | + String authKey = System.getProperty("LT_ACCESS_KEY"); |
| 29 | + |
| 30 | + String hub = "@hub.lambdatest.com/wd/hub"; |
| 31 | + |
| 32 | + DesiredCapabilities caps = new DesiredCapabilities(); |
| 33 | + caps.setCapability("platform", "win10"); |
| 34 | + caps.setCapability("browserName", "chrome"); |
| 35 | + caps.setCapability("version", "latest"); |
| 36 | + caps.setCapability("build", "TestNG With Java"); |
| 37 | + caps.setCapability("name", m.getName() + " - " + this.getClass().getName()); |
| 38 | + caps.setCapability("plugin", "git-testng"); |
| 39 | + |
| 40 | + String[] Tags = new String[] { "Feature", "Falcon", "Severe" }; |
| 41 | + caps.setCapability("tags", Tags); |
| 42 | + |
| 43 | + driver = new RemoteWebDriver(new URL("https://" + username + ":" + authKey + hub), caps); |
| 44 | + |
| 45 | + } |
| 46 | + public void wait(By locator, int waitTime) { |
| 47 | + WebDriverWait wait = new WebDriverWait(driver, waitTime); |
| 48 | + wait.until(ExpectedConditions.presenceOfElementLocated(locator)); |
| 49 | + } |
| 50 | + |
| 51 | + @Test(priority = 1) |
| 52 | + public void register() { |
| 53 | + driver.get("https://ecommerce-playground.lambdatest.io/"); |
| 54 | + driver.findElement(By.cssSelector("#main-navigation a[href*='account/account']")).click(); |
| 55 | + driver.findElement(By.cssSelector("#column-right a[href*='account/register']")).click(); |
| 56 | + wait(By.id("input-firstname"), 30); |
| 57 | + driver.findElement(By.id("input-firstname")).sendKeys("name"); |
| 58 | + driver.findElement(By.id("input-lastname")).sendKeys("LastName"); |
| 59 | + driver.findElement(By.id("input-email")).sendKeys("Email"); |
| 60 | + driver.findElement(By.id("input-telephone")).sendKeys("Number"); |
| 61 | + driver.findElement(By.id("input-password")).sendKeys("Password"); |
| 62 | + driver.findElement(By.id("input-confirm")).sendKeys("Confirm password"); |
| 63 | +// driver.findElement(By.id("input-agree")).click(); |
| 64 | + driver.findElement(By.cssSelector("input[type='submit']")).click(); |
| 65 | + System.out.println("TestFinished"); |
| 66 | + } |
| 67 | + |
| 68 | +// @Test(priority = 2) |
| 69 | + public void searchProduct() { |
| 70 | + driver.findElement(By.cssSelector("#main-header [placeholder='Search For Products']")).sendKeys("i pod Nano"); |
| 71 | + driver.findElement(By.cssSelector("#search .dropdown ul>li:first-of-type")).click(); |
| 72 | + driver.findElement(By.cssSelector(".order-1 .btn-cart")).click(); |
| 73 | + } |
| 74 | + |
| 75 | + @AfterMethod |
| 76 | + public void tearDown() { |
| 77 | + driver.executeScript("lambda-status=" + Status); |
| 78 | + driver.quit(); |
| 79 | + } |
| 80 | +} |
0 commit comments