Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ckzgraphics/6514a74fe5c83feb5c54982541ea67ff to your computer and use it in GitHub Desktop.
Save ckzgraphics/6514a74fe5c83feb5c54982541ea67ff to your computer and use it in GitHub Desktop.
package com.bs.test;
import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ChromeOptions_Flags {
public static void main(String[] args) {
String USERNAME = System.getenv("BROWSERSTACK_USERNAME");
String AUTOMATE_KEY = System.getenv("BROWSERSTACK_ACCESS_KEY");
String HUB_URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
JavascriptExecutor js = null;
WebDriver webDriver = null;
ChromeOptions options = null;
Map<String, Object> prefs = null;
Keys keys = null;
WebElement ele = null;
WebDriverWait wait = null;
Actions act = null;
String AUT_URL = "http://camendesign.com/code/video_for_everybody/test.html";
URL URLObj = null;
DesiredCapabilities caps = null;
try {
URLObj = new URL(HUB_URL);
options = new ChromeOptions();
options.addArguments("autoplay-policy=no-user-gesture-required");
caps = new DesiredCapabilities();
caps.setCapability(ChromeOptions.CAPABILITY, options);
caps.setCapability("project", "Test Run");
caps.setCapability("build", "Build v1");
caps.setCapability("name", "Test: Chrome Options [autoplay-policy=no-user-gesture-required]");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "73");
caps.setCapability("browserstack.console", "verbose");
webDriver = new RemoteWebDriver(URLObj, caps);
webDriver.get(AUT_URL);
System.out.println("TITLE :: " + webDriver.getTitle());
Thread.sleep(5000);
take_screenshot(webDriver);
} catch (Exception e) {
e.printStackTrace();
} finally {
if(webDriver != null){
webDriver.quit();
}
}
} // MAIN END
public static void take_screenshot(WebDriver webDriver){
try {
TakesScreenshot scrShot =((TakesScreenshot)webDriver);
File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
// File DestFile=new File("/Users/test.png");
// FileUtils.copyFile(SrcFile, DestFile);
} catch (Exception e) {
e.printStackTrace();
}
} // FUNC END
} // CLASS END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment