讲课时有疑问可随时回帖
appium desktop
下载地址: http://shell.testing-studio.com/download/appiumdesktop/
capability: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
雪球app下载: 关于雪球
安装Appium Server
- 先直接安装
- cnpm
- 科学上网
https://testerhome.com/topics/12022
获取app信息
adb logcat | grep -i displayed
客户端
各个语言的客户端: https://github.com/appium/appium/blob/master/docs/en/about-appium/appium-clients.md
java
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>appium.testerhome.com</groupId>
<artifactId>AppiumDemo20180520</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.0.0-BETA5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</project>
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", "xx");
desiredCapabilities.setCapability("appPackage", "com.xueqiu.android");
desiredCapabilities.setCapability("appActivity", ".view.WelcomeActivityAlias");
URL remoteUrl = new URL("http://localhost:4723/wd/hub");
driver = new AndroidDriver(remoteUrl, desiredCapabilities);
}
@Test
public void sampleTest() {
MobileElement el1 = (MobileElement) driver.findElementById("com.xueqiu.android:id/tv_login");
el1.click();
MobileElement el2 = (MobileElement) driver.findElementById("com.xueqiu.android:id/login_account");
el2.sendKeys("15600534760");
MobileElement el3 = (MobileElement) driver.findElementById("com.xueqiu.android:id/login_password");
el3.sendKeys("xueqiu123456");
MobileElement el4 = (MobileElement) driver.findElementById("com.xueqiu.android:id/button_next");
el4.click();
}
@After
public void tearDown() {
driver.quit();
}
}
增加稳定性
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Python
# 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"] = "xx"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
el1 = driver.find_element_by_id("com.xueqiu.android:id/tv_login")
el1.click()
el2 = driver.find_element_by_id("com.xueqiu.android:id/login_account")
el2.send_keys("15600534760")
el3 = driver.find_element_by_id("com.xueqiu.android:id/login_password")
el3.send_keys("xueqiu123456")
el4 = driver.find_element_by_id("com.xueqiu.android:id/button_next")
el4.click()
driver.quit()
作业
- 录制雪球的某个操作流程,比如登陆或者搜索,并把对应的python或者java代码贴到回复里
- 把录制的用例运行起来