活动沙龙 app 自动化测试 workshop-深圳站-20191020

思寒_seveniruby for 霍格沃兹测试学院外部交流圈 · October 20, 2019 · Last by 思寒_seveniruby replied at October 21, 2019 · 1336 hits

参考资料

安装appium

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"
}

录制代码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"] = "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()

录制代码Java

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();
}
}

测试用例改造

  • unittest
  • pytest

Page Object改造

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 4 条回复 时间 点赞

华为荣耀8,android8.0.0,自动获取权限为true,appium跑自动化仍有权限弹框

panzer945 回复

小米一样有这个问题的。
说好像国内的rom应该都是这样,应该是被系统拦截了。

小啄 回复

好的 等我到家就更新哈,刚回北京,昨晚忘记更新了。因为时间关系数据驱动没来得及,下次公开课给大家讲。

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up