mirror of
https://github.com/appium/appium.git
synced 2026-02-06 17:48:56 -06:00
TestNG and Junit tests for Android.These tests are similar to the one available in the sample-code/examples/python
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package com.saucelabs.appium;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.remote.CapabilityType;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.remote.RemoteTouchScreen;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
public class AndroidContactsTest {
|
||||
private WebDriver driver;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// set up appium
|
||||
File classpathRoot = new File(System.getProperty("user.dir"));
|
||||
File appDir = new File(classpathRoot, "../../../apps/ContactManager");
|
||||
File app = new File(appDir, "ContactManager.apk");
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.setCapability("device","Android");
|
||||
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "4.2");
|
||||
capabilities.setCapability(CapabilityType.PLATFORM, "MAC");
|
||||
capabilities.setCapability("app", app.getAbsolutePath());
|
||||
capabilities.setCapability("app-package", "com.example.android.contactmanager");
|
||||
capabilities.setCapability("app-activity", ".ContactManager");
|
||||
driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
driver.quit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addContact(){
|
||||
WebElement el = driver.findElement(By.name("Add Contact"));
|
||||
el.click();
|
||||
List<WebElement> textFieldsList = driver.findElements(By.tagName("textfield"));
|
||||
textFieldsList.get(0).sendKeys("Some Name");
|
||||
textFieldsList.get(2).sendKeys("Some@example.com");
|
||||
driver.findElement(By.name("Save")).click();
|
||||
}
|
||||
|
||||
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
|
||||
private RemoteTouchScreen touch;
|
||||
|
||||
public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
|
||||
super(remoteAddress, desiredCapabilities);
|
||||
touch = new RemoteTouchScreen(getExecuteMethod());
|
||||
}
|
||||
|
||||
public TouchScreen getTouch() {
|
||||
return touch;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.saucelabs.appium;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.remote.CapabilityType;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.remote.RemoteTouchScreen;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class AndroidTest {
|
||||
|
||||
private WebDriver driver;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
File classpathRoot = new File(System.getProperty("user.dir"));
|
||||
File appDir = new File(classpathRoot, "../../../apps/ApiDemos/bin");
|
||||
File app = new File(appDir, "ApiDemos-debug.apk");
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.setCapability("device","Android");
|
||||
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
|
||||
capabilities.setCapability(CapabilityType.VERSION, "4.2");
|
||||
capabilities.setCapability(CapabilityType.PLATFORM, "MAC");
|
||||
capabilities.setCapability("app", app.getAbsolutePath());
|
||||
capabilities.setCapability("app-package", "com.example.android.apis");
|
||||
capabilities.setCapability("app-activity", ".ApiDemos");
|
||||
driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
driver.quit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void apiDemo(){
|
||||
WebElement el = driver.findElement(By.name("Animation"));
|
||||
assertEquals(el.getText(), "Animation");
|
||||
el = driver.findElement(By.tagName("text"));
|
||||
assertEquals(el.getText(), "API Demos");
|
||||
el = driver.findElement(By.name("App"));
|
||||
el.click();
|
||||
List<WebElement> els = driver.findElements(By.tagName("text"));
|
||||
assertEquals(els.get(2).getText(), "Activity");
|
||||
}
|
||||
|
||||
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
|
||||
private RemoteTouchScreen touch;
|
||||
|
||||
public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
|
||||
super(remoteAddress, desiredCapabilities);
|
||||
touch = new RemoteTouchScreen(getExecuteMethod());
|
||||
}
|
||||
|
||||
public TouchScreen getTouch() {
|
||||
return touch;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.saucelabs.appium;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
import org.openqa.selenium.remote.RemoteTouchScreen;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
public class AndroidWebViewTest {
|
||||
private WebDriver driver;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// set up appium
|
||||
File classpathRoot = new File(System.getProperty("user.dir"));
|
||||
File appDir = new File(classpathRoot, "../../../apps/WebViewDemo/target");
|
||||
String file = getApkFile(appDir);
|
||||
File app = new File(appDir, file);
|
||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||
capabilities.setCapability("device","selendroid");
|
||||
capabilities.setCapability("app", app.getAbsolutePath());
|
||||
capabilities.setCapability("app-package", "io.selendroid.testapp");
|
||||
capabilities.setCapability("app-activity", ".HomeScreenActivity");
|
||||
driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
|
||||
}
|
||||
private String getApkFile(File appDir) {
|
||||
|
||||
for(String s : appDir.list())
|
||||
if(s.contains(".apk")){
|
||||
return s;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
driver.quit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webView(){
|
||||
WebElement button = driver.findElement(By.id("buttonStartWebview"));
|
||||
button.click();
|
||||
driver.switchTo().window("WEBVIEW");
|
||||
WebElement inputField = driver.findElement(By.id("name_input"));
|
||||
inputField.sendKeys("Some name");
|
||||
inputField.submit();
|
||||
}
|
||||
|
||||
|
||||
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
|
||||
private RemoteTouchScreen touch;
|
||||
|
||||
public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
|
||||
super(remoteAddress, desiredCapabilities);
|
||||
touch = new RemoteTouchScreen(getExecuteMethod());
|
||||
}
|
||||
|
||||
public TouchScreen getTouch() {
|
||||
return touch;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user