Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created December 29, 2021 11:49
Show Gist options
  • Save muditlambda/ee8d6edefd92d384f19c31fc6c38c3c9 to your computer and use it in GitHub Desktop.
Save muditlambda/ee8d6edefd92d384f19c31fc6c38c3c9 to your computer and use it in GitHub Desktop.
package com.pages;
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.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.TestNG.annotations.*;
import java.util.concurrent.TimeUnit;
public class SimpleTest {
WebDriver driver;
String url = "https://www.lambdatest.com/";
@BeforeTest
public void setup() {
System.out.println("Setting up the drivers");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Shalini\\Downloads\\chromedriver_latest94\\chromedriver.exe");
driver = new ChromeDriver();
}
@Test(dataProvider = "credentials")
public void LoginTest(String username,String password) {
driver.get(url);
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
WebElement login = driver.findElement(By.xpath("//a[text()='Login']"));
login.click();
WebElement name = driver.findElement(By.xpath("//input[@name=\"email\"]"));
WebElement passwd = driver.findElement(By.xpath("//input[@name=\"password\"]"));
WebDriverWait wait = new WebDriverWait(driver,20);
wait.until(ExpectedConditions.visibilityOf(name));
name.clear();
name.sendKeys(username);
passwd.clear();
passwd.sendKeys(password);
WebElement loginButton = driver.findElement(By.xpath("//button[text()='Login']"));
loginButton.click();
System.out.println("Logged in successfully");
}
@DataProvider(name = "credentials")
public Object[][] getUserInput() {
return new Object[][]{
{"abc@gmail.com", "xaxxdssc"},
{"alexdan@gmail.com", "mypasswd"},
{"myemail123@yahoo.com", "textmypass"}
};
}
@AfterTest
public void tearDown(){
driver.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment