Skip to content

Instantly share code, notes, and snippets.

@hanikhan
Last active August 7, 2018 16:17
Show Gist options
  • Save hanikhan/88d4a0711ef5821128c5d098a2a6d3ff to your computer and use it in GitHub Desktop.
Save hanikhan/88d4a0711ef5821128c5d098a2a6d3ff to your computer and use it in GitHub Desktop.
NativeWebTap on real iOS devices - Sample on BrowserStack
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class nativeTapSample {
public static final String USERNAME = "<BrowserStack_Username>";
public static final String AUTOMATE_KEY = "<BrowserStack_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();
caps.setCapability("device", "iPhone 8");
caps.setCapability("realMobile", true);
caps.setCapability("nativeWebTap",true);
WebDriver driver = new RemoteWebDriver(new URL("https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub"), caps);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://www.browserstack.com/docs?product=automate");
driver.getCurrentUrl();
driver.getWindowHandles();
driver.findElement(By.xpath("//h4[text()='Languages and Frameworks']/parent::div/following-sibling::div/div//h3/a[text()='Java']")).click();
driver.getCurrentUrl();
driver.getWindowHandles();
Thread.sleep(5000);
driver.quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment