• 老师,我在作业中遇到无法导入包的问题,报错如下:

    涉及代码中的3个文件search.py、stock.py、main.py
    报错的时候导入包的方式这样写的:
    search.py :需要由搜索页面跳转到行情页面stock.py,所以在这个文件中 'from xx import stock'导入了stock类
    stock.py:需要由此页面跳转到搜索页面search.py,所以在这个文件中'from xx import search'导入了search类
    main.py:需要同时调用这两个页面,所以同样采用了'from xx import'方式,将这两个类都导进来
    结果:执行测试用例test_stock.py,就报上面截图错误,一直导入包失败
    网上搜索:说是python循环导入包的问题,解决方案我找到了其中一个,说是这种情况不要在全局导入包,在需要调用的函数里面导入包即可
    解决:作业中按上面的办法,在调用的函数里面导入包不报错了,执行成功
    但是,这样写好像是不太好看呀,不知道咋能优化下或者避免下

    作业:#8 楼

  • 第 11 期_appium 进阶_20200223 at February 26, 2020

    作业1

    from time import sleep

    from appium import webdriver
    from appium.webdriver.common.mobileby import MobileBy
    from appium.webdriver.common.touch_action import TouchAction
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions
    from selenium.webdriver.support.wait import WebDriverWait


    class TestXueqiu:
    def setup(self):
    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "hogwarts"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    caps["noReset"] = True
    # caps["uiautomator2ServerInstallTimeout"]=50000
    caps["chromedriverExecutable"] = r"E:\drivers\appium_drivers\chromedriver_2.20.exe"
    caps["adbExecTimeout"] = 50000
    # caps["dontStopAppOnReset"] = True
    # caps["unicodeKeyboard"] = True
    # caps["resetKeyboard"] = True
    caps["skipServerInstallation"] = True

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

    def test_webview_context(self):
    self.driver.find_element(By.XPATH, "//*[@text='交易' and contains(@resource-id, 'tab')]").click()
    WebDriverWait(self.driver, 30).until(lambda x: len(self.driver.contexts) > 1)

    # 切换webview 之前,获取当前context
    contexts = self.driver.current_context
    self.driver.switch_to.context(self.driver.contexts[-1])

    # 定位点击"港美股开户"
    self.driver.find_element(By.CSS_SELECTOR, ".trade_home_xueying_SJY .trade_home_info_3aI").click()
    #等待新窗口出现
    WebDriverWait(self.driver, 30).until(lambda x: len(self.driver.window_handles) > 3)
    # 切换到新窗口
    self.driver.switch_to.window(self.driver.window_handles[-1])

    phone = (By.XPATH, '//*[@placeholder="请输入手机号"]')
    checkcode = (By.XPATH, '//*[@placeholder="请输入验证码"]')
    # 显式等待元素出现
    WebDriverWait(self.driver, 60).until(expected_conditions.visibility_of_element_located(phone))
    self.driver.find_element(*phone).send_keys("13465784653")
    self.driver.find_element(*checkcode).send_keys("098452")

    # 点击立即开户
    self.driver.find_element(By.XPATH, '//button[text()="立即开户"]').click()
    #定位toast弹框
    toast_locator=(By.CSS_SELECTOR,'.Toast_toast_22U')
    WebDriverWait(self.driver, 60).until(expected_conditions.visibility_of_element_located(toast_locator))
    toast=self.driver.find_element(*toast_locator).text
    assert '验证码错误' in toast

    # 切换回原生
    self.driver.switch_to.context(contexts)
    # 点击返回按钮
    self.driver.find_element(MobileBy.ID, 'action_bar_back').click()

  • 作业1

    #appium启动
    2020-02-20 13:32:37:539 [Appium] Welcome to Appium v1.14.2
    2020-02-20 13:32:37:542 [Appium] Non-default server args:
    2020-02-20 13:32:37:544 [Appium] logFile: f:\appium.log
    2020-02-20 13:32:37:544 [Appium] logTimestamp: true
    2020-02-20 13:32:37:545 [Appium] localTimezone: true

    #启动appium server,端口为4723,监听客户端http请求
    2020-02-20 13:32:37:630 [Appium] Appium REST http interface listener started on 0.0.0.0:4723

    #接收到客户端的post请求,创建session
    2020-02-20 13:32:59:477 [HTTP] --> POST /wd/hub/session
    2020-02-20 13:32:59:479 [HTTP] {"capabilities":{"firstMatch":[{"platformName":"android","appium:deviceName":"hogwarts","appium:appPackage":"com.xueqiu.android","appium:appActivity":".view.WelcomeActivityAlias","appium:noReset":true,"appium:dontStopAppOnReset":true,"appium:unicodeKeyboard":true,"appium:resetKeyboard":true,"appium:skipServerInstallation":true}]},"desiredCapabilities":{"platformName":"android","deviceName":"hogwarts","appPackage":"com.xueqiu.android","appActivity":".view.WelcomeActivityAlias","noReset":true,"dontStopAppOnReset":true,"unicodeKeyboard":true,"resetKeyboard":true,"skipServerInstallation":true}}

    #通过调用AppiumDrivercreateSession方法并传入desired_capabilities参数请求创建一个Session,并将请求创建Session的事件时间记录下来
    2020-02-20 13:32:59:484 [W3C] Calling AppiumDriver.createSession() with args: [{"platformName":"android","deviceName":"hogwarts","appPackage":"com.xueqiu.android","appActivity":".view.WelcomeActivityAlias","noReset":true,"dontStopAppOnReset":true,"unicodeKeyboard":true,"resetKeyboard":true,"skipServerInstallation":true},null,{"firstMatch":[{"platformName":"android","appium:deviceName":"hogwarts","appium:appPackage":"com.xueqiu.android","appium:appActivity":".view.WelcomeActivityAlias","appium:noReset":true,"appium:dontStopAppOnReset":true,"appium:unicodeKeyboard":true,"appium:resetKeyboard":true,"appium:skipServerInstallation":true}]}]
    2020-02-20 13:32:59:486 [BaseDriver] Event 'newSessionRequested' logged at 1582176779485 (13:32:59 GMT+0800 (GMT+08:00))

    #appium调用basedriver创建AndroidUiautomator2Driversession,返回session id
    2020-02-20 13:32:59:501 [Appium]
    2020-02-20 13:32:59:502 [Appium] ======================================================================
    2020-02-20 13:32:59:503 [Appium] DEPRECATION WARNING:
    2020-02-20 13:32:59:504 [Appium]
    2020-02-20 13:32:59:505 [Appium] The 'automationName' capability was not provided in the desired
    2020-02-20 13:32:59:506 [Appium] capabilities for this Android session
    2020-02-20 13:32:59:509 [Appium]
    2020-02-20 13:32:59:510 [Appium] Setting 'automationName=UiAutomator2' by default and using the
    2020-02-20 13:32:59:511 [Appium] UiAutomator2 Driver
    2020-02-20 13:32:59:512 [Appium]
    2020-02-20 13:32:59:512 [Appium] The next major version of Appium (2.x) will **require** the
    2020-02-20 13:32:59:514 [Appium] 'automationName' capability to be set for all sessions on all
    2020-02-20 13:32:59:516 [Appium] platforms
    2020-02-20 13:32:59:517 [Appium]
    2020-02-20 13:32:59:518 [Appium] In previous versions (Appium <= 1.13.x), the default was
    2020-02-20 13:32:59:520 [Appium] 'automationName=UiAutomator1'
    2020-02-20 13:32:59:521 [Appium]
    2020-02-20 13:32:59:523 [Appium] If you wish to use that automation instead of UiAutomator2, please
    2020-02-20 13:32:59:524 [Appium] add 'automationName=UiAutomator1' to your desired capabilities
    2020-02-20 13:32:59:525 [Appium]
    2020-02-20 13:32:59:528 [Appium] For more information about drivers, please visit
    2020-02-20 13:32:59:531 [Appium] http://appium.io/docs/en/about-appium/intro/ and explore the
    2020-02-20 13:32:59:533 [Appium] 'Drivers' menu
    2020-02-20 13:32:59:534 [Appium]
    2020-02-20 13:32:59:535 [Appium] ======================================================================
    2020-02-20 13:32:59:536 [Appium]
    2020-02-20 13:33:00:757 [Appium] Appium v1.14.2 creating new AndroidUiautomator2Driver (v1.37.1) session
    2020-02-20 13:33:00:760 [Appium] Capabilities:
    2020-02-20 13:33:00:761 [Appium] platformName: android
    2020-02-20 13:33:00:762 [Appium] deviceName: hogwarts
    2020-02-20 13:33:00:764 [Appium] appPackage: com.xueqiu.android
    2020-02-20 13:33:00:765 [Appium] appActivity: .view.WelcomeActivityAlias
    2020-02-20 13:33:00:768 [Appium] noReset: true
    2020-02-20 13:33:00:770 [Appium] dontStopAppOnReset: true
    2020-02-20 13:33:00:772 [Appium] unicodeKeyboard: true
    2020-02-20 13:33:00:775 [Appium] resetKeyboard: true
    2020-02-20 13:33:00:778 [Appium] skipServerInstallation: true
    2020-02-20 13:33:00:793 [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
    2020-02-20 13:33:00:798 [BaseDriver] Creating session with W3C capabilities: {
    2020-02-20 13:33:00:800 [BaseDriver] "alwaysMatch": {
    2020-02-20 13:33:00:802 [BaseDriver] "platformName": "android",
    2020-02-20 13:33:00:804 [BaseDriver] "appium:deviceName": "hogwarts",
    2020-02-20 13:33:00:808 [BaseDriver] "appium:appPackage": "com.xueqiu.android",
    2020-02-20 13:33:00:813 [BaseDriver] "appium:appActivity": ".view.WelcomeActivityAlias",
    2020-02-20 13:33:00:816 [BaseDriver] "appium:noReset": true,
    2020-02-20 13:33:00:818 [BaseDriver] "appium:dontStopAppOnReset": true,
    2020-02-20 13:33:00:821 [BaseDriver] "appium:unicodeKeyboard": true,
    2020-02-20 13:33:00:823 [BaseDriver] "appium:resetKeyboard": true,
    2020-02-20 13:33:00:826 [BaseDriver] "appium:skipServerInstallation": true
    2020-02-20 13:33:00:830 [BaseDriver] },
    2020-02-20 13:33:00:833 [BaseDriver] "firstMatch": [
    2020-02-20 13:33:00:836 [BaseDriver] {}
    2020-02-20 13:33:00:837 [BaseDriver] ]
    2020-02-20 13:33:00:840 [BaseDriver] }
    2020-02-20 13:33:00:883 [BaseDriver] Session created with session id: 5410cd7e-45ea-4c1f-9b27-d8b32c9c947d

    #UiAutomator2启动对应app
    2020-02-20 13:33:00:886 [UiAutomator2] Starting 'com.xueqiu.android' directly on the device

    #查找使用的build-tools文件夹以及adb.exe文件的位置
    2020-02-20 13:33:01:428 [ADB] Found 1 'build-tools' folders under 'E:\AndroidSDK' (newest first):
    2020-02-20 13:33:01:433 [ADB] E:/AndroidSDK/build-tools/29.0.2
    2020-02-20 13:33:01:437 [ADB] Using 'adb.exe' from 'E:\AndroidSDK\platform-tools\adb.exe'

    #使用adb命令查找连接的设备,并为设备设置id
    2020-02-20 13:33:01:439 [AndroidDriver] Retrieving device list
    2020-02-20 13:33:01:441 [ADB] Trying to find a connected android device
    2020-02-20 13:33:01:445 [ADB] Getting connected devices...
    2020-02-20 13:33:01:545 [ADB] Connected devices: [{"udid":"127.0.0.1:7555","state":"device"}]
    2020-02-20 13:33:01:548 [AndroidDriver] Using device: 127.0.0.1:7555
    2020-02-20 13:33:01:551 [ADB] Using 'adb.exe' from 'E:\AndroidSDK\platform-tools\adb.exe'
    2020-02-20 13:33:01:553 [ADB] Setting device id to 127.0.0.1:7555

    #查找sdk版本
    2020-02-20 13:33:01:557 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell getprop ro.build.version.sdk'
    2020-02-20 13:33:01:644 [ADB] Current device property 'ro.build.version.sdk': 23
    2020-02-20 13:33:01:645 [ADB] Device API level: 23

    #检查设备连接状态
    2020-02-20 13:33:01:647 [AndroidDriver] No app sent in, not parsing package/activity
    2020-02-20 13:33:01:649 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 wait-for-device'
    2020-02-20 13:33:01:723 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell echo ping'

    #检查并安装io.appium.settings,apk
    2020-02-20 13:33:01:795 [AndroidDriver] Pushing settings apk to device...
    2020-02-20 13:33:01:798 [ADB] Getting install status for io.appium.settings
    2020-02-20 13:33:01:800 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell dumpsys package io.appium.settings'
    2020-02-20 13:33:01:889 [ADB] 'io.appium.settings' is not installed
    2020-02-20 13:33:01:891 [ADB] App 'E:\nodejs\node_global\node_modules\appium\node_modules\_io.appium.settings@2.14.2@io.appium.settings\apks\settings_apk-debug.apk' is not installed
    2020-02-20 13:33:01:892 [ADB] Installing 'E:\nodejs\node_global\node_modules\appium\node_modules\_io.appium.settings@2.14.2@io.appium.settings\apks\settings_apk-debug.apk'
    2020-02-20 13:33:01:907 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell 'ls -t -1 /data/local/tmp/appium_cache 2>&1 || echo _ERROR_''
    2020-02-20 13:33:01:999 [ADB] The current Android API does not support extended ls options. Defaulting to no-options call
    2020-02-20 13:33:02:001 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell 'ls /data/local/tmp/appium_cache 2>&1 || echo _ERROR_''
    2020-02-20 13:33:02:085 [ADB] The count of applications in the cache: 3
    2020-02-20 13:33:02:088 [ADB] The application at 'E:\nodejs\node_global\node_modules\appium\node_modules\_io.appium.settings@2.14.2@io.appium.settings\apks\settings_apk-debug.apk' is already cached to '/data/local/tmp/appium_cache/3d97225b036c28750562ef8962defee6b1af19a4.apk'
    2020-02-20 13:33:02:093 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell pm install -g /data/local/tmp/appium_cache/3d97225b036c28750562ef8962defee6b1af19a4.apk'
    2020-02-20 13:33:02:990 [ADB] The installation of 'settings_apk-debug.apk' took 0.892s
    2020-02-20 13:33:03:024 [ADB] Install command stdout: pkg: /data/local/tmp/appium_cache/3d97225b036c28750562ef8962defee6b1af19a4.apk
    2020-02-20 13:33:03:026 [ADB] Success
    2020-02-20 13:33:03:047 [ADB] Getting IDs of all 'io.appium.settings' processes
    2020-02-20 13:33:03:049 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell 'pgrep --help; echo $?''
    2020-02-20 13:33:03:182 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell pgrep -f io\\.appium\\.settings'

    2020-02-20 13:33:03:285 [AndroidDriver] Granting android.permission.SET_ANIMATION_SCALE, CHANGE_CONFIGURATION, ACCESS_FINE_LOCATION by pm grant
    2020-02-20 13:33:03:287 [ADB] Granting permissions ["android.permission.SET_ANIMATION_SCALE","android.permission.CHANGE_CONFIGURATION","android.permission.ACCESS_FINE_LOCATION"] to 'io.appium.settings'
    2020-02-20 13:33:03:291 [ADB] Got the following command chunks to execute: [["pm","grant","io.appium.settings","android.permission.SET_ANIMATION_SCALE",";","pm","grant","io.appium.settings","android.permission.CHANGE_CONFIGURATION",";","pm","grant","io.appium.settings","android.permission.ACCESS_FINE_LOCATION",";"]]
    2020-02-20 13:33:03:293 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell pm grant io.appium.settings android.permission.SET_ANIMATION_SCALE \; pm grant io.appium.settings android.permission.CHANGE_CONFIGURATION \; pm grant io.appium.settings android.permission.ACCESS_FINE_LOCATION \;'
    2020-02-20 13:33:04:439 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell am start -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER'
    2020-02-20 13:33:05:063 [ADB] Getting IDs of all 'io.appium.settings' processes
    2020-02-20 13:33:05:067 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell pgrep -f io\\.appium\\.settings'

    # 调用appopsio.appium.settings添加允许模拟位置(mock_location)的权限
    2020-02-20 13:33:05:280 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell appops set io.appium.settings android\:mock_location allow'

    #启用unicode
    2020-02-20 13:33:05:945 [Logcat] Starting logcat capture
    2020-02-20 13:33:06:063 [AndroidDriver] Enabling Unicode keyboard support
    2020-02-20 13:33:06:071 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell settings get secure default_input_method'
    2020-02-20 13:33:07:122 [AndroidDriver] Unsetting previous IME com.netease.nemu_vinput.nemu/com.android.inputmethodcommon.SoftKeyboard
    2020-02-20 13:33:07:124 [AndroidDriver] Setting IME to 'io.appium.settings/.UnicodeIME'
    2020-02-20 13:33:07:125 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell ime enable io.appium.settings/.UnicodeIME'
    2020-02-20 13:33:07:700 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell ime set io.appium.settings/.UnicodeIME'
    2020-02-20 13:33:08:319 [UiAutomator2] 'skipServerInstallation' is set. Skipping UIAutomator2 server installation.

    #建立UiAutomator2服务的端口转发,将PC端的一个端口数据转发给设备端的另一个端口
    2020-02-20 13:33:08:320 [UiAutomator2] Forwarding UiAutomator2 Server port 6790 to 8203
    2020-02-20 13:33:08:322 [ADB] Forwarding system: 8203 to device: 6790
    2020-02-20 13:33:08:325 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 forward tcp\:8203 tcp\:6790'

    2020-02-20 13:33:08:400 [UiAutomator2] No app capability. Assuming it is already on the device
    2020-02-20 13:33:08:403 [UiAutomator2] Performing shallow cleanup of automation leftovers
    2020-02-20 13:33:08:465 [UiAutomator2] The following obsolete sessions are still running: ["7c6f5fff-0285-457d-a9fb-5fb0adad722c"]
    2020-02-20 13:33:08:467 [UiAutomator2] Cleaning up the obsolete sessions

    #adb shell am force-stop 关闭uiautomator2.server.test
    2020-02-20 13:33:09:524 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell am force-stop io.appium.uiautomator2.server.test'
    2020-02-20 13:33:10:143 [UiAutomator2] 'skipServerInstallation' is set. Attempting to use UIAutomator2 server from the device
    2020-02-20 13:33:10:145 [UiAutomator2] Waiting up to 30000ms for UiAutomator2 to be online...

    #adb shell am instrument启动一个am子进程Instrumentation测试
    2020-02-20 13:33:10:147 [ADB] Creating ADB subprocess with args: ["-P",5037,"-s","127.0.0.1:7555","shell","am","instrument","-w","io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner"]
    2020-02-20 13:33:10:772 [Instrumentation] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:
    2020-02-20 13:33:11:174 [WD Proxy] Matched '/status' to command name 'getStatus'
    2020-02-20 13:33:11:186 [WD Proxy] Proxying [GET /status] to [GET http://localhost:8203/wd/hub/status] with no body
    2020-02-20 13:33:11:215 [WD Proxy] Got an unexpected response with status undefined: {"code":"ECONNRESET"}
    2020-02-20 13:33:12:223 [WD Proxy] Matched '/status' to command name 'getStatus'
    2020-02-20 13:33:12:238 [WD Proxy] Proxying [GET /status] to [GET http://localhost:8203/wd/hub/status] with no body
    2020-02-20 13:33:12:342 [WD Proxy] Got response with status 200: {"sessionId":"None","value":{"ready":true,"message":"UiAutomator2 Server is ready to accept commands"}}
    2020-02-20 13:33:12:345 [UiAutomator2] The initialization of the instrumentation process took 2201ms

    #通过POST方法将capabilities参数通过代理传输到设备端
    2020-02-20 13:33:12:348 [WD Proxy] Matched '/session' to command name 'createSession'
    2020-02-20 13:33:12:353 [WD Proxy] Proxying [POST /session] to [POST http://localhost:8203/wd/hub/session] with body: {"capabilities":{"firstMatch":[{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"android","deviceName":"hogwarts","appPackage":"com.xueqiu.android","appActivity":".view.WelcomeActivityAlias","noReset":true,"dontStopAppOnReset":true,"unicodeKeyboard":true,"resetKeyboard":true,"skipServerInstallation":true},"platformName":"android","deviceName":"127.0.0.1:7555","appPackage":"com.xueqiu.android","appActivity":".view.WelcomeActivityAlias","noReset":true,"dontStopAppOnReset":true,"unicodeKeyboard":true,"resetKeyboard":true,"skipServerInstallation":true,"deviceUDID":"127.0.0.1:7555"}],"alwaysMatch":{}}}
    2020-02-20 13:33:12:387 [WD Proxy] Got response with status 200: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","capabilities":{"firstMatch":[{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"android","deviceName":"hogwarts","appPackage":"com.xueqiu.android","appActivity":".view.WelcomeActivityAlias","noReset":true,"dontStopAppOnReset":true,"unicodeKeyboard":true,"resetKeyboard":true,"skipServerInstallation":true},"platformName":"android","deviceName":"127.0.0.1:7555","appPackage":"com.xueqiu.android","appActivity":".view.WelcomeActivityAlias","noReset":true,"dontStopAppOnReset":true,"unicodeKeyboard":true,"resetKeyboard":true,"skipServerInstallation":true,"deviceUDID":"127.0.0.1:7555"}],"alwaysMatch":{}}}}
    2020-02-20 13:33:12:389 [WD Proxy] Determined the downstream protocol as 'W3C'

    #/appium/device/info获取设备硬件信息
    2020-02-20 13:33:12:423 [WD Proxy] Proxying [GET /appium/device/info] to [GET http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/appium/device/info] with no body
    2020-02-20 13:33:12:463 [WD Proxy] Got response with status 200: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"androidId":"1acc8bcf5e2059fb","manufacturer":"samsung","model":"SM-G9550","brand":"samsung","apiVersion":"23","platformVersion":"6.0.1","carrierName":"中国移动","realDisplaySize":"1024x576","displayDensity":192,"networks":[{"type":1,"typeName":"WIFI","subtype":0,"subtypeName":"","isConnected":true,"detailedState":"CONNECTED","state":"CONNECTED","extraInfo":"\"u10gr4gdJ9F\"","isAvailable":true,"isFailover":false,"isRoaming":false,"capabilities":{"transportTypes":"NET_CAPABILITY_SUPL","networkCapabilities":"","linkUpstreamBandwidthKbps":1048576,"linkDownBandwidthKbps":1048576,"signalStrength":-55,"networkSpecifier":null,"SSID":null}}],"locale":"zh_CN","timeZone":"Asia\/Shanghai"}}

    #屏幕解锁
    2020-02-20 13:33:12:465 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell dumpsys window'
    2020-02-20 13:33:12:562 [AndroidDriver] Screen already unlocked, doing nothing

    #根据参数中的appPackageappActivity启动app
    2020-02-20 13:33:12:565 [UiAutomator2] Starting 'com.xueqiu.android/.view.WelcomeActivityAlias and waiting for 'com.xueqiu.android/.view.WelcomeActivityAlias'
    2020-02-20 13:33:12:569 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell am start -W -n com.xueqiu.android/.view.WelcomeActivityAlias -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000'

    #获取设备像素比、系统栏、尺寸
    2020-02-20 13:33:15:425 [WD Proxy] Proxying [GET /appium/device/pixel_ratio] to [GET http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/appium/device/pixel_ratio] with body: {}
    2020-02-20 13:33:15:457 [WD Proxy] Got response with status 200: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":1.2}
    2020-02-20 13:33:15:469 [WD Proxy] Matched '/appium/device/system_bars' to command name 'getSystemBars'
    2020-02-20 13:33:15:485 [WD Proxy] Proxying [GET /appium/device/system_bars] to [GET http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/appium/device/system_bars] with body: {}
    2020-02-20 13:33:15:515 [WD Proxy] Got response with status 200: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"statusBar":29}}
    2020-02-20 13:33:15:521 [WD Proxy] Matched '/window/current/size' to command name 'getWindowSize'
    2020-02-20 13:33:15:525 [WD Proxy] Proxying [GET /window/current/size] to [GET http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/window/current/size] with body: {}
    2020-02-20 13:33:15:559 [WD Proxy] Got response with status 200: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"height":1024,"width":576}}

    #AndroidUiautomator2Driversession创建成功
    2020-02-20 13:33:15:562 [Appium] New AndroidUiautomator2Driver session created successfully, session 5410cd7e-45ea-4c1f-9b27-d8b32c9c947d added to master session list
    2020-02-20 13:33:15:567 [BaseDriver] Event 'newSessionStarted' logged at 1582176795564 (13:33:15 GMT+0800 (GMT+08:00))

    #session创建完成
    2020-02-20 13:33:15:575 [W3C (5410cd7e)] Cached the protocol value 'W3C' for the new session 5410cd7e-45ea-4c1f-9b27-d8b32c9c947d
    2020-02-20 13:33:15:588 [W3C (5410cd7e)] 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","deviceName":"hogwarts","appPackage":"com.xueqiu.android","appActivity":".view.WelcomeActivityAlias","noReset":true,"dontStopAppOnReset":true,"unicodeKeyboard":true,"resetKeyboard":true,"skipServerInstallation":true},"platformName":"android","deviceName":"127.0.0.1:7555","appPackage":"com.xueqiu.android","appActivity":".view.WelcomeActivityAlias","noReset":true,"dontStopAppOnReset":true,"unicodeKeyboard":true,"resetKeyboard":true,"skipServerInstallation":true,"deviceUDID":"127.0.0.1:7555","deviceApiLevel":23,"platformVersion":"6.0.1","deviceScreenSize":"1024x576","deviceScreenDensity":192,"deviceModel":"SM-G9550","deviceManufacturer":"samsung","pixelRatio":1.2,"statBarHeight":29,"viewportRect":{"left":0,"top":29,"width":576,"height":995}}}
    2020-02-20 13:33:15:619 [HTTP] <-- POST /wd/hub/session 200 16122 ms - 1057
    2020-02-20 13:33:15:662 [HTTP]

    #发送post请求,设置隐式等待
    2020-02-20 13:33:15:689 [HTTP] --> POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/timeouts
    2020-02-20 13:33:15:695 [HTTP] {"implicit":20000}
    2020-02-20 13:33:15:709 [W3C (5410cd7e)] Calling AppiumDriver.timeouts() with args: [null,null,null,null,20000,"5410cd7e-45ea-4c1f-9b27-d8b32c9c947d"]
    2020-02-20 13:33:15:833 [BaseDriver] W3C timeout argument: {"implicit":20000}}
    2020-02-20 13:33:15:838 [BaseDriver] Set implicit wait to 20000ms
    2020-02-20 13:33:15:841 [W3C (5410cd7e)] Responding to client with driver.timeouts() result: null
    2020-02-20 13:33:15:859 [HTTP] <-- POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/timeouts 200 168 ms - 14
    2020-02-20 13:33:15:861 [HTTP]

    #发送post请求,在隐式等待时间内,循环查找元素,直到timeout或者找到元素
    2020-02-20 13:33:15:872 [HTTP] --> POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element
    2020-02-20 13:33:15:873 [HTTP] {"using":"id","value":"tv_search"}
    2020-02-20 13:33:15:880 [W3C (5410cd7e)] Calling AppiumDriver.findElement() with args: ["id","tv_search","5410cd7e-45ea-4c1f-9b27-d8b32c9c947d"]
    2020-02-20 13:33:15:887 [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
    2020-02-20 13:33:15:889 [BaseDriver] Waiting up to 20000 ms for condition
    2020-02-20 13:33:15:906 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:15:912 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"strategy":"id","selector":"tv_search","context":"","multiple":false}
    2020-02-20 13:33:16:062 [WD Proxy] Got an unexpected response with status 404: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:78)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
    2020-02-20 13:33:16:064 [W3C] Matched W3C error code 'no such element' to NoSuchElementError
    2020-02-20 13:33:16:066 [BaseDriver] Waited for 175 ms so far
    2020-02-20 13:33:16:570 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:16:573 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"
    strategy":"id","selector":"tv_search","context":"","multiple":false}
    2020-02-20 13:33:16:943 [WD Proxy] Got an unexpected response with status 404: {"
    sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:78)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
    2020-02-20 13:33:16:944 [W3C] Matched W3C error code 'no such element' to NoSuchElementError
    2020-02-20 13:33:16:945 [BaseDriver] Waited for 1055 ms so far
    2020-02-20 13:33:17:448 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:17:450 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"strategy":"id","selector":"tv_search","context":"","multiple":false}
    2020-02-20 13:33:17:958 [WD Proxy] Got an unexpected response with status 404: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:78)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
    2020-02-20 13:33:17:960 [W3C] Matched W3C error code 'no such element' to NoSuchElementError
    2020-02-20 13:33:17:963 [BaseDriver] Waited for 2071 ms so far
    2020-02-20 13:33:18:473 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:18:483 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"
    strategy":"id","selector":"tv_search","context":"","multiple":false}
    2020-02-20 13:33:18:658 [WD Proxy] Got an unexpected response with status 404: {"
    sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:78)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
    2020-02-20 13:33:18:662 [W3C] Matched W3C error code 'no such element' to NoSuchElementError
    2020-02-20 13:33:18:664 [BaseDriver] Waited for 2773 ms so far
    2020-02-20 13:33:19:168 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:19:172 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"strategy":"id","selector":"tv_search","context":"","multiple":false}
    2020-02-20 13:33:19:201 [WD Proxy] Got an unexpected response with status 404: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:78)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
    2020-02-20 13:33:19:204 [W3C] Matched W3C error code 'no such element' to NoSuchElementError
    2020-02-20 13:33:19:206 [BaseDriver] Waited for 3315 ms so far
    2020-02-20 13:33:19:716 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:19:720 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"
    strategy":"id","selector":"tv_search","context":"","multiple":false}
    2020-02-20 13:33:20:300 [WD Proxy] Got an unexpected response with status 404: {"
    sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:78)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
    2020-02-20 13:33:20:303 [W3C] Matched W3C error code 'no such element' to NoSuchElementError
    2020-02-20 13:33:20:316 [BaseDriver] Waited for 4414 ms so far
    2020-02-20 13:33:20:819 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:20:825 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"strategy":"id","selector":"tv_search","context":"","multiple":false}
    2020-02-20 13:33:22:398 [WD Proxy] Got an unexpected response with status 404: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:78)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
    2020-02-20 13:33:22:401 [W3C] Matched W3C error code 'no such element' to NoSuchElementError
    2020-02-20 13:33:22:406 [BaseDriver] Waited for 6512 ms so far
    2020-02-20 13:33:22:913 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:22:982 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"
    strategy":"id","selector":"tv_search","context":"","multiple":false}
    2020-02-20 13:33:23:244 [WD Proxy] Got response with status 200: {"
    sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"ELEMENT":"5d5ee9fd-4afa-4549-8082-209ac2365a78","element-6066-11e4-a52e-4f735466cecf":"5d5ee9fd-4afa-4549-8082-209ac2365a78"}}
    2020-02-20 13:33:23:248 [W3C (5410cd7e)] Responding to client with driver.findElement() result: {"
    element-6066-11e4-a52e-4f735466cecf":"5d5ee9fd-4afa-4549-8082-209ac2365a78","ELEMENT":"5d5ee9fd-4afa-4549-8082-209ac2365a78"}
    2020-02-20 13:33:23:252 [HTTP] <-- POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element 200 7385 ms - 137
    2020-02-20 13:33:23:258 [HTTP]

    #点击上面查找到的元素
    2020-02-20 13:33:23:268 [HTTP] --> POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element/5d5ee9fd-4afa-4549-8082-209ac2365a78/click
    2020-02-20 13:33:23:280 [HTTP] {"
    id":"5d5ee9fd-4afa-4549-8082-209ac2365a78"}
    2020-02-20 13:33:23:302 [W3C (5410cd7e)] Calling AppiumDriver.click() with args: ["
    5d5ee9fd-4afa-4549-8082-209ac2365a78","5410cd7e-45ea-4c1f-9b27-d8b32c9c947d"]
    2020-02-20 13:33:23:312 [WD Proxy] Matched '/element/5d5ee9fd-4afa-4549-8082-209ac2365a78/click' to command name 'click'
    2020-02-20 13:33:23:337 [WD Proxy] Proxying [POST /element/5d5ee9fd-4afa-4549-8082-209ac2365a78/click] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element/5d5ee9fd-4afa-4549-8082-209ac2365a78/click] with body: {"
    element":"5d5ee9fd-4afa-4549-8082-209ac2365a78"}
    2020-02-20 13:33:24:163 [WD Proxy] Got response with status 200: {"
    sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":null}
    2020-02-20 13:33:24:172 [W3C (5410cd7e)] Responding to client with driver.click() result: null
    2020-02-20 13:33:24:193 [HTTP] <-- POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element/5d5ee9fd-4afa-4549-8082-209ac2365a78/click 200 915 ms - 14
    2020-02-20 13:33:24:203 [HTTP]

    #查找元素
    2020-02-20 13:33:24:249 [HTTP] --> POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element
    2020-02-20 13:33:24:253 [HTTP] {"
    using":"id","value":"search_input_text"}
    2020-02-20 13:33:24:263 [W3C (5410cd7e)] Calling AppiumDriver.findElement() with args: ["
    id","search_input_text","5410cd7e-45ea-4c1f-9b27-d8b32c9c947d"]
    2020-02-20 13:33:24:280 [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
    2020-02-20 13:33:24:285 [BaseDriver] Waiting up to 20000 ms for condition
    2020-02-20 13:33:24:333 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:24:343 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"
    strategy":"id","selector":"search_input_text","context":"","multiple":false}
    2020-02-20 13:33:25:199 [WD Proxy] Got response with status 200: {"
    sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"ELEMENT":"83196862-45d1-4574-97fe-4d0975c3c77e","element-6066-11e4-a52e-4f735466cecf":"83196862-45d1-4574-97fe-4d0975c3c77e"}}
    2020-02-20 13:33:25:203 [W3C (5410cd7e)] Responding to client with driver.findElement() result: {"
    element-6066-11e4-a52e-4f735466cecf":"83196862-45d1-4574-97fe-4d0975c3c77e","ELEMENT":"83196862-45d1-4574-97fe-4d0975c3c77e"}
    2020-02-20 13:33:25:207 [HTTP] <-- POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element 200 992 ms - 137
    2020-02-20 13:33:25:211 [HTTP]

    #在上面找到的元素中输入文本
    2020-02-20 13:33:25:219 [HTTP] --> POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element/83196862-45d1-4574-97fe-4d0975c3c77e/value
    2020-02-20 13:33:25:225 [HTTP] {"
    text":"阿里巴巴","value":["","","",""],"id":"83196862-45d1-4574-97fe-4d0975c3c77e"}
    2020-02-20 13:33:25:237 [W3C (5410cd7e)] Calling AppiumDriver.setValue() with args: [["
    ","","",""],"83196862-45d1-4574-97fe-4d0975c3c77e","5410cd7e-45ea-4c1f-9b27-d8b32c9c947d"]
    2020-02-20 13:33:25:252 [WD Proxy] Matched '/element/83196862-45d1-4574-97fe-4d0975c3c77e/value' to command name 'setValue'
    2020-02-20 13:33:25:258 [Protocol Converter] Added 'value' property ["
    ","","",""] to 'setValue' request body
    2020-02-20 13:33:25:266 [WD Proxy] Proxying [POST /element/83196862-45d1-4574-97fe-4d0975c3c77e/value] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element/83196862-45d1-4574-97fe-4d0975c3c77e/value] with body: {"
    elementId":"83196862-45d1-4574-97fe-4d0975c3c77e","text":"阿里巴巴","replace":false,"unicodeKeyboard":true,"value":["","","",""]}
    2020-02-20 13:33:25:879 [WD Proxy] Got response with status 200: {"
    sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":null}
    2020-02-20 13:33:25:885 [W3C (5410cd7e)] Responding to client with driver.setValue() result: null
    2020-02-20 13:33:25:888 [HTTP] <-- POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element/83196862-45d1-4574-97fe-4d0975c3c77e/value 200 672 ms - 14
    2020-02-20 13:33:25:891 [HTTP]

    #查找元素
    2020-02-20 13:33:25:893 [HTTP] --> POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element
    2020-02-20 13:33:25:897 [HTTP] {"
    using":"id","value":"name"}
    2020-02-20 13:33:25:901 [W3C (5410cd7e)] Calling AppiumDriver.findElement() with args: ["
    id","name","5410cd7e-45ea-4c1f-9b27-d8b32c9c947d"]
    2020-02-20 13:33:25:907 [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
    2020-02-20 13:33:25:911 [BaseDriver] Waiting up to 20000 ms for condition
    2020-02-20 13:33:25:914 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:25:920 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"
    strategy":"id","selector":"name","context":"","multiple":false}
    2020-02-20 13:33:26:562 [WD Proxy] Got response with status 200: {"
    sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"ELEMENT":"50aa53fb-b95a-494a-870c-b320bd095dff","element-6066-11e4-a52e-4f735466cecf":"50aa53fb-b95a-494a-870c-b320bd095dff"}}
    2020-02-20 13:33:26:565 [W3C (5410cd7e)] Responding to client with driver.findElement() result: {"
    element-6066-11e4-a52e-4f735466cecf":"50aa53fb-b95a-494a-870c-b320bd095dff","ELEMENT":"50aa53fb-b95a-494a-870c-b320bd095dff"}
    2020-02-20 13:33:26:568 [HTTP] <-- POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element 200 673 ms - 137
    2020-02-20 13:33:26:576 [HTTP]

    #点击找到的元素
    2020-02-20 13:33:26:580 [HTTP] --> POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element/50aa53fb-b95a-494a-870c-b320bd095dff/click
    2020-02-20 13:33:26:584 [HTTP] {"
    id":"50aa53fb-b95a-494a-870c-b320bd095dff"}
    2020-02-20 13:33:26:589 [W3C (5410cd7e)] Calling AppiumDriver.click() with args: ["
    50aa53fb-b95a-494a-870c-b320bd095dff","5410cd7e-45ea-4c1f-9b27-d8b32c9c947d"]
    2020-02-20 13:33:26:598 [WD Proxy] Matched '/element/50aa53fb-b95a-494a-870c-b320bd095dff/click' to command name 'click'
    2020-02-20 13:33:26:602 [WD Proxy] Proxying [POST /element/50aa53fb-b95a-494a-870c-b320bd095dff/click] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element/50aa53fb-b95a-494a-870c-b320bd095dff/click] with body: {"
    element":"50aa53fb-b95a-494a-870c-b320bd095dff"}
    2020-02-20 13:33:26:637 [WD Proxy] Got response with status 200: {"
    sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":null}
    2020-02-20 13:33:26:640 [W3C (5410cd7e)] Responding to client with driver.click() result: null
    2020-02-20 13:33:26:646 [HTTP] <-- POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element/50aa53fb-b95a-494a-870c-b320bd095dff/click 200 64 ms - 14
    2020-02-20 13:33:26:649 [HTTP]

    #查找元素
    2020-02-20 13:33:26:666 [HTTP] --> POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element
    2020-02-20 13:33:26:677 [HTTP] {"
    using":"id","value":"current_price"}
    2020-02-20 13:33:26:706 [W3C (5410cd7e)] Calling AppiumDriver.findElement() with args: ["
    id","current_price","5410cd7e-45ea-4c1f-9b27-d8b32c9c947d"]
    2020-02-20 13:33:26:737 [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
    2020-02-20 13:33:26:746 [BaseDriver] Waiting up to 20000 ms for condition
    2020-02-20 13:33:26:751 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:26:755 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"
    strategy":"id","selector":"current_price","context":"","multiple":false}
    2020-02-20 13:33:26:850 [WD Proxy] Got an unexpected response with status 404: {"
    sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:78)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann...
    2020-02-20 13:33:26:854 [W3C] Matched W3C error code 'no such element' to NoSuchElementError
    2020-02-20 13:33:26:855 [BaseDriver] Waited for 107 ms so far
    2020-02-20 13:33:27:365 [WD Proxy] Matched '/element' to command name 'findElement'
    2020-02-20 13:33:27:371 [WD Proxy] Proxying [POST /element] to [POST http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element] with body: {"strategy":"id","selector":"current_price","context":"","multiple":false}
    2020-02-20 13:33:27:517 [WD Proxy] Got response with status 200: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":{"ELEMENT":"e3fffd26-e466-4606-b4ff-ae72e01a0635","element-6066-11e4-a52e-4f735466cecf":"e3fffd26-e466-4606-b4ff-ae72e01a0635"}}
    2020-02-20 13:33:27:522 [W3C (5410cd7e)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"e3fffd26-e466-4606-b4ff-ae72e01a0635","ELEMENT":"e3fffd26-e466-4606-b4ff-ae72e01a0635"}
    2020-02-20 13:33:27:532 [HTTP] <-- POST /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element 200 872 ms - 137
    2020-02-20 13:33:27:534 [HTTP]

    #匹配元素text属性为对应值
    2020-02-20 13:33:27:553 [HTTP] --> GET /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element/e3fffd26-e466-4606-b4ff-ae72e01a0635/text
    2020-02-20 13:33:27:554 [HTTP] {}
    2020-02-20 13:33:27:581 [W3C (5410cd7e)] Driver proxy active, passing request on via HTTP proxy
    2020-02-20 13:33:27:598 [WD Proxy] Matched '/wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element/e3fffd26-e466-4606-b4ff-ae72e01a0635/text' to command name 'getText'
    2020-02-20 13:33:27:602 [WD Proxy] Proxying [GET /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element/e3fffd26-e466-4606-b4ff-ae72e01a0635/text] to [GET http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d/element/e3fffd26-e466-4606-b4ff-ae72e01a0635/text] with body: {}
    2020-02-20 13:33:28:022 [WD Proxy] Got response with status 200: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":"222.14"}
    2020-02-20 13:33:28:026 [WD Proxy] Replacing sessionId 41523ce7-ceb5-4f96-b76b-87c9d6a6e36d with 5410cd7e-45ea-4c1f-9b27-d8b32c9c947d
    2020-02-20 13:33:28:031 [HTTP] <-- GET /wd/hub/session/5410cd7e-45ea-4c1f-9b27-d8b32c9c947d/element/e3fffd26-e466-4606-b4ff-ae72e01a0635/text 200 480 ms - 80
    2020-02-20 13:33:28:034 [HTTP]

    #脚本执行完毕关闭BaseDriver
    2020-02-20 13:34:28:038 [BaseDriver] Shutting down because we waited 60 seconds for a command

    #删除UiAutomator2 Appium session
    2020-02-20 13:34:28:045 [UiAutomator2] Deleting UiAutomator2 session
    2020-02-20 13:34:28:048 [Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability'
    2020-02-20 13:34:28:048 [Appium] Removing session 5410cd7e-45ea-4c1f-9b27-d8b32c9c947d from our master session list
    2020-02-20 13:34:28:049 [UiAutomator2] Deleting UiAutomator2 server session
    2020-02-20 13:34:28:050 [WD Proxy] Matched '/' to command name 'deleteSession'
    2020-02-20 13:34:28:051 [WD Proxy] Proxying [DELETE /] to [DELETE http://localhost:8203/wd/hub/session/41523ce7-ceb5-4f96-b76b-87c9d6a6e36d] with no body
    2020-02-20 13:34:28:096 [WD Proxy] Got response with status 200: {"sessionId":"41523ce7-ceb5-4f96-b76b-87c9d6a6e36d","value":null}

    #重置输入法
    2020-02-20 13:34:28:098 [UiAutomator2] Resetting IME to 'com.netease.nemu_vinput.nemu/com.android.inputmethodcommon.SoftKeyboard'
    2020-02-20 13:34:28:102 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 shell ime set com.netease.nemu_vinput.nemu/com.android.inputmethodcommon.SoftKeyboard'

    #删除建立的PC和手机端的转发
    2020-02-20 13:34:28:920 [Logcat] Stopping logcat capture
    2020-02-20 13:34:28:930 [ADB] Removing forwarded port socket connection: 8203
    2020-02-20 13:34:28:932 [ADB] Running 'E:\AndroidSDK\platform-tools\adb.exe -P 5037 -s 127.0.0.1\:7555 forward --remove tcp\:8203'
    2020-02-20 13:34:28:961 [Instrumentation] .
    2020-02-20 13:34:29:266 [Instrumentation] Time: 78.196
    2020-02-20 13:34:29:275 [Instrumentation]
    2020-02-20 13:34:29:277 [Instrumentation] OK (1 test)
    2020-02-20 13:34:29:486 [Instrumentation] The process has exited with code 0

    作业2+作业3


    def test_search_and_get_price_from_hk(self):
    # self.driver.find_element(MobileBy.ID, "tv_agree").click()
    self.driver.find_element(MobileBy.ID, "tv_search").click()
    self.driver.find_element(MobileBy.ID, "search_input_text").send_keys("阿里巴巴")
    self.driver.find_element(MobileBy.ID, "name").click()
    stock = (By.XPATH, "//*[contains(@resource-id, 'title_container')]//*[@text='股票']")
    self.driver.find_element(*stock).click()
    price = (By.XPATH, "//*[@text='09988']/../../..//*[contains(@resource-id, 'current_price')]")
    assert float(self.driver.find_element(*price).text) < 219
    print(self.driver.find_element(*price).get_attribute("resourceId"))

    def test_add_stock(self):
    self.driver.find_element(MobileBy.ID, "tv_search").click()
    self.driver.find_element(MobileBy.ID, "search_input_text").send_keys("alibaba")
    self.driver.find_element(MobileBy.ID, "name").click()
    #点击股票
    self.driver.find_element(MobileBy.XPATH,"//*[contains(@resource-id,'title_container')]//*[@text='股票']").click()
    #点击添加自选
    self.driver.find_element(MobileBy.XPATH,"//*[@text='BABA']/../../..//*[contains(@resource-id,'follow_btn')]").click()
    # #点击弹出框下次再说
    # self.driver.find_element(MobileBy.ID, "tv_left").click()
    #点击搜索框删除按钮
    self.driver.find_element(MobileBy.ID,"action_delete_text").click()
    #再次搜索添加的自选股票
    # self.driver.find_element(MobileBy.ID, "tv_search").click()
    self.driver.find_element(MobileBy.ID, "search_input_text").send_keys("alibaba")
    self.driver.find_element(MobileBy.ID, "name").click()
    #断言已添加
    assert "已添加" == self.driver.find_element(MobileBy.XPATH,"//*[@text='BABA']/../../..//*[contains(@resource-id,'followed_btn')]").get_attribute('text')
  • 课间作业1

    # Generated by Selenium IDE
    import pytest
    import time
    import json
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support import expected_conditions
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

    class TestDefaultSuite():
    def setup_method(self, method):
    self.driver = webdriver.Firefox()
    self.vars = {}

    def teardown_method(self, method):
    self.driver.quit()

    def test_firsttest(self):
    self.driver.get("https://testerhome.com/")
    self.driver.set_window_size(1382, 754)
    self.driver.find_element(By.LINK_TEXT, "社团").click()
    self.driver.find_element(By.LINK_TEXT, "霍格沃兹测试学院").click()
    self.driver.find_element(By.CSS_SELECTOR, ".topic-21848 .title > a").click()
    self.driver.find_element(By.CSS_SELECTOR, ".fa-close").click()

    课间作业2

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions
    from selenium.webdriver.support.wait import WebDriverWait


    class TestFirstWeb:
    def setup_method(self):
    self.driver = webdriver.Chrome()
    self.driver.get("https://testerhome.com/")
    self.driver.set_window_size(1366, 738)
    self.driver.implicitly_wait(5)

    def test_hogwarts(self):
    self.driver.find_element(By.CSS_SELECTOR, '[title = "MTSC2020 中国互联网测试开发大会议题征集"]').click()
    element_contents = (By.CSS_SELECTOR, '.toc-container > .btn')
    WebDriverWait(self.driver, 10).until((expected_conditions.element_to_be_clickable(element_contents)))
    self.driver.find_element(*element_contents).click()
    element_tablecontents = (By.CSS_SELECTOR, '.toc-item:nth-child(4) > .toc-item-link')
    WebDriverWait(self.driver, 10).until((expected_conditions.element_to_be_clickable(element_tablecontents)))
    self.driver.find_element(*element_tablecontents).click()

    def teardown_method(self):
    self.driver.quit()

    课后作业3

    在控制台输入:chrome --remote-debugging-port=9222 提前打开chrome浏览器

    import os
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.wait import WebDriverWait


    def wait(driver) -> WebDriverWait:
    return WebDriverWait(driver, 10)


    class TestWework:
    def setup_method(self):
    # 多浏览器处理
    browser = os.getenv("browser", "").lower()
    if browser == "headless":
    self.driver = webdriver.PhantomJS()
    elif browser == "firefox":
    self.driver = webdriver.Firefox()
    else:
    options = webdriver.ChromeOptions()
    options.debugger_address = "127.0.0.1:9222"
    self.driver = webdriver.Chrome(options=options)
    url = "https://work.weixin.qq.com/wework_admin/frame#index"
    self.driver.get(url)
    self.driver.implicitly_wait(5)

    def teardown_method(self):
    self.driver.quit()

    def test_wework(self):
    # 在首页点击添加成员,进入表单填写页面
    add_member_element = (By.CSS_SELECTOR, '.index_service_cnt_itemWrap:nth-child(1)')

    wait(self.driver).until((EC.element_to_be_clickable(add_member_element)))
    self.driver.find_element(*add_member_element).click()

    # ***************************定位表达式************************
    # 姓名、别名、账号、性别

    name_element = (By.CSS_SELECTOR, '#username')
    add_name_element = (By.CSS_SELECTOR, '#memberAdd_english_name')
    account_element = (By.CSS_SELECTOR, '#memberAdd_acctid')
    sex_element_man = (By.XPATH, '//*[@name="gender" and @value="1"]')
    sex_element_woman = (By.XPATH, '//*[@name="gender" and @value="2"]')

    # 手机、座机、邮箱、地址
    phone_element = (By.CSS_SELECTOR, '#memberAdd_phone')
    tel_element = (By.CSS_SELECTOR, '#memberAdd_telephone')
    email_element = (By.CSS_SELECTOR, '#memberAdd_mail')
    address_element = (By.CSS_SELECTOR, '#memberEdit_address')

    # 部门、职务input、身份
    # depart_element
    Position_element = (By.CSS_SELECTOR, '#memberAdd_title')
    Identity_com_element = (By.XPATH, '//*[@name="identity_stat" and @value="0"]')
    Identity__element = (By.XPATH, '//*[@name="identity_stat" and @value="1"]')

    # 职务单选
    Position_sync_element = (By.XPATH, '//*[@name="extern_position_set" and @value="sync"]')
    Position_custom_element = (By.XPATH, '//*[@name="extern_position_set" and @value="custom"]')

    # 保存按钮
    save_button_element = (By.XPATH, '(//a[contains(text(),"保存")])[4]')

    # 填写表单开始

    wait(self.driver).until((EC.visibility_of_element_located(name_element)))
    self.driver.find_element(*name_element).send_keys('二花')

    wait(self.driver).until((EC.visibility_of_element_located(add_name_element)))
    self.driver.find_element(*add_name_element).send_keys('1')

    wait(self.driver).until((EC.visibility_of_element_located(account_element)))
    self.driver.find_element(*account_element).send_keys('test01')

    wait(self.driver).until((EC.element_to_be_clickable(sex_element_woman)))
    self.driver.find_element(*sex_element_woman).click()

    wait(self.driver).until((EC.visibility_of_element_located(phone_element)))
    self.driver.find_element(*phone_element).send_keys('18205496845')

    wait(self.driver).until((EC.visibility_of_element_located(tel_element)))
    self.driver.find_element(*tel_element).send_keys('09135879641')

    wait(self.driver).until((EC.visibility_of_element_located(email_element)))
    self.driver.find_element(*email_element).send_keys('694673084@qq.com')

    wait(self.driver).until((EC.visibility_of_element_located(address_element)))
    self.driver.find_element(*address_element).send_keys('北京市昌平区')

    wait(self.driver).until((EC.visibility_of_element_located(Position_element)))
    self.driver.find_element(*Position_element).send_keys('测试工程师')

    wait(self.driver).until((EC.element_to_be_clickable(save_button_element)))
    self.driver.find_element(*save_button_element).click()

    # 断言添加成员是否成功
    assert "批量导入" in self.driver.page_source

  • 十一期_Python 测试_20191222 at December 22, 2019

    课间作业1


    import pytest

    from unit.div import div


    def test_div_int():
    assert div(4, 2) == 2
    assert div(10000000, 2) == 5000000
    assert div(-10, 2) == -5
    assert div(10, -2) == -5
    assert div(-2, -2) == 1


    def test_div_float():
    assert div(0.8, 0.2) == 4
    assert div(0.8, 2) == 0.4
    assert div(1, 3) == 0.33333


    def test_div_exception():
    assert div("a", 1) == None


    def test_zero_division():
    with pytest.raises(ZeroDivisionError):
    div(1, 0)

    课后作业2

    import pytest
    from unit.div import div


    @pytest.mark.parametrize("num1,num2,expect", [
    (4, 2, 2),
    (10000000, 2, 5000000),
    (-10, 2, -5),
    (10, -2, -5),
    (-2, -2, 1)])
    def test_div_int(num1, num2, expect):
    assert div(num1, num2) == expect


    @pytest.mark.parametrize("num1,num2,expect", [
    (0.8, 0.2, 4),
    (0.8, 2, 0.4),
    (1, 3, 0.33333)])
    def test_div_float(num1, num2, expect):
    assert div(num1, num2) == expect


    @pytest.mark.parametrize("num1,num2,expect", [("a", 1, None), (1, "a", None), ("adf", "f", None)])
    def test_div_exception(num1, num2, expect):
    assert div(num1, num2) == expect


    def test_zero_division():
    with pytest.raises(ZeroDivisionError) as exceptions:
    div(1, 0)
    assert exceptions.type == ZeroDivisionError

  • 课间作业1:

    curl 'https://testerhome.com/' |grep -E '<a title=".*" href=".*">[^<]*</a>$'|wc -l

    课间作业2:

    grep -o '[0-9, ]*条结果' bing.txt|awk '{print $1}'|sed 's/,//g'|sed -E 's/[0]{4,4}$/W/'

    课后作业3:

    • 1.找出log中的404 500的记录总共有多少条

    less nginx.log |awk '{print $9}'|grep -E '404|500'|wc -l
    执行结果:
    [01086491@izuf60jasqavbxb9efockpz ~]$ less nginx.log |awk '{print $9}'|grep -E '404|500'|wc -l
    267

    • 2.找出访问量最高的前三名ip

    less nginx.log |awk '{print $1}'|sort|uniq -c|sort -nr|head -3
    执行结果:
    [01086491@izuf60jasqavbxb9efockpz ~]$ less nginx.log |awk '{print $1}'|sort|uniq -c|sort -nr|head -3
    282 216.244.66.241
    130 136.243.151.90
    110 127.0.0.1

    • 3.聚类所有的url,比如把/topics/1234 /topics/2434 都聚类成 /topics/id,去掉变化的数字等元素,聚类完成后取出top10的访问量最高的路由地址

    less nginx.log |awk '{print $7}'|sed 's/topics\/[0-9]*$/topics\/id/g'|sort|uniq -c|sort -nr|head -10
    执行结果:
    [01086491@izuf60jasqavbxb9efockpz ~]$ less nginx.log |awk '{print $7}'|sed 's/topics\/[0-9]*$/topics\/id/g'|sort|uniq -c|sort -nr|head -10
    584 /cable
    237 /topics/id
    94 /
    7 /account/sign_in
    6 /topics/feed
    4 /topics
    4 /oauth/token
    3 /hogwarts
    2 /uploads/user/avatar/39358/751c8a.png!sm
    2 /uploads/photo/2018/72ebfdc3-8a3d-4c1a-9e7f-6a6bc73c504e.png!large

  • 课间作业

    def test_get_login():
    url="https://testerhome.com/api/v3/topics.json"
    params={"limit":3}
    r=requests.get(url,params=params)
    result=r.json()['topics'][-1]['user']['login']
    assert result == 'liangqiangWang'

    def test_xueqiu_search():
    url="https://xueqiu.com/stock/search.json"
    param={"code":"sogo","size":3,"page":1}
    header={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36",
    "Accept":"application/json",
    #"Cookie": "aliyungf_tc=AQAAAPcbdguWQQwAnonY3ZRV7lyXgyZo; acw_tc=2760822215709536378096462eed0137cd88ccae322415e4ccca9899fefad3; xq_a_token=d831cd39b53563679545656fba1f4efd8e48faa0; xq_r_token=fd2f0f487c8298cad8e7519f1560abb7a18c589d; u=371570953639944; device_id=24700f9f1986800ab4fcc880530dd0ed; Hm_lvt_1db88642e346389874251b5a1eded6e3=1570953642; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1571239059"
    }
    cookie={"xq_a_token":"d831cd39b53563679545656fba1f4efd8e48faa0"}
    result=requests.get(url,params=param,headers=header,cookies=cookie).json()
    assert result['stocks'][0]['name'] == '搜狗'

    课后作业

    def test_get_token():
    url="https://qyapi.weixin.qq.com/cgi-bin/gettoken"
    ID="xxx"
    SECRET="xxx"
    param={"corpid":ID,"corpsecret":SECRET}
    try:
    result=requests.get(url,params=param).json()
    if result["errcode"] ==0:
    access_token = result["access_token"]
    else:
    logging.info(result["errmsg"])
    except Exception as e:
    logging.error(e)
    return access_token
  • 课后作业

    import logging
    import pytest

    logging.basicConfig(level=logging.DEBUG)

    def setup_module():
    logging.info("login")

    def teardown_module():
    logging.info("整个module完成执行数据清理")

    class TestA:

    @classmethod
    def teardown_class(cls):
    logging.info("TestA_teardown 环境清理")

    def test_1(self):
    logging.info("test_1")
    assert 1==1

    def test_2(self):
    logging.info("test_2")
    assert 1 == 1

    def test_3(self):
    logging.info("test_3")
    assert 1 == 1

    class TestB:

    def setup_method(self):
    logging.info("testB_每个方法都要初始化")

    def test_4(self):
    logging.info("test_4")
    assert 1 == 1

    def test_5(self):
    logging.info("test_5")
    assert 1 == 1

    @pytest.mark.parametrize("a,b",[(2,2),(1,1),(3,4)])
    def test_6(self,a,b):
    logging.info("test_6")
    assert a == b

    class TestC:

    @pytest.mark.run(order=3)
    def test_7(self):
    logging.info("test_7")
    assert 1 == 1

    @pytest.mark.run(order=1)
    def test_8(self):
    logging.info("test_8")
    assert 1 == 2

    @pytest.mark.run(order=2)
    def test_9(self):
    logging.info("test_9")
    assert 1 == 1

    报告截图