请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师,多线程启动脚本,只有一个app会找到页面元素,另一个就找不到页面元素了

我启动后两个都可以打开慕课网进入登陆界面

模拟器1输入账号密码登录模拟器2就报错说找不到页面元素没法输入账号密码
有时两个反过来模拟器2找得到模拟器1找不到

这是base_driver的代码

class BaseDriver():
def android_driver(self, i):
ini = ReadIni(node=“server_port”, file_name=r"D:\测试\自动化测试\App自动化测试\Appnium\config\userconfig.ini")
deviceName = ini.get_value(“devices” + str(i))
port = ini.get_value(“appium_port” + str(i))
capabilities = {
“platformName”: “Android”,
“automationName”: “UiAutomator2”,
“deviceName”: deviceName,
“app”: “D:\测试\APPnium\mukewang.apk”,
“noReset”: “true”
}
driver = webdriver.Remote(“127.0.0.1:” + port +"/wd/hub", capabilities)
time.sleep(5)
return driver

这是case页面的代码

class ParamTestCase(unittest.TestCase):
def init(self, methodName=‘runTest’, param=None):
super(ParamTestCase, self).init(methodName)
self.param = param
global params
params = param

class LoginCaseTest(ParamTestCase):

@classmethod
def setUpClass(cls):
    base_driver = BaseDriver()
    cls.driver = base_driver.android_driver(params)
    time.sleep(10)
    cls.login_business = LoginBusiness(cls.driver)

def test_login_pass(self):
    self.login_business.login_pass()

def get_suite(i):
suite = unittest.TestSuite()
# for name in testnames:
suite.addTest(LoginCaseTest(“test_login_pass”, param=i))
unittest.TextTestRunner().run(suite)

if name == “main”:
se = Server()
se.start_server_thread()
threads = []
for i in range(2):
t = threading.Thread(target=get_suite, args=(i,))
threads.append(t)
for j in threads:
j.start()

这是部分日志
[AndroidDriver] Granting android.permission.SET_ANIMATION_SCALE, CHANGE_CONFIGURATION, ACCESS_FINE_LOCATION by pm grant
[debug] [AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
[debug] [ADB] Granting permissions [“android.permission.SET_ANIMATION_SCALE”,“android.permission.CHANGE_CONFIGURATION”,“android.permission.ACCESS_FINE_LOCATION”] to ‘io.appium.settings’
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell settings put secure mock_location 1’
[debug] [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”,";"]]
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 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 ;’
[debug] [Logcat] Starting logcat capture
[debug] [UiAutomator2] Forwarding UiAutomator2 Server port 6790 to 8200
[debug] [ADB] Forwarding system: 8200 to device: 6790
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 forward tcp:8200 tcp:6790’
[debug] [ADB] Getting install status for io.appium.uiautomator2.server
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell dumpsys package io.appium.uiautomator2.server’
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell am start -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER’
[debug] [ADB] ‘io.appium.uiautomator2.server’ is installed
[debug] [ADB] Getting package info for ‘io.appium.uiautomator2.server’
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell dumpsys package io.appium.uiautomator2.server’
[debug] [ADB] The version name of the installed ‘io.appium.uiautomator2.server’ is greater or equal to the application version name (‘4.5.5’ >= ‘4.5.5’)
[debug] [UiAutomator2] io.appium.uiautomator2.server installation state: sameVersionInstalled
[debug] [ADB] Checking app cert for D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-v4.5.5.apk
[ADB] Found 0 ‘build-tools’ folders under ‘’ (newest first):
[ADB] Cannot use apksigner tool for signature verification. Original error: Could not find ‘apksigner.bat’ in [“D:\测试\自动化测试\App自动化测试\Appnium\case\platform-tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\emulator\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\bin\apksigner.bat”]. Do you have Android Build Tools installed at ‘’?
[debug] [ADB] Defaulting to verify.jar
[debug] [ADB] ‘D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-v4.5.5.apk’ is already signed.
[debug] [ADB] Getting install status for io.appium.uiautomator2.server.test
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell dumpsys package io.appium.uiautomator2.server.test’
[debug] [ADB] ‘io.appium.uiautomator2.server.test’ is installed
[debug] [ADB] Checking app cert for D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-debug-androidTest.apk
[ADB] Cannot use apksigner tool for signature verification. Original error: Could not find ‘apksigner.bat’ in [“D:\测试\自动化测试\App自动化测试\Appnium\case\platform-tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\emulator\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\bin\apksigner.bat”]. Do you have Android Build Tools installed at ‘’?
[debug] [ADB] Defaulting to verify.jar
[debug] [ADB] ‘D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-debug-androidTest.apk’ is already signed.
[UiAutomator2] Server packages are not going to be (re)installed
[debug] [UiAutomator2] Waiting up to 30000ms for services to be available
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell pm list instrumentation’
[debug] [ADB] Getting IDs of all ‘io.appium.settings’ processes
[debug] [ADB] Using ps-based PID detection
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell ps’
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell settings put secure mock_location 1’
[debug] [UiAutomator2] Instrumentation target ‘io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner’ is available
[debug] [ADB] Checking app cert for D:测试APPniummukewang.apk
[ADB] Cannot use apksigner tool for signature verification. Original error: Could not find ‘apksigner.bat’ in [“D:\测试\自动化测试\App自动化测试\Appnium\case\platform-tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\emulator\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\bin\apksigner.bat”]. Do you have Android Build Tools installed at ‘’?
[debug] [ADB] Defaulting to verify.jar
[debug] [Logcat] Starting logcat capture
[debug] [ADB] ‘D:测试APPniummukewang.apk’ is already signed.
[debug] [ADB] Getting install status for cn.com.open.mooc
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell dumpsys package cn.com.open.mooc’
[debug] [ADB] ‘cn.com.open.mooc’ is installed
[debug] [ADB] Getting package info for ‘cn.com.open.mooc’
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell dumpsys package cn.com.open.mooc’
[debug] [ADB] The version name of the installed ‘cn.com.open.mooc’ is greater or equal to the application version name (‘5.1.2’ >= ‘5.1.2’)
[debug] [ADB] There is no need to install/upgrade ‘D:测试APPniummukewang.apk’
[debug] [UiAutomator2] Performing shallow cleanup of automation leftovers
[debug] [UiAutomator2] No obsolete sessions have been detected (Error: read ECONNRESET)
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell am force-stop io.appium.uiautomator2.server.test’
[debug] [UiAutomator2] Forwarding UiAutomator2 Server port 6790 to 8201
[debug] [ADB] Forwarding system: 8201 to device: 6790
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 forward tcp:8201 tcp:6790’
[debug] [ADB] Getting install status for io.appium.uiautomator2.server
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell dumpsys package io.appium.uiautomator2.server’
[debug] [ADB] ‘io.appium.uiautomator2.server’ is installed
[debug] [ADB] Getting package info for ‘io.appium.uiautomator2.server’
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell dumpsys package io.appium.uiautomator2.server’
[debug] [ADB] The version name of the installed ‘io.appium.uiautomator2.server’ is greater or equal to the application version name (‘4.5.5’ >= ‘4.5.5’)
[debug] [UiAutomator2] io.appium.uiautomator2.server installation state: sameVersionInstalled
[debug] [ADB] Checking app cert for D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-v4.5.5.apk
[ADB] Found 0 ‘build-tools’ folders under ‘’ (newest first):
[ADB] Cannot use apksigner tool for signature verification. Original error: Could not find ‘apksigner.bat’ in [“D:\测试\自动化测试\App自动化测试\Appnium\case\platform-tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\emulator\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\bin\apksigner.bat”]. Do you have Android Build Tools installed at ‘’?
[debug] [ADB] Defaulting to verify.jar
[debug] [ADB] ‘D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-v4.5.5.apk’ is already signed.
[debug] [ADB] Getting install status for io.appium.uiautomator2.server.test
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell dumpsys package io.appium.uiautomator2.server.test’
[debug] [ADB] ‘io.appium.uiautomator2.server.test’ is installed
[debug] [ADB] Checking app cert for D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-debug-androidTest.apk
[ADB] Cannot use apksigner tool for signature verification. Original error: Could not find ‘apksigner.bat’ in [“D:\测试\自动化测试\App自动化测试\Appnium\case\platform-tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\emulator\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\bin\apksigner.bat”]. Do you have Android Build Tools installed at ‘’?
[debug] [ADB] Defaulting to verify.jar
[UiAutomator2] Starting UIAutomator2 server 4.5.5
[UiAutomator2] Using UIAutomator2 server from ‘D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-v4.5.5.apk’ and test from ‘D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-debug-androidTest.apk’
[UiAutomator2] Waiting up to 30000ms for UiAutomator2 to be online…
[debug] [ADB] Creating ADB subprocess with args: ["-P",5037,"-s",“127.0.0.1:62001”,“shell”,“am”,“instrument”,"-w",“io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner”]
[debug] [ADB] ‘D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-debug-androidTest.apk’ is already signed.
[UiAutomator2] Server packages are not going to be (re)installed
[debug] [UiAutomator2] Waiting up to 30000ms for services to be available
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell pm list instrumentation’
[debug] [Instrumentation] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:
[debug] [UiAutomator2] Instrumentation target ‘io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner’ is available
[debug] [ADB] Checking app cert for D:测试APPniummukewang.apk
[ADB] Cannot use apksigner tool for signature verification. Original error: Could not find ‘apksigner.bat’ in [“D:\测试\自动化测试\App自动化测试\Appnium\case\platform-tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\emulator\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\apksigner.bat”,“D:\测试\自动化测试\App自动化测试\Appnium\case\tools\bin\apksigner.bat”]. Do you have Android Build Tools installed at ‘’?
[debug] [ADB] Defaulting to verify.jar
[debug] [ADB] ‘D:测试APPniummukewang.apk’ is already signed.
[debug] [ADB] Getting install status for cn.com.open.mooc
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell dumpsys package cn.com.open.mooc’
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8200/wd/hub/status] with no body
[WD Proxy] Got an unexpected response with status undefined: {“errno”:“ECONNRESET”,“code”:“ECONNRESET”,“syscall”:“read”}
[debug] [ADB] ‘cn.com.open.mooc’ is installed
[debug] [ADB] Getting package info for ‘cn.com.open.mooc’
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell dumpsys package cn.com.open.mooc’
[debug] [ADB] The version name of the installed ‘cn.com.open.mooc’ is greater or equal to the application version name (‘5.1.2’ >= ‘5.1.2’)
[debug] [ADB] There is no need to install/upgrade ‘D:测试APPniummukewang.apk’
[debug] [UiAutomator2] Performing shallow cleanup of automation leftovers
[debug] [UiAutomator2] No obsolete sessions have been detected (Error: read ECONNRESET)
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell am force-stop io.appium.uiautomator2.server.test’
[UiAutomator2] Starting UIAutomator2 server 4.5.5
[UiAutomator2] Using UIAutomator2 server from ‘D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-v4.5.5.apk’ and test from ‘D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-uiautomator2-server@4.5.5@appium-uiautomator2-serverapksappium-uiautomator2-server-debug-androidTest.apk’
[UiAutomator2] Waiting up to 30000ms for UiAutomator2 to be online…
[debug] [ADB] Creating ADB subprocess with args: ["-P",5037,"-s",“127.0.0.1:62025”,“shell”,“am”,“instrument”,"-w",“io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner”]
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8200/wd/hub/status] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“None”,“value”:{“ready”:true,“message”:“UiAutomator2 Server is ready to accept commands”}}
[debug] [UiAutomator2] The initialization of the instrumentation process took 2022ms
[debug] [WD Proxy] Matched ‘/session’ to command name ‘createSession’
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8200/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”,“udid”:“127.0.0.1:62001”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62001”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true},“platformName”:“Android”,“udid”:“127.0.0.1:62001”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62001”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true,“deviceUDID”:“127.0.0.1:62001”,“appPackage”:“cn.com.open.mooc”}],“alwaysMatch”:{}}}
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“da21a83c-c304-4fbd-9138-317a8c0fed70”,“value”:{“sessionId”:“da21a83c-c304-4fbd-9138-317a8c0fed70”,“capabilities”:{“firstMatch”:[{“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“platformName”:“Android”,“udid”:“127.0.0.1:62001”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62001”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true},“platformName”:“Android”,“udid”:“127.0.0.1:62001”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62001”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true,“deviceUDID”:“127.0.0.1:62001”,“appPackage”:“cn.com.open.mooc”}],“alwaysMatch”:{}}}}
[WD Proxy] Determined the downstream protocol as ‘W3C’
[debug] [WD Proxy] Proxying [GET /appium/device/info] to [GET http://127.0.0.1:8200/wd/hub/session/da21a83c-c304-4fbd-9138-317a8c0fed70/appium/device/info] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“da21a83c-c304-4fbd-9138-317a8c0fed70”,“value”:{“androidId”:“b4b686d23a9a6886”,“manufacturer”:“HUAWEI”,“model”:“HUAWEI MLA-AL10”,“brand”:“HUAWEI”,“apiVersion”:“22”,“platformVersion”:“5.1.1”,“carrierName”:“CHINA MOBILE”,“realDisplaySize”:“900x1600”,“displayDensity”:320,“networks”:[{“type”:1,“typeName”:“WIFI”,“subtype”:0,“subtypeName”:"",“isConnected”:true,“detailedState”:“CONNECTED”,“state”:“CONNECTED”,“extraInfo”:"“WiredSSID”",“isAvailable”:true,“isFailover”:false,“isRoaming”:false,“capabilities”:{“transportTypes”:“TRANSPORT_WIFI”,“networkCapabilities”:“NET_CAPABILITY_NOT_RESTRICTED,NET_CAPABILITY_NOT_VPN,NET_CAPABILITY_INTERNET,NET_CAPABILITY_TRUSTED”,“linkUpstreamBandwidthKbps”:1048576,“linkDownBandwidthKbps”:1048576,“signalStrength”:null,“networkSpecifier”:null,“SSID”:null}}],“locale”:“zh_CN”,“timeZone”:“Asia/Shanghai”,“bluetooth”:{“state”:“OFF”}}}
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell dumpsys window’
[AndroidDriver] Screen already unlocked, doing nothing
[UiAutomator2] Starting 'cn.com.open.mooc/cn.com.open.mooc.index.splash.MCSplashActivity and waiting for ‘cn.com.open.mooc/cn.com.open.mooc.index.splash.MCSplashActivity’
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell am start -W -n cn.com.open.mooc/cn.com.open.mooc.index.splash.MCSplashActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000’
[debug] [Instrumentation] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8201/wd/hub/status] with no body
[WD Proxy] Got an unexpected response with status undefined: {“errno”:“ECONNRESET”,“code”:“ECONNRESET”,“syscall”:“read”}
[debug] [ADB] Waiting up to 20000ms for activity matching pkg: ‘cn.com.open.mooc’ and activity: ‘cn.com.open.mooc.index.splash.MCSplashActivity’ to be focused
[debug] [ADB] Possible activities, to be checked: ‘cn.com.open.mooc.index.splash.MCSplashActivity’, ‘cn.com.open.mooc.cn.com.open.mooc.index.splash.MCSplashActivity’
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell dumpsys window windows’
[debug] [ADB] Found package: ‘cn.com.open.mooc’ and fully qualified activity name : ‘cn.com.open.mooc.index.splash.MCSplashActivity’
[debug] [WD Proxy] Proxying [GET /appium/device/pixel_ratio] to [GET http://127.0.0.1:8200/wd/hub/session/da21a83c-c304-4fbd-9138-317a8c0fed70/appium/device/pixel_ratio] with body: {}
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“da21a83c-c304-4fbd-9138-317a8c0fed70”,“value”:2}
[debug] [WD Proxy] Matched ‘/appium/device/system_bars’ to command name ‘getSystemBars’
[debug] [WD Proxy] Proxying [GET /appium/device/system_bars] to [GET http://127.0.0.1:8200/wd/hub/session/da21a83c-c304-4fbd-9138-317a8c0fed70/appium/device/system_bars] with body: {}
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“da21a83c-c304-4fbd-9138-317a8c0fed70”,“value”:{“statusBar”:50}}
[debug] [WD Proxy] Matched ‘/window/current/size’ to command name ‘getWindowSize’
[debug] [WD Proxy] Proxying [GET /window/current/size] to [GET http://127.0.0.1:8200/wd/hub/session/da21a83c-c304-4fbd-9138-317a8c0fed70/window/current/size] with body: {}
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“da21a83c-c304-4fbd-9138-317a8c0fed70”,“value”:{“height”:1600,“width”:900}}
[Appium] New AndroidUiautomator2Driver session created successfully, session 45014a2a-2eb0-46b3-a2de-37db0165f5a9 added to master session list
[debug] [BaseDriver] Event ‘newSessionStarted’ logged at 1581828864009 (12:54:24 GMT+0800 (GMT+08:00))
[debug] [W3C (45014a2a)] Cached the protocol value ‘W3C’ for the new session 45014a2a-2eb0-46b3-a2de-37db0165f5a9
[debug] [W3C (45014a2a)] 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”,“udid”:“127.0.0.1:62001”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62001”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true},“platformName”:“Android”,“udid”:“127.0.0.1:62001”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62001”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true,“deviceUDID”:“127.0.0.1:62001”,“appPackage”:“cn.com.open.mooc”,“deviceApiLevel”:22,“platformVersion”:“5.1.1”,“deviceScreenSize”:“900x1600”,“deviceScreenDensity”:320,“deviceModel”:“HUAWEI MLA-AL10”,“deviceManufacturer”:“HUAWEI”,“pixelRatio”:2,“statBarHeight”:50,“viewportRect”:{“left”:0,“top”:50,“width”:900,“height”:1550}}}
[HTTP] <-- POST /wd/hub/session 200 6751 ms - 947
[HTTP]
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8201/wd/hub/status] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“None”,“value”:{“ready”:true,“message”:“UiAutomator2 Server is ready to accept commands”}}
[debug] [UiAutomator2] The initialization of the instrumentation process took 2058ms
[debug] [WD Proxy] Matched ‘/session’ to command name ‘createSession’
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8201/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”,“udid”:“127.0.0.1:62025”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62025”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true},“platformName”:“Android”,“udid”:“127.0.0.1:62025”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62025”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true,“deviceUDID”:“127.0.0.1:62025”,“appPackage”:“cn.com.open.mooc”}],“alwaysMatch”:{}}}
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3”,“value”:{“sessionId”:“93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3”,“capabilities”:{“firstMatch”:[{“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“platformName”:“Android”,“udid”:“127.0.0.1:62025”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62025”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true},“platformName”:“Android”,“udid”:“127.0.0.1:62025”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62025”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true,“deviceUDID”:“127.0.0.1:62025”,“appPackage”:“cn.com.open.mooc”}],“alwaysMatch”:{}}}}
[WD Proxy] Determined the downstream protocol as ‘W3C’
[debug] [WD Proxy] Proxying [GET /appium/device/info] to [GET http://127.0.0.1:8201/wd/hub/session/93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3/appium/device/info] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3”,“value”:{“androidId”:“1b4b686d23a9a730”,“manufacturer”:“Xiaomi”,“model”:“MI 9”,“brand”:“Xiaomi”,“apiVersion”:“22”,“platformVersion”:“5.1.1”,“carrierName”:“CHINA MOBILE”,“realDisplaySize”:“900x1600”,“displayDensity”:320,“networks”:[{“type”:1,“typeName”:“WIFI”,“subtype”:0,“subtypeName”:"",“isConnected”:true,“detailedState”:“CONNECTED”,“state”:“CONNECTED”,“extraInfo”:"“WiredSSID”",“isAvailable”:true,“isFailover”:false,“isRoaming”:false,“capabilities”:{“transportTypes”:“TRANSPORT_WIFI”,“networkCapabilities”:“NET_CAPABILITY_NOT_RESTRICTED,NET_CAPABILITY_NOT_VPN,NET_CAPABILITY_INTERNET,NET_CAPABILITY_TRUSTED”,“linkUpstreamBandwidthKbps”:1048576,“linkDownBandwidthKbps”:1048576,“signalStrength”:null,“networkSpecifier”:null,“SSID”:null}}],“locale”:“zh_CN”,“timeZone”:“Asia/Shanghai”,“bluetooth”:{“state”:“OFF”}}}
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell dumpsys window’
[AndroidDriver] Screen already unlocked, doing nothing
[UiAutomator2] Starting 'cn.com.open.mooc/cn.com.open.mooc.index.splash.MCSplashActivity and waiting for ‘cn.com.open.mooc/cn.com.open.mooc.index.splash.MCSplashActivity’
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell am start -W -n cn.com.open.mooc/cn.com.open.mooc.index.splash.MCSplashActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000’
[debug] [ADB] Waiting up to 20000ms for activity matching pkg: ‘cn.com.open.mooc’ and activity: ‘cn.com.open.mooc.index.splash.MCSplashActivity’ to be focused
[debug] [ADB] Possible activities, to be checked: ‘cn.com.open.mooc.index.splash.MCSplashActivity’, ‘cn.com.open.mooc.cn.com.open.mooc.index.splash.MCSplashActivity’
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62025 shell dumpsys window windows’
[debug] [ADB] Found package: ‘cn.com.open.mooc’ and fully qualified activity name : ‘cn.com.open.mooc.index.splash.MCSplashActivity’
[debug] [WD Proxy] Proxying [GET /appium/device/pixel_ratio] to [GET http://127.0.0.1:8201/wd/hub/session/93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3/appium/device/pixel_ratio] with body: {}
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3”,“value”:2}
[debug] [WD Proxy] Matched ‘/appium/device/system_bars’ to command name ‘getSystemBars’
[debug] [WD Proxy] Proxying [GET /appium/device/system_bars] to [GET http://127.0.0.1:8201/wd/hub/session/93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3/appium/device/system_bars] with body: {}
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3”,“value”:{“statusBar”:50}}
[debug] [WD Proxy] Matched ‘/window/current/size’ to command name ‘getWindowSize’
[debug] [WD Proxy] Proxying [GET /window/current/size] to [GET http://127.0.0.1:8201/wd/hub/session/93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3/window/current/size] with body: {}
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3”,“value”:{“height”:1600,“width”:900}}
[Appium] New AndroidUiautomator2Driver session created successfully, session e865f30f-d902-4705-84a8-931af42f00b4 added to master session list
[debug] [BaseDriver] Event ‘newSessionStarted’ logged at 1581828866005 (12:54:26 GMT+0800 (GMT+08:00))
[debug] [W3C (e865f30f)] Cached the protocol value ‘W3C’ for the new session e865f30f-d902-4705-84a8-931af42f00b4
[debug] [W3C (e865f30f)] 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”,“udid”:“127.0.0.1:62025”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62025”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true},“platformName”:“Android”,“udid”:“127.0.0.1:62025”,“automationName”:“UiAutomator2”,“deviceName”:“127.0.0.1:62025”,“app”:“D:\测试\APPnium\mukewang.apk”,“noReset”:true,“deviceUDID”:“127.0.0.1:62025”,“appPackage”:“cn.com.open.mooc”,“deviceApiLevel”:22,“platformVersion”:“5.1.1”,“deviceScreenSize”:“900x1600”,“deviceScreenDensity”:320,“deviceModel”:“MI 9”,“deviceManufacturer”:“Xiaomi”,“pixelRatio”:2,“statBarHeight”:50,“viewportRect”:{“left”:0,“top”:50,“width”:900,“height”:1550}}}
[HTTP] <-- POST /wd/hub/session 200 8747 ms - 936

[HTTP] --> POST /wd/hub/session/e865f30f-d902-4705-84a8-931af42f00b4/element
[HTTP] {“using”:“id”,“value”:“cn.com.open.mooc:id/account_edit”}
[debug] [W3C (e865f30f)] Calling AppiumDriver.findElement() with args: [“id”,“cn.com.open.mooc:id/account_edit”,“e865f30f-d902-4705-84a8-931af42f00b4”]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [WD Proxy] Matched ‘/element’ to command name ‘findElement’
[debug] [WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:8201/wd/hub/session/93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3/element] with body: {“strategy”:“id”,“selector”:“cn.com.open.mooc:id/account_edit”,“context”:"",“multiple”:false}
[WD Proxy] Got an unexpected response with status 404: {“sessionId”:“93eb6b2b-e550-41d3-a0ec-3d7d5f5e88e3”,“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
at io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:78)
at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)
at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)
at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)
at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:51)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.chann…
[debug] [W3C] Matched W3C error code ‘no such element’ to NoSuchElementError
[debug] [W3C (e865f30f)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
[debug] [W3C (e865f30f)] at AndroidUiautomator2Driver.findElOrEls (D:
odejs
ode_global
ode_modulesappium
ode_modules_appium-android-driver@4.24.0@appium-android-driverlibcommandsind.js:75:11)
[HTTP] <-- POST /wd/hub/session/e865f30f-d902-4705-84a8-931af42f00b4/element 404 29 ms - 433
[HTTP]
E

ERROR: test_login_pass (main.LoginCaseTest)

Traceback (most recent call last):
File “D:测试自动化测试App自动化测试Appniumpagesase_page.py”, line 34, in get_element
return WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(locator))
File “C:Users刘杰AppDataLocalProgramsPythonPython37libsite-packagesseleniumwebdriversupportwait.py”, line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “D:/测试/自动化测试/App自动化测试/Appnium/case/login_case.py”, line 35, in test_login_pass
self.login_business.login_pass()
File “D:测试自动化测试App自动化测试AppniumBusinesslogin_business.py”, line 29, in login_pass
self.login_handle.send_username(‘15226499639’)
File “D:测试自动化测试App自动化测试Appniumhandlelogin_handle.py”, line 14, in send_username
self.login_page.get_username_element().send_keys(username)
File “D:测试自动化测试App自动化测试Appniumpageslogin_page.py”, line 18, in get_username_element
return self.base.get_element(“username”)
File “D:测试自动化测试App自动化测试Appniumpagesase_page.py”, line 37, in get_element
raise TimeoutException(msg=“定位元素失败定位方式是:{}”.format(locator))
selenium.common.exceptions.TimeoutException: Message: 定位元素失败定位方式是:(‘id’, ‘cn.com.open.mooc:id/account_edit’)


Ran 1 test in 33.858s

FAILED (errors=1)
[BaseDriver] Shutting down because we waited 60 seconds for a command
[Appium] Closing session, cause was ‘New Command Timeout of 60 seconds expired. Try customizing the timeout using the ‘newCommandTimeout’ desired capability’
[Appium] Removing session ‘45014a2a-2eb0-46b3-a2de-37db0165f5a9’ from our master session list
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [UiAutomator2] Deleting UiAutomator2 server session
[debug] [WD Proxy] Matched ‘/’ to command name ‘deleteSession’
[debug] [WD Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:8200/wd/hub/session/da21a83c-c304-4fbd-9138-317a8c0fed70] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“da21a83c-c304-4fbd-9138-317a8c0fed70”,“value”:null}
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 shell am force-stop cn.com.open.mooc’
[debug] [Instrumentation] .
[debug] [Logcat] Stopping logcat capture
[debug] [ADB] Removing forwarded port socket connection: 8200
[debug] [ADB] Running ‘D:sdkplatform-toolsadb.exe -P 5037 -s 127.0.0.1:62001 forward --remove tcp:8200’

[debug] [Instrumentation] OK (1 test)
[debug] [Instrumentation] The process has exited with code 0

图片描述

正在回答 回答被采纳积分+3

插入代码

2回答

提问者 weixin_慕雪2209780 2020-02-19 15:38:58

https://img1.sycdn.imooc.com//szimg/5e4ce52a09fc39ca17581047.jpg

老师,我手动打开的2个appium服务,还是报这个错

selenium.common.exceptions.StaleElementReferenceException: Message: The element 'By.id: cn.com.open.mooc:id/login_lable' does not exist in DOM anymore

他还是找不到元素啊,你看,右边的模拟器成功登录,左边的报错

import multiprocessing
import time
from appium import webdriver


def base_driver(i):
   if i == 0:
       capabilities = {
           "platformName": "Android",
           # "automationName": "UiAutomator2",
           "deviceName": "62001",
           "app": "D:\\测试\\APPnium\\mukewang.apk",
           "noReset": "true"
       }
       driver = webdriver.Remote("127.0.0.1:4700/wd/hub", capabilities)
   else:
       capabilities = {
           "platformName": "Android",
           # "automationName": "UiAutomator2",
           "deviceName": "62025",
           "app": "D:\\测试\\APPnium\\mukewang.apk",
           "noReset": "true"
       }
       driver = webdriver.Remote("127.0.0.1:4701/wd/hub", capabilities)
   time.sleep(5)
   return driver


def test_case01(i):
   driver = base_driver(i)
   time.sleep(10)
   driver.find_element_by_id("cn.com.open.mooc:id/account_edit").send_keys('15226499639')
   driver.find_element_by_id("cn.com.open.mooc:id/password_edit").send_keys('qwer123456')
   driver.find_element_by_id("cn.com.open.mooc:id/login_lable").click()


if __name__ == "__main__":
   threads = []
   for i in range(2):
       t = multiprocessing.Process(target=test_case01, args=(i,))
       threads.append(t)
   for j in threads:
       j.start()


这就是全部代码,没有导入其他文件了,还是报错,我也不知道怎么回事,请老师指点

0 回复 有任何疑惑可以回复我~
Mushishi 2020-02-18 09:51:39

定位元素失败定位方式是:(‘id’, ‘cn.com.open.mooc:id/account_edit’) 1、这个后面又讲解多进程执行,你先往后看。

0 回复 有任何疑惑可以回复我~
  • 提问者 weixin_慕雪2209780 #1
    老师,我往后面看了,多进程也一样的,但是模拟器我关了前面的,就可以同时运行两个模拟器,但是最多10分钟,又会报错,早不到元素,我又得新开一个模拟器
    回复 有任何疑惑可以回复我~ 2020-02-18 11:36:07
  • Mushishi 回复 提问者 weixin_慕雪2209780 #2
    我猜测还是你得传递参数那里混淆了,我建议你先用两个最简单得driver生成了,然后就手动启动俩服务端口,然后通过多进程直接去跑 生成得driver然后去定位元素。然后去看是否报错
    回复 有任何疑惑可以回复我~ 2020-02-19 13:55:39
  • 提问者 weixin_慕雪2209780 回复 Mushishi #3
    试了试,还是报错,没得用,找不到原因
    回复 有任何疑惑可以回复我~ 2020-02-19 15:39:29
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号