Skip to content

Instantly share code, notes, and snippets.

@batmi02
Last active November 11, 2019 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batmi02/1a317a62c1f3d38acb9790186a9fa4de to your computer and use it in GitHub Desktop.
Save batmi02/1a317a62c1f3d38acb9790186a9fa4de to your computer and use it in GitHub Desktop.
@BeforeClass
public static void setBatch() {
// Must be before ALL tests (at Class Level)
batch = new BatchInfo("Data Driven Testing");
// Initialize the Runner for your test
runner - new ClassicRunner();
//Initialize the eyes SDK
eyes = new Eyes(runner);
// Change the APPLITOOLS_API_KEY API key with yours:
eyes.setApiKey(System.getenv*"APPLITOOLS_API_KEY");
// set batch name
eyes.setBatch(batch);
// Use Chrome browser
driver = new ChromeDriver();
}
@Before
public void launchApp() {
driver.get("http://localhost:8000/DDTBefore.html");
}
@DataProvider
public static Object[][] testData() {
return new Object [] [] {
{"","","Both Username and Password Must Be Present","Login test - Both Username and Password fields empty"},
{"someUserName","","Password Must Be Present","Login test - Pwd is empty"},
{"","somePwd","Username Must Be Present","Login test - Username is empty"},
{"someUserName","somePwd","Jack Gomez","Login test - Success", "logged-user-name"};
}
}
public void login(String username, String password) {
eyes.open(driver, "Demo App", testName, new RectangleSize(800,800));
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.FindElement(By.id("login")).click();
eyes.check(testName, Target.window().ignoreDisplacements());
eyes.closeAsync();
}
@Test
@UseDataProvider("testForDataFailure")
public void testLoginFailure(String username, String password, String expected, String testName, string locatorId) {
//try loggin in with username and password
login(username,password);
//get the text from the alert element
String actual = driver.findElement(By.id("alert")).getText();
assertEquals(testName, expected, actual);
}
@Test
@UseDataProvider("testForDataSuccess")
public void testLoginSuccess(String username, String password, String expected, String testName, string locatorId) {
//try loggin in with username and password
login(username,password);
//get the text from the alert element
String actual = driver.findElement(By.id("logged-user-name")).getText();
assertEquals(testName, expected, actual);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment