Appium 多个 py 文件,放在一个脚本中执行,使用 TestSuite,怎样才能只执行一次 setUp ( 已经使用了 @classmethod ) ?

tancaidexiaoming · 2020年08月12日 · 最后由 hhhuskar 回复于 2020年08月12日 · 687 次阅读

有 3 个 py 文件,FooTest_Case1.py,FooTest_Case2.py,FooTest_Case3.py。新建了一个 FooTest_AllCase.py,将前面的三个文件使用 TestSuite 放在这里面。在 FooTest_AllCase.py 中,setUp 和 tearDown 均加了装饰器 @classmethod。我的预期是在执行所有 case 之前只执行一次 setUp,所有 case 结束后现在有两个问题:

  1. 实际执行中,在每条用例完成之后会执行 tearDown,下条用例执行之前都会执行 setUp,和预期不符;
  2. 最后一条用例结束后没有执行 tearDown,但是脚本还是正常的结束了

这两点希望有人可以帮忙解答,谢谢

代码很简单,如下所示:
FooTest_Case1.py:

from appium import webdriver
import unittest
import time, os
from selenium.webdriver.support.ui import WebDriverWait

class FooTest_Case_1(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        os.system("adb shell input keyevent 26")
        os.system("adb shell input keyevent 3")

        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '9'   #Pixel 2
        desired_caps['deviceName'] = 'FA7971A04040'    #Pixel 2
        desired_caps['appPackage'] = 'com.android.settings'
        desired_caps['appActivity'] = 'com.android.settings.Settings'
        desired_caps['newCommandTimeout'] = '3000'

        cls.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    # test_case_1: 检查飞行模式是否开启
    def test_case_1(self):
        self.driver.find_element_by_name("网络和互联网").click()
        textFly = self.driver.find_element_by_id("android:id/switch_widget").get_attribute("text")
        if textFly == "开启":
            print("飞行模式已开启")
        elif textFly == "关闭":
            print("飞行模式已关闭")
        print("test_case_1 --------------------")
        time.sleep(3)
        os.system('adb shell input keyevent 4')

    @classmethod
    def tearDownClass(cls):
        cls.driver.keyevent(26)   
        cls.driver.quit()

if __name__ == '__main__':
    unittest.main()

FooTest_Case2.py:

from appium import webdriver
import unittest
import time, os
from selenium.webdriver.support.ui import WebDriverWait

class FooTest_Case_2(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        os.system("adb shell input keyevent 26")
        os.system("adb shell input keyevent 3")

        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '9'   #Pixel 2
        desired_caps['deviceName'] = 'FA7971A04040'    #Pixel 2
        desired_caps['appPackage'] = 'com.android.settings'
        desired_caps['appActivity'] = 'com.android.settings.Settings'
        desired_caps['newCommandTimeout'] = '3000'

        cls.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    # test_case_2: 检查蓝牙是否开启
    def test_case_2(self):
        self.driver.find_element_by_name("已连接的设备").click()
        self.driver.find_element_by_android_uiautomator('new UiSelector().text("连接偏好设置")').click()
        self.driver.find_element_by_name("蓝牙").click()
        bt = self.driver.find_element_by_id("com.android.settings:id/switch_widget").get_attribute('checked')
        if bt == 'true':
            print("蓝牙已开启")
        elif bt == 'false':
            print("蓝牙已关闭")
        print("test_case_2 ....................")
        time.sleep(3)
        os.system('adb shell input keyevent 4')
        os.system('adb shell input keyevent 4')
        os.system('adb shell input keyevent 4')

if __name__ == '__main__':
    unittest.main()

FooTest_Case3.py:

from appium import webdriver
import unittest
import time, os
from selenium.webdriver.support.ui import WebDriverWait

class FooTest_Case_3(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        os.system("adb shell input keyevent 26")
        os.system("adb shell input keyevent 3")

        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '9'   #Pixel 2
        desired_caps['deviceName'] = 'FA7971A04040'    #Pixel 2
        desired_caps['appPackage'] = 'com.android.settings'
        desired_caps['appActivity'] = 'com.android.settings.Settings'
        desired_caps['newCommandTimeout'] = '3000'

        cls.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    # test_case_3: 检查wifi是否开启
    def test_case_3(self):
        self.driver.find_element_by_name("网络和互联网").click()
        self.driver.find_element_by_android_uiautomator('new UiSelector().text("WLAN")').click()
        wifi = self.driver.find_element_by_id("com.android.settings:id/switch_widget").get_attribute('checked')
        if wifi == 'true':
            print('WiFi 已开启')
        else:
            print('WiFi 已关闭')
        print("test_case_3 ********************")
        time.sleep(3)
        os.system('adb shell input keyevent 4 && adb shell input keyevent 4')

    @classmethod
    def tearDownClass(cls):
        cls.driver.keyevent(26)   #作用等同于上句调用adb,灭屏
        cls.driver.quit()


if __name__ == '__main__':
    unittest.main()

FooTest_AllCase.py

from appium import webdriver
import unittest
import time, os
from selenium.webdriver.support.ui import WebDriverWait

from FooTest_Case1 import FooTest_Case_1   
from FooTest_Case2 import FooTest_Case_2
from FooTest_Case3 import FooTest_Case_3

class FooTest_All_Case(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        os.system("adb shell input keyevent 26")
        os.system("adb shell input keyevent 3")

        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '9'   #Pixel 2
        desired_caps['deviceName'] = 'FA7971A04040'    #Pixel 2
        desired_caps['appPackage'] = 'com.android.settings'
        desired_caps['appActivity'] = 'com.android.settings.Settings'
        desired_caps['newCommandTimeout'] = '3000'
        cls.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    @classmethod
    def tearDownClass(cls):
        cls.driver.keyevent(26)   
        cls.driver.quit()

if __name__ == '__main__':
    #unittest.main()
    suite = unittest.TestSuite()
    suite.addTest(FooTest_Case_3("test_case_3"))     
    suite.addTest(FooTest_Case_1("test_case_1"))
    suite.addTest(FooTest_Case_2("test_case_2"))
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(suite)

Appium Log:

[BaseDriver] Event 'quitSessionFinished' logged at 1597195765635 (09:29:25 GMT+0800 (中国标准时间))
[W3C (8090ade4)] Received response: null
[W3C (8090ade4)] But deleting session, so not returning
[W3C (8090ade4)] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/8090ade4-8bc5-4bd3-9987-5742cc4ca7f7 200 1989 ms - 14
[HTTP] 
[HTTP] --> POST /wd/hub/session
[HTTP] {"capabilities":{"firstMatch":[{"platformName":"Android","appium:platformVersion":"9","appium:deviceName":"FA7971A04040","appium:appPackage":"com.android.settings","appium:appActivity":"com.android.settings.Settings","appium:newCommandTimeout":"3000"}]},"desiredCapabilities":{"platformName":"Android","platformVersion":"9","deviceName":"FA7971A04040","appPackage":"com.android.settings","appActivity":"com.android.settings.Settings","newCommandTimeout":"3000"}}
[W3C] Calling AppiumDriver.createSession() with args: [{"platformName":"Android","platformVersion":"9","deviceName":"FA7971A04040","appPackage":"com.android.settings","appActivity":"com.android.settings.Settings","newCommandTimeout":"3000"},null,{"firstMatch":[{"platformName":"Android","appium:platformVersion":"9","appium:deviceName":"FA7971A04040","appium:appPackage":"com.android.settings","appium:appActivity":"com.android.settings.Settings","appium:newCommandTimeout":"3000"}]}]
[BaseDriver] Event 'newSessionRequested' logged at 1597195768048 (09:29:28 GMT+0800 (中国标准时间))
[BaseDriver] Number capability passed in as string. Functionality may be compromised.
[Appium] 
[Appium] ======================================================================
[Appium]   DEPRECATION WARNING:
[Appium] 
[Appium]   The 'automationName' capability was not provided in the desired 
[Appium]   capabilities for this Android session
[Appium] 
[Appium]   Setting 'automationName=UiAutomator1' by default and using the 
[Appium]   UiAutomator1 Driver
[Appium] 
[Appium]   The next minor version of Appium (1.14.x) will set 
[Appium]   'automationName=UiAutomator2' by default and use the UiAutomator2 
[Appium]   Driver
[Appium] 
[Appium]   The next major version of Appium (2.x) will **require** the 
[Appium]   'automationName' capability to be set for all sessions on all 
[Appium]   platforms
[Appium] 
[Appium]   If you are happy with 'UiAutomator1' and do not wish to upgrade 
[Appium]   Android drivers, please add 'automationName=UiAutomator1' to your 
[Appium]   desired capabilities
[Appium] 
[Appium]   For more information about drivers, please visit 
[Appium]   http://appium.io/docs/en/about-appium/intro/ and explore the 
[Appium]   'Drivers' menu
[Appium] 
[Appium] ======================================================================
[Appium] 
[Appium] Setting automation to 'UiAutomator1'. 
[Appium] Consider setting 'automationName' capability to 'UiAutomator2' on Android >= 6, since UIAutomator1 framework is not maintained anymore by the OS vendor.
[Appium] Appium v1.13.0 creating new AndroidDriver (v4.15.1) session
[Appium] Capabilities:
[Appium]   platformName: Android
[Appium]   platformVersion: 9
[Appium]   deviceName: FA7971A04040
[Appium]   appPackage: com.android.settings
[Appium]   appActivity: com.android.settings.Settings
[Appium]   newCommandTimeout: 3000
[BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities {"platformName":"Android","... were provided
[BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa...
[BaseDriver] Number capability passed in as string. Functionality may be compromised.
[BaseDriver] Capability 'newCommandTimeout' changed from string ('3000') to integer (3000). This may cause unexpected behavior
[BaseDriver] Session created with session id: 17effdf8-266d-4239-9edc-a5372dd5ad6b
[ADB] Using 'adb.exe' from 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe'
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[AndroidDriver] Looking for a device with Android '9'
[ADB] Setting device id to FA7971A04040
[ADB] Getting device platform version
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell getprop ro.build.version.release'
[ADB] Current device property 'ro.build.version.release': 9
[AndroidDriver] Using device: FA7971A04040
[ADB] Using 'adb.exe' from 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe'
[ADB] Setting device id to FA7971A04040
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell getprop ro.build.version.sdk'
[ADB] Current device property 'ro.build.version.sdk': 28
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell getprop ro.build.version.release'
[ADB] Current device property 'ro.build.version.release': 9
[ADB] Device API level: 28
[AndroidDriver] Consider setting 'automationName' capability to 'uiautomator2' on Android >= 6, since UIAutomator framework is not maintained anymore by the OS vendor.
[AndroidDriver] App file was not listed, instead we're going to run com.android.settings directly on the device
[AndroidDriver] Checking whether package is present on the device
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell pm list packages com.android.settings'
[AndroidDriver] Starting Android session
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 wait-for-device'
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell echo ping'
[AndroidDriver] Pushing settings apk to device...
[ADB] Getting install status for io.appium.settings
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell dumpsys package io.appium.settings'
[ADB] 'io.appium.settings' is installed
[ADB] Getting package info for 'io.appium.settings'
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell dumpsys package io.appium.settings'
[ADB] Using 'aapt.exe' from 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\build-tools\29.0.3\aapt.exe'
[ADB] The version name of the installed 'io.appium.settings' is greater or equal to the application version name ('2.14.0' >= '2.14.0')
[ADB] There is no need to install/upgrade 'C:\Users\cody.ming\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\io.appium.settings\apks\settings_apk-debug.apk'
[ADB] Getting IDs of all 'io.appium.settings' processes
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell 'pgrep --help; echo $?''
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell pgrep -f io\\.appium\\.settings'
[AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell appops set io.appium.settings android\:mock_location allow'
[Logcat] Starting logcat capture
[ADB] Getting device platform version
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell getprop ro.build.version.release'
[ADB] Current device property 'ro.build.version.release': 9
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell wm size'
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell getprop ro.product.model'
[ADB] Current device property 'ro.product.model': Pixel 2
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell getprop ro.product.manufacturer'
[ADB] Current device property 'ro.product.manufacturer': Google
[AndroidDriver] No app sent in, not parsing package/activity
[AndroidDriver] No app capability. Assuming it is already on the device
[ADB] Getting install status for com.android.settings
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell dumpsys package com.android.settings'
[ADB] 'com.android.settings' is installed
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell am force-stop com.android.settings'
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell pm clear com.android.settings'
[AndroidDriver] Performed fast reset on the installed 'com.android.settings' application (stop and clear)
[AndroidBootstrap] Watching for bootstrap disconnect
[ADB] Forwarding system: 4724 to device: 4724
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 forward tcp\:4724 tcp\:4724'
[UiAutomator] Starting UiAutomator
[UiAutomator] Moving to state 'starting'
[UiAutomator] Parsing uiautomator jar
[UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell mkdir -p /data/local'
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 push C\:\\Users\\cody.ming\\AppData\\Local\\Programs\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-android-driver\\bootstrap\\bin\\AppiumBootstrap.jar /data/local/tmp/'
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting IDs of all 'uiautomator' processes
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell pgrep -f uiautomator'
[ADB] No 'uiautomator' process has been found
[UiAutomator] Starting UIAutomator
[ADB] Creating ADB subprocess with args: ["-P",5037,"-s","FA7971A04040","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.android.settings","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[UiAutomator] Moving to state 'online'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] Android bootstrap socket is now connected
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell dumpsys window'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[AndroidDriver] Screen already unlocked, doing nothing
[ADB] Running 'E:\Android_for_Appium\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\adb.exe -P 5037 -s FA7971A04040 shell am start -W -n com.android.settings/com.android.settings.Settings -S'
[Appium] New AndroidDriver session created successfully, session 17effdf8-266d-4239-9edc-a5372dd5ad6b added to master session list
[BaseDriver] Event 'newSessionStarted' logged at 1597195778217 (09:29:38 GMT+0800 (中国标准时间))
[W3C (17effdf8)] Cached the protocol value 'W3C' for the new session 17effdf8-266d-4239-9edc-a5372dd5ad6b
[W3C (17effdf8)] Responding to client with driver.createSession() result: {"capabilities":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","platformVersion":"9","deviceName":"FA7971A04040","appPackage":"com.android.settings","appActivity":"com.android.settings.Settings","newCommandTimeout":3000},"platformName":"Android","platformVersion":"9","deviceName":"FA7971A04040","appPackage":"com.android.settings","appActivity":"com.android.settings.Settings","newCommandTimeout":3000,"deviceUDID":"FA7971A04040","deviceScreenSize":"1080x1920","deviceModel":"Pixel 2","deviceManufacturer":"Google"}}
[HTTP] <-- POST /wd/hub/session 200 10168 ms - 762
[HTTP] 
[HTTP] --> POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element
[HTTP] {"using":"name","value":"已连接的设备"}
[W3C (17effdf8)] Calling AppiumDriver.findElement() with args: ["name","已连接的设备","17effdf8-266d-4239-9edc-a5372dd5ad6b"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator, name
[BaseDriver] Waiting up to 0 ms for condition
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"已连接的设备","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"已连接的设备","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '已连接的设备' using 'NAME' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[DESCRIPTION=已连接的设备, INSTANCE=0]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[TEXT=已连接的设备, INSTANCE=0]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"1"}}
[AndroidBootstrap] Received command result from bootstrap
[W3C (17effdf8)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"1","ELEMENT":"1"}
[HTTP] <-- POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element 200 834 ms - 67
[HTTP] 
[HTTP] --> POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element/1/click
[HTTP] {"id":"1"}
[W3C (17effdf8)] Calling AppiumDriver.click() with args: ["1","17effdf8-266d-4239-9edc-a5372dd5ad6b"]
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"1"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"1"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[AndroidBootstrap] Received command result from bootstrap
[W3C (17effdf8)] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element/1/click 200 219 ms - 14
[HTTP] 
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[HTTP] --> POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element
[HTTP] {"using":"-android uiautomator","value":"new UiSelector().text(\"连接偏好设置\")"}
[W3C (17effdf8)] Calling AppiumDriver.findElement() with args: ["-android uiautomator","new UiSelector().text(\"连接偏好设置\")","17effdf8-266d-4239-9edc-a5372dd5ad6b"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator, name
[BaseDriver] Waiting up to 0 ms for condition
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiSelector().text(\"连接偏好设置\")","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiSelector().text(\"连接偏好设置\")","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'new UiSelector().text("连接偏好设置")' using 'ANDROID_UIAUTOMATOR' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Parsing selector: new UiSelector().text("连接偏好设置")
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: class java.lang.String arg: "连接偏好设置"
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[TEXT=连接偏好设置]
[AndroidBootstrap] Received command result from bootstrap
[W3C (17effdf8)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"2","ELEMENT":"2"}
[HTTP] <-- POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element 200 687 ms - 67
[HTTP] 
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"2"}}
[HTTP] --> POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element/2/click
[HTTP] {"id":"2"}
[W3C (17effdf8)] Calling AppiumDriver.click() with args: ["2","17effdf8-266d-4239-9edc-a5372dd5ad6b"]
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"2"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"2"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[AndroidBootstrap] Received command result from bootstrap
[W3C (17effdf8)] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element/2/click 200 227 ms - 14
[HTTP] 
[HTTP] --> POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element
[HTTP] {"using":"name","value":"蓝牙"}
[W3C (17effdf8)] Calling AppiumDriver.findElement() with args: ["name","蓝牙","17effdf8-266d-4239-9edc-a5372dd5ad6b"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator, name
[BaseDriver] Waiting up to 0 ms for condition
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"蓝牙","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"蓝牙","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '蓝牙' using 'NAME' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[DESCRIPTION=蓝牙, INSTANCE=0]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[TEXT=蓝牙, INSTANCE=0]
[AndroidBootstrap] Received command result from bootstrap
[W3C (17effdf8)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"3","ELEMENT":"3"}
[HTTP] <-- POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element 200 793 ms - 67
[HTTP] 
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"3"}}
[HTTP] --> POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element/3/click
[HTTP] {"id":"3"}
[W3C (17effdf8)] Calling AppiumDriver.click() with args: ["3","17effdf8-266d-4239-9edc-a5372dd5ad6b"]
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"3"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"3"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[AndroidBootstrap] Received command result from bootstrap
[W3C (17effdf8)] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element/3/click 200 222 ms - 14
[HTTP] 
[HTTP] --> POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element
[HTTP] {"using":"id","value":"com.android.settings:id/switch_widget"}
[W3C (17effdf8)] Calling AppiumDriver.findElement() with args: ["id","com.android.settings:id/switch_widget","17effdf8-266d-4239-9edc-a5372dd5ad6b"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator, name
[BaseDriver] Waiting up to 0 ms for condition
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.settings:id/switch_widget","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.settings:id/switch_widget","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.android.settings:id/switch_widget' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.android.settings:id/switch_widget]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"4"}}
[AndroidBootstrap] Received command result from bootstrap
[W3C (17effdf8)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"4","ELEMENT":"4"}
[HTTP] <-- POST /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element 200 725 ms - 67
[HTTP] 
[HTTP] --> GET /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element/4/attribute/checked
[HTTP] {}
[W3C (17effdf8)] Calling AppiumDriver.getAttribute() with args: ["checked","4","17effdf8-266d-4239-9edc-a5372dd5ad6b"]
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:getAttribute","params":{"attribute":"checked","elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getAttribute","params":{"attribute":"checked","elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getAttribute
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"true"}
[AndroidBootstrap] Received command result from bootstrap
[W3C (17effdf8)] Responding to client with driver.getAttribute() result: "true"
[HTTP] <-- GET /wd/hub/session/17effdf8-266d-4239-9edc-a5372dd5ad6b/element/4/attribute/checked 200 37 ms - 16
[HTTP] 

CMD 中的执行结果:

以上,谢谢!

共收到 6 条回复 时间 点赞

有没有试过模块级的 Fixture?可以自己看一下 setUpModule() 和 tearDownModule() 的使用

可以学习一下 unittest 的使用

setup_class() 方法是每个 class 执行一次,你三个 class,执行 3 次有啥毛病,你在第一个 class 里放两个测试方法就能看出区别了。把这事本身当个功能测试来做,也不应该一个 class 里丢一个测试方法

把 setup 放到init.py 里去。

这个是之前几个 demo 复制黏贴出来的。。。。犯了个错误。。。。已经改好了。。。。

分开三个 class 当然是三次了,建议复习 unittest

tancaidexiaoming 关闭了讨论 08月13日 08:00
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册