Skip to content

Instantly share code, notes, and snippets.

@ujwalp1994
Created January 2, 2017 12:33
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 ujwalp1994/c64eb2baadd562dc472d9d1d6306c6e0 to your computer and use it in GitHub Desktop.
Save ujwalp1994/c64eb2baadd562dc472d9d1d6306c6e0 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class GeoPopUpChrome {
/*** Add your credentials here ***/
public static final String USERNAME = "<username>";
public static final String AUTOMATE_KEY = "<access_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();
/*** Add OS /Browser capabilities ***/
caps.setCapability("browserName", "Chrome");
caps.setCapability("browser_version", "55.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
/*** ChromeOptions to bypass the GeoLocation Popu up. ***/
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
Map<String, Object> profile = new HashMap<String, Object>();
Map<String, Object> contentSettings = new HashMap<String, Object>();
contentSettings.put("geolocation", 1);
profile.put("managed_default_content_settings", contentSettings);
prefs.put("profile", profile);
options.setExperimentalOption("prefs", prefs);
options.addArguments("--disable-plugins");
options.addArguments("--start-maximized");
caps.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
/*** Accessing a URL which throws the popup ***/
driver.get("https://pargopickuppoints.appspot.com/");
Thread.sleep(2000);
driver = (RemoteWebDriver) new Augmenter().augment(driver);
File srcFile = (File) ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File("/Your-path/check.png"));
System.out.println(driver.getTitle());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment