Skip to content

Instantly share code, notes, and snippets.

@manoj9788
Created November 8, 2017 12:49
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 manoj9788/a8153bd7bfec7a7f72776232944f0444 to your computer and use it in GitHub Desktop.
Save manoj9788/a8153bd7bfec7a7f72776232944f0444 to your computer and use it in GitHub Desktop.
package com.applitools.seleniumJavaExamples;
import com.applitools.eyes.BatchInfo;
import com.applitools.eyes.MatchLevel;
import com.applitools.eyes.RectangleSize;
import com.applitools.eyes.selenium.Eyes;
import com.applitools.eyes.selenium.StitchMode;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import java.net.URL;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
public class DisableImagesSauceApplitools {
private WebDriver driver;
public static BatchInfo batch;
private Eyes eyes = new Eyes();
public static final String APPLITOOLS_KEY = "Your-key";
public static final String USERNAME = "username";
public static final String ACCESS_KEY = "Your-key";
public static final String URL = "https://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:443/wd/hub";
@BeforeSuite
public void before_suite() throws Exception {
HashMap<String, Object> images = new HashMap<String, Object>();
images.put("images", 2);
HashMap<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values", images);
ChromeOptions options= new ChromeOptions();
options.addArguments("--test-type --no-sandbox");
options.addArguments("--enable-strict-powerful-feature-restrictions");
options.setExperimentalOption("prefs", prefs);
DesiredCapabilities caps = DesiredCapabilities.chrome();
caps.setCapability("platform", "macOS 10.12");
caps.setCapability("version", "62.0");
caps.setCapability("screenResolution", "1280x960");
driver = new RemoteWebDriver(new URL(URL), caps);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
}
@AfterSuite
public void after_suite() throws Exception {
driver.quit();
}
@BeforeMethod
public void resetBrowser() {
driver.get("about:blank");
eyes.setForceFullPageScreenshot(true);
eyes.setStitchMode(StitchMode.CSS);
eyes.setMatchLevel(MatchLevel.LAYOUT);
eyes.setBatch(batch);
}
@Test
public void my_first_test() throws InterruptedException {
driver.get("http://assertselenium.com/");
eyes.open(driver, "my-test-no-images", "images0ff", new RectangleSize(1400, 800));
eyes.checkWindow("homepage-with-no-images");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment