npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install -g appium
{
"platformName": "android",
"deviceName": "i love shenzhen",
"appPackage": "com.xueqiu.android",
"appActivity": ".view.WelcomeActivityAlias",
"autoGrantPermissions": "true"
}
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
from appium import webdriver
caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "i love shenzhen"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["autoGrantPermissions"] = "true"
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
el1 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.ImageView")
el1.click()
el2 = driver.find_element_by_id("com.xueqiu.android:id/iv_login_phone")
el2.click()
el3 = driver.find_element_by_id("com.xueqiu.android:id/register_phone_number")
el3.send_keys("15600534700")
el4 = driver.find_element_by_id("com.xueqiu.android:id/register_code")
el4.send_keys("1234")
el5 = driver.find_element_by_id("com.xueqiu.android:id/button_next")
el5.click()
el6 = driver.find_element_by_id("com.xueqiu.android:id/md_content")
el6.click()
el7 = driver.find_element_by_id("com.xueqiu.android:id/md_buttonDefaultPositive")
el7.click()
driver.quit()
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SampleTest {
private AndroidDriver driver;
@Before
public void setUp() throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformName", "android");
desiredCapabilities.setCapability("deviceName", "i love shenzhen");
desiredCapabilities.setCapability("appPackage", "com.xueqiu.android");
desiredCapabilities.setCapability("appActivity", ".view.WelcomeActivityAlias");
desiredCapabilities.setCapability("autoGrantPermissions", "true");
URL remoteUrl = new URL("http://localhost:4723/wd/hub");
driver = new AndroidDriver(remoteUrl, desiredCapabilities);
}
@Test
public void sampleTest() {
MobileElement el1 = (MobileElement) driver.findElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.ImageView");
el1.click();
MobileElement el2 = (MobileElement) driver.findElementById("com.xueqiu.android:id/iv_login_phone");
el2.click();
MobileElement el3 = (MobileElement) driver.findElementById("com.xueqiu.android:id/register_phone_number");
el3.sendKeys("15600534700");
MobileElement el4 = (MobileElement) driver.findElementById("com.xueqiu.android:id/register_code");
el4.sendKeys("1234");
MobileElement el5 = (MobileElement) driver.findElementById("com.xueqiu.android:id/button_next");
el5.click();
MobileElement el6 = (MobileElement) driver.findElementById("com.xueqiu.android:id/md_content");
el6.click();
MobileElement el7 = (MobileElement) driver.findElementById("com.xueqiu.android:id/md_buttonDefaultPositive");
el7.click();
}
@After
public void tearDown() {
driver.quit();
}
}