Skip to content

Instantly share code, notes, and snippets.

@hanikhan
Created February 2, 2018 19:00
Show Gist options
  • Save hanikhan/e74c59917ef51b69669b86991481d5f3 to your computer and use it in GitHub Desktop.
Save hanikhan/e74c59917ef51b69669b86991481d5f3 to your computer and use it in GitHub Desktop.
Integrate BrowserStack with Applitools - Java Sample
/*
Add the following dependency to your project OR download and add equivalent jar file to your project
<dependency>
<groupId>com.applitools</groupId>
<artifactId>eyes-selenium-java3</artifactId>
<version>RELEASE</version>
</dependency>
*/
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.applitools.eyes.selenium.Eyes;
import com.applitools.eyes.RectangleSize;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
public class HelloWorld {
public static final String USERNAME = "BrowserStack_Username";
public static final String AUTOMATE_KEY = "BrowserStack_Key";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "63");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
caps.setCapability("browserstack.debug", "true");
caps.setCapability("acceptSslCert",true);
caps.setCapability("resolution","1600x1200");
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
// Initialize the eyes SDK and set your private API key.
Eyes eyes = new Eyes();
eyes.setApiKey("YOUR_APPLITOOLS_API_KEY");
try{
// Start the test and set the browser's viewport size to 800x600.
eyes.open(driver, "Hello World!", "My first Selenium Java test!",
new RectangleSize(800, 600));
// Navigate the browser to the "hello world!" web-site.
driver.get("https://applitools.com/helloworld");
// Visual checkpoint #1.
eyes.checkWindow("Hello!");
// Click the "Click me!" button.
driver.findElement(By.tagName("button")).click();
// Visual checkpoint #2.
eyes.checkWindow("Click!");
// End the test.
eyes.close();
} finally {
// Close the browser.
driver.quit();
// If the test was aborted before eyes.close was called, ends the test as aborted.
eyes.abortIfNotClosed();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment