Skip to content

Instantly share code, notes, and snippets.

@ujwalp1994
Created January 2, 2017 12:41
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/b999faf80cb2b172a2d5e783bc731e2c to your computer and use it in GitHub Desktop.
Save ujwalp1994/b999faf80cb2b172a2d5e783bc731e2c 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.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
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", "Firefox");
caps.setCapability("browser_version", "50.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "10");
/*** FirefoxProfile to bypass the GeoLocation Popu up. ***/
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("geo.prompt.testing", true);
profile.setPreference("geo.prompt.testing.allow", true);
caps.setCapability(FirefoxDriver.PROFILE, profile);
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