测试人社区

app自动化测试训练营第二课

参考链接

启动配置

{
  "platformName": "android",
  "deviceName": "seveniruby",
  "appPackage": "com.xueqiu.android",
  "appActivity": ".view.WelcomeActivityAlias",
  "unicodeKeyboard": "true",
  "resetKeyboard": "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"] = "seveniruby"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)

el1 = driver.find_element_by_id("com.xueqiu.android:id/tv_agree")
el1.click()
el2 = driver.find_element_by_id("com.xueqiu.android:id/home_search")
el2.click()
el3 = driver.find_element_by_id("com.xueqiu.android:id/search_input_text")
el3.send_keys("alibaba")

driver.quit()

pytest改造

# 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


class TestDemo:
    def setup(self):
        caps = {}
        caps["platformName"] = "android"
        caps["deviceName"] = "seveniruby"
        caps["appPackage"] = "com.xueqiu.android"
        caps["appActivity"] = ".view.WelcomeActivityAlias"

        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
        self.driver.implicitly_wait(30)

    def test_search(self):
        el1 = self.driver.find_element_by_id("com.xueqiu.android:id/tv_agree")
        el1.click()
        el2 = self.driver.find_element_by_id("com.xueqiu.android:id/home_search")
        el2.click()
        el3 = self.driver.find_element_by_id("com.xueqiu.android:id/search_input_text")
        el3.send_keys("alibaba")
    def teardown(self):
        self.driver.quit()





UI自动化有什么框架支持mock么,或者有什么mock库比较好用,UI做自动化感觉好多场景需要mock才方便,但是单接口直接mock到本地的话,不能很好支持自动化

在mumu自带的应用商店下载的雪球app,在启动脚本的时候Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES],网上查了下这个错误了好像是包的问题···

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: pkg: /data/local/tmp/appium_cache/8d4156e508daae39c3f4815552e22e311432ff1f.apk
Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]

思寒老师,我们公司产品的接口是会先发一个url相同option请求,再发一个普通请求。用map local修改响应结果时,修改了option请求导致后面的普通请求报错。这个问题我在百度上查了怎么解决,但是现在还没有头绪,有老师能一下怎么解决吗

思寒老师 请问Linux部署使用selenium grid 整合appium进行多机测试时,环境是不是也需要SDK配置?

case执行机器是不需要的。但是appium启动的节点是需要的。appium会调用adb

  1. 增加过滤掉件,区分request method
  2. 如果charles做不到,需要你定制自己的代理服务器。我们的大课里会讲如何定制自己的代理服务器实现这种需求
  3. 还有一个山寨的办法,两次请求之间,对文件的内容做修改。利用map remote,自己做个小的cgi服务,判断下第一次访问不修改,第二次访问修改即可。
1 Like

我mumu模拟器是可以安装的,你确定是从腾讯应用宝上下载的嘛?

确定,应用宝商店下载的,你帖子里的链接,我用adb install可以安装

charles是一个手工mock的好工具,要想个称心如意的mock工具,还是需要自己定制的。我们大课里会讲这个知识点

但是appium的脚本,包括在inspect那个session里都起不来

贴下代码看看,可能你是capability有问题,你的appium版本是多少

image

image

``python
from appium import webdriver

desired_caps = {}
desired_caps[‘platformName’] = ‘Android’
desired_caps[‘platformVersion’] = ‘6.0’
desired_caps[‘deviceName’] = ‘emulator-5554’
desired_caps[‘appPackage’] = ‘com.xueqiu.android’
desired_caps[‘appActivity’] = ‘com.xueqiu.android.common.MainActivity’
driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
driver.quit()
``
adb install可以正常安装,但是appium不行,包括录制脚本那边start session都启动不了,一样的报错
image

你的appActivity写的有问题哈

多谢思寒老师,问题解决了。我用rewrite处理option请求的响应头就可以map local了。我试试老师说的其他办法,后面可以整理个文档发到论坛上

那个我发现了,那个改了也没用,在server端log显示appium-uiautomator2-server-debug-androidTest.apk被重定向为8d4156e508daae39c3f4815552e22e311432ff1f.apk,最终adb命令里面是这个包报的[INSTALL_PARSE_FAILED_NO_CERTIFICATES]

[ADB] The application at '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk' is already cached to '/data/local/tmp/appium_cache/8d4156e508daae39c3f4815552e22e311432ff1f.apk'
[ADB] Running '/Users/chenling/Downloads/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell touch -am /data/local/tmp/appium_cache/8d4156e508daae39c3f4815552e22e311432ff1f.apk'
[ADB] Running '/Users/chenling/Downloads/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm install -r /data/local/tmp/appium_cache/8d4156e508daae39c3f4815552e22e311432ff1f.apk'
[ADB] The installation of 'appium-uiautomator2-server-debug-androidTest.apk' took 883ms
[ADB] Install command stdout: pkg: /data/local/tmp/appium_cache/8d4156e508daae39c3f4815552e22e311432ff1f.apk
[ADB] Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]

期待你的总结文档~这个问题我也遇到过 :face_with_hand_over_mouth:

我也遇到了这个问题,换了个Appium Desktop1.8的版本就解决了