Skip to content

Instantly share code, notes, and snippets.

@ckzgraphics
Created September 5, 2019 19:19
Show Gist options
  • Save ckzgraphics/ab6cb106d10d9b224aee57e8fea95499 to your computer and use it in GitHub Desktop.
Save ckzgraphics/ab6cb106d10d9b224aee57e8fea95499 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.net.URL;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.html5.Location;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
public class GPS_Location_Android {
public static void main(String[] args) {
String USERNAME = System.getenv("BROWSERSTACK_USERNAME");
String AUTOMATE_KEY = System.getenv("BROWSERSTACK_ACCESS_KEY");
String HUB_URL = "http://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
AppiumDriver<WebElement> webDriver = null;
URL URLObj = null;
DesiredCapabilities caps = null;
try {
URLObj = new URL(HUB_URL);
caps = new DesiredCapabilities(); // https://www.browserstack.com/app-automate/capabilities
caps.setCapability("project", "Test Run");
caps.setCapability("build", "Build v1");
caps.setCapability("name", "Test: GPS Location");
caps.setCapability("device", "Google Nexus 6");
caps.setCapability("app","<HASHED_ID>"); // https://www.browserstack.com/app-automate/rest-api#app-upload
caps.setCapability("browserstack.debug", "true");
caps.setCapability("browserstack.video", "true");
// caps.setCapability("browserstack.gpsLocation", "55.7522200,37.6155600");
// caps.setCapability("browserstack.appium_version", "1.14.0");
webDriver = new AppiumDriver(URLObj, caps);
Thread.sleep(2000);
take_screenshot(webDriver);
// NEW YORK - https://www.latlong.net/place/new-york-city-ny-usa-1848.html
Location location = new Location(40.730610, -73.935242, 0);
webDriver.setLocation(location);
Thread.sleep(2000);
webDriver.closeApp();
webDriver.launchApp();
Thread.sleep(2000);
take_screenshot(webDriver);
// BALI - https://www.latlong.net/place/bali-indonesia-3445.html
location = new Location(-8.409518, 115.188919, 0);
webDriver.setLocation(location);
Thread.sleep(2000);
webDriver.closeApp();
webDriver.launchApp();
Thread.sleep(3000);
take_screenshot(webDriver);
} catch (Exception e) {
e.printStackTrace();
} finally {
if(webDriver != null){
webDriver.quit();
}
}
}
public static void take_screenshot(WebDriver webDriver){
try {
TakesScreenshot scrShot =((TakesScreenshot)webDriver);
File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
} 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