Skip to content

Instantly share code, notes, and snippets.

@pr4bh4sh
Last active June 25, 2016 11:52
Show Gist options
  • Save pr4bh4sh/d1274e0efac73e176b7b to your computer and use it in GitHub Desktop.
Save pr4bh4sh/d1274e0efac73e176b7b to your computer and use it in GitHub Desktop.
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileBrowserType;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
public class SafariTest
{
AppiumDriver<WebElement> driver;
@BeforeClass
public void setUp() throws MalformedURLException
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.SAFARI);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 5s");
capabilities.setCapability("udid", UDID);
driver = new IOSDriver<WebElement>(new URL("http://localhost:4723/wd/hub"), capabilities);
}
@AfterClass
public void tearDown()
{
driver.quit();
}
@Test
public void test() throws InterruptedException
{
System.out.println("in test");
Thread.sleep(10000);// give time to load the webview
System.out.println("wait finished");
for (String context : driver.getContextHandles())
{
System.out.println(context);
if (context.toLowerCase().contains("web"))
driver.context(context);
}
System.out.println("context finished");
driver.get("http://google.com");
driver.findElement(By.name("q")).sendKeys("hello\n");
Thread.sleep(5000);
}
}
@email2vimalraj
Copy link

Add the .java extension to the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment