-
-
Save tourdedave/bff0cc430a2e34770d81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.applitools.eyes.Eyes; | |
import org.junit.*; | |
import org.junit.rules.TestRule; | |
import org.junit.rules.TestWatcher; | |
import org.junit.runner.Description; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.Platform; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import java.net.URL; | |
public class Login { | |
private WebDriver driver; | |
private Eyes eyes; | |
public String testName; | |
public String sessionId; | |
@Rule | |
public TestRule watcher = new TestWatcher() { | |
protected void starting(Description description) { | |
testName = description.getDisplayName(); | |
} | |
@Override | |
protected void failed(Throwable e, Description description) { | |
System.out.println(String.format("https://saucelabs.com/tests/%s", sessionId)); | |
} | |
}; | |
@Before | |
public void setup() throws Exception { | |
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); | |
capabilities.setCapability("platform", Platform.XP); | |
capabilities.setCapability("version", "8"); | |
capabilities.setCapability("name", testName); | |
String sauceUrl = String.format( | |
"http://%s:%s@ondemand.saucelabs.com:80/wd/hub", | |
System.getenv("SAUCE_USERNAME"), | |
System.getenv("SAUCE_ACCESS_KEY")); | |
WebDriver browser = new RemoteWebDriver(new URL(sauceUrl), capabilities); | |
sessionId = ((RemoteWebDriver) browser).getSessionId().toString(); | |
eyes = new Eyes(); | |
eyes.setApiKey(System.getenv("APPLITOOLS_API_KEY")); | |
driver = eyes.open(browser, "the-internet", testName); | |
} | |
@Test | |
public void succeeded() { | |
driver.get("http://the-internet.herokuapp.com/login"); | |
eyes.checkWindow("Login"); | |
driver.findElement(By.id("username")).sendKeys("tomsmith"); | |
driver.findElement(By.id("password")).sendKeys("SuperSecretPassword!"); | |
driver.findElement(By.id("login")).submit(); | |
eyes.checkWindow("Logged In"); | |
Assert.assertTrue("success message should be present after logging in", | |
driver.findElement(By.cssSelector(".flash.success")).isDisplayed()); | |
eyes.close(); | |
} | |
@After | |
public void teardown() { | |
eyes.abortIfNotClosed(); | |
driver.quit(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.elementalselenium.tips</groupId> | |
<artifactId>sauce-eyes-example</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>com.applitools</groupId> | |
<artifactId>eyes-selenium-java</artifactId> | |
<version>RELEASE</version> | |
</dependency> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.12</version> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment