Skip to content

Instantly share code, notes, and snippets.

@andreidbr
Created March 13, 2018 19:36
Show Gist options
  • Save andreidbr/0688f441b777708451caddd703d99afa to your computer and use it in GitHub Desktop.
Save andreidbr/0688f441b777708451caddd703d99afa to your computer and use it in GitHub Desktop.
A Java class with basic Selenium tests organized with TestNG
package PortfolioTests;
import PortfolioTests.Utilities.Utils;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static PortfolioTests.Utilities.Utils.driver;
public class Portfolio {
@BeforeMethod
public void setUp() {
Utils.instantiate();
}
@AfterMethod
public void tearDown() {
driver.close();
}
@Test(testName = "Access Positive Test", description = "Check that you can access the 01 Drums page", groups = {"01Drums"})
public void accessDrumsPositiveTest() {
driver.findElement(By.xpath("/html/body/div[2]/div[1]")).click();
Assert.assertEquals(driver.getTitle(), "JS30: 01 Drums");
}
@Test(testName = "Access Negative Test", description = "Check that you can access the correct 01Drums page", groups = {"01Drums"})
public void accessDrumsNegativeTest() {
driver.findElement(By.xpath("/html/body/div[2]/div[1]")).click();
Assert.assertNotEquals(driver.getTitle(), "Lorem Ipsum");
}
@Test(testName = "Back from Drums Test", description = "Check that you can go back from the 01 Drums page", groups = {"01Drums"})
public void backFromDrumsTest() {
driver.findElement(By.xpath("/html/body/div[2]/div[1]")).click();
driver.navigate().back();
Assert.assertEquals(driver.getTitle(), "JavaScript 30 Portfolio by Andrei Dobra");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment