Skip to content

Instantly share code, notes, and snippets.

@hatena-iti
Last active August 29, 2015 14:03
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 hatena-iti/756feebea52d0d4d7e20 to your computer and use it in GitHub Desktop.
Save hatena-iti/756feebea52d0d4d7e20 to your computer and use it in GitHub Desktop.
package jp.co.iti.test;
import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.OutputType;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class AndroidChromeTest {
private AppiumDriver driver;
@Before
public void setUp() throws Exception {
// set up appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("browserName", "Chrome");
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void shouldSearchWithEbay() throws InterruptedException {
// And now use this to visit ebay
driver.get("http://m.ebay.de");
// Find the text input element by its id
WebElement element = driver.findElement(By.id("kw"));
// Enter something to search for
element.sendKeys("Nexus 5");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
driver.findElement(By.id("refinetxtId"));
getScreenshotAs("capture_webviewtest.jpg");
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
}
private void getScreenshotAs(String path) {
TakesScreenshot ts = (TakesScreenshot) driver;
try {
FileUtils.copyFile(
ts.getScreenshotAs(OutputType.FILE),
new File(path));
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment