app 测试

seldom 3.0 基于appium支持APP测试。

appium 官方网站:https://appium.io/

环境安装

app 的自动化测试环境相比较 web 要复杂一些,请参考appium官方。

  1. 安装node

https://nodejs.org/en/

> node --version
v16.17.0
  1. 安装appium
> npm i --location=global appium  # appium 2.x
  1. 启动appium
> appium server --address '127.0.0.1' -p 4723

[Appium] Welcome to Appium v2.2.2
[Appium] Non-default server args:
[Appium] {
[Appium]   address: '127.0.0.1'
[Appium] }
...
  1. 移动设备

准备一台设备(Android/iOS手机)通过USB数据线连接电脑。通过以下工具确认手机与电脑是否连接。

  • adb
> adb devices 
List of devices attached
UMXDU000000000000       device
  • taobao-iphone-device
> tidevice list
List of apple devices attached
00008030-00000000000000 xxx的iPhoneSE

编写测试

基于seldom编写app自动化测试, 由于appium 继承自selenium,所以,部分API共用。

import seldom
from seldom.appium_lab.android import UiAutomator2Options


class TestBBS(seldom.TestCase):

    def test_bbs_search(self):
        self.click(id_="com.meizu.flyme.flymebbs:id/nw")
        self.type(id_="com.meizu.flyme.flymebbs:id/nw", text="flyme")
        self.click(id_="com.meizu.flyme.flymebbs:id/o1")
        self.sleep(2)
        elems = self.get_elements(id_="com.meizu.flyme.flymebbs:id/a29")
        for title in elems:
            print(title.text)
            self.assertIn("lyme", title.text)


if __name__ == '__main__':
    capabilities = {
        "automationName": "UiAutomator2",
        "platformName": "Android",
        "appPackage": "com.meizu.flyme.flymebbs",
        "appActivity": "com.meizu.myplus.ui.splash.SplashActivity",
        "noReset": True,
    }
    options = UiAutomator2Options().load_capabilities(capabilities)
    seldom.main(app_server="http://127.0.0.1:4723", app_info=options)

注:上面的测试用例隐含了appium的一些知识点,你需要对appium有足够的了解。

  • 运行日志
python test_app.py

              __    __
   ________  / /___/ /___  ____ ____
  / ___/ _ \/ / __  / __ \/ __ ` ___/
 (__  )  __/ / /_/ / /_/ / / / / / /
/____/\___/_/\__,_/\____/_/ /_/ /_/  v3.0.0
-----------------------------------------
                             @itest.info


XTestRunner Running tests...

----------------------------------------------------------------------
2022-10-03 00:01:30 webdriver.py | INFO | 💤️ sleep: 5s.
2022-10-03 00:01:35 webdriver.py | INFO | ✅ Find 1 element: id=com.meizu.flyme.flymebbs:id/nw  -> click.
2022-10-03 00:01:36 webdriver.py | INFO | ✅ Find 1 element: id=com.meizu.flyme.flymebbs:id/nw  -> input 'flyme'.
2022-10-03 00:01:37 webdriver.py | INFO | ✅ Find 1 element: id=com.meizu.flyme.flymebbs:id/o1  -> click.
2022-10-03 00:01:37 webdriver.py | INFO | 💤️ sleep: 2s.
2022-10-03 00:01:39 webdriver.py | INFO | ✅ Find 5 element: id=com.meizu.flyme.flymebbs:id/a29 .
flyme的屏幕色彩显示应该是比较差的

魅族17的Flyme9状态栏下拉问题。

flyme9.3连上耳机来电话还是会外放

flyme自带录屏功能吗?

关于Flyme 8.18.0A稳定版


Generating HTML reports...
.12022-10-03 00:01:40 runner.py | SUCCESS | generated html file: file:///D:\github\seldom\reports\2022_10_03_00_01_23_result.html
2022-10-03 00:01:40 runner.py | SUCCESS | generated log file: file:///D:\github\seldom\reports\seldom_log.log