Skip to content

Instantly share code, notes, and snippets.

@tourdedave

tourdedave/Login.java Secret

Last active Aug 29, 2015
Embed
What would you like to do?
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();
}
}
<?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