留个言
报名的来顶个~
#8 楼 @xiaoafeizt
如果是要依次执行,直接用平行的 try-except 就好
try:
driver.find_element_by_name('允许').click()
except NoSuchElementException:
pass
try:
driver.find_element_by_name('切换').click()
except NoSuchElementException:
pass
try:
driver.find_element_by_id('com.tuniu.app.ui:id/iv_close').click()
except NoSuchElementException:
pass
try:
driver.find_element_by_id('com.tuniu.app.ui:id/iv_style3_card_1').click()
except ...
不过这样写的话 中间有报错的会直接跳过,你的操作依赖步骤的话可能会导致后续操作失败
应该这样写
try:
driver.find_element_by_name('允许').click()
except NoSuchElementException:
try:
driver.find_element_by_name('切换').click()
except NoSuchElementException:
try:
driver.find_element_by_id('com.tuniu.app.ui:id/iv_close').click()
except NoSuchElementException:
try:
driver.find_element_by_id('com.tuniu.app.ui:id/iv_style3_card_1').click()
except ...
多重 try-except 嵌套
你的写法 except 之间是并列的,尝试捕获的都是driver.find_element_by_name('允许').click()
的异常,
所以第二个driver.find_element_by_name('切换').click()
仍会抛出异常
人生苦短,我用 python
因为嫌 HTMLTestRunner 的报告风格太丑,所以我自己用 bootstrap 写了个测试报告模板
在每个测试进行的时候将测试编号、名称、结果、耗时以及想要返回的内容直接保存之后再将对应内容填充到测试报告的模板中形成测试报告,感觉还是比 HTMLTestRunner 的美观些
如下图 灰色部分默认是隐藏的点击查看可以展开
指的是 封装常用的业务逻辑 这个么
嗯,我之前也考虑不在用例中输入实际数据,而是用某个或某类关键字代替,执行时根据关键字自动生成或者从某处 取得数据,然后感觉这样实现起来成本太高。
另一个考虑就是直接在 page object 中封装常用的业务逻辑,这样只要传入所需参数就能执行某一个业务逻辑。
不知道您手头又没有在做 web 自动化这块,可否分享下您项目是如何进行的?
#5 楼 @chrisjywu 多谢回复 特意查看确认了版本 1.4.16 不过目前我已经找开发通过 xposed 框架 hook 的方式获取到了 toast 文本信息 既然实在起不来就换条路走走
因为想获取 toast 提示信息,尝试 以 Selendroid 模式启动 Appium 但是一直报错提示建立新 session 失败 如下
def setUp(self):
desired_caps={}
desired_caps['device'] = 'android'
desired_caps['platformName']='Android'
desired_caps['automationName']='Selendroid'
desired_caps['browserName']=''
desired_caps['noReset'] = True
desired_caps['platformVersion']='4.3'
desired_caps['deviceName']='SM-G7108V'
desired_caps['app'] = PATH('C:\Program Files (x86)\Appium\golo.apk')
报错信息如下:
Traceback (most recent call last):
File "C:\Users\Win-Attack\Desktop\test_get_toast.py", line 53, in setUp
self.driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
File "C:\Python27\lib\site-packages\appium\webdriver\webdriver.py", line 36, in __init__
super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: A new session could not be created. (Original error: Required platform doesn't exist (API level >= 17))
求解~希望各位大神帮助~ 或者有没有其他方式获取到 toast 进行比对 多谢各位啦
#2 楼 @yzx200712256 多谢回复!您说的帖子我看了 楼主实现的方法确实挺巧妙地 之前看过有在 selendriod 模式下获取 toast 所以想尝试下 然而失败了。。。
@seveniruby 大神有时间看看我这个为啥跑不起来 提示 API>=17 但是明明就用的 4.3 啦~
def setUp(self):
desired_caps_android = {
'platformVersion': '4.3', \
'deviceName': 'SM-G7108V', \
'platformName': 'Android', \
'automationName': 'Selendroid', \
'app': PATH('C:\Program Files (x86)\Appium\golo.apk'), \
'unicodeKeyboard': True, \
'resetKeyboard': True, \
'noReset':True,
}
报错信息:
Traceback (most recent call last):
File "C:\Users\Win-Attack\Desktop\test_get_toast.py", line 38, in setUp
self.driver=webdriver.Remote('http://localhost:4723/wd/hub,desired_caps_android')
File "C:\Python27\lib\site-packages\appium\webdriver\webdriver.py", line 36, in init
super(WebDriver, self).init(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in init
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: A new session could not be created. (Original error: Required platform doesn't exist (API level >= 17))
og:
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe devices
info: [debug] 0 device(s) connected
info: [debug] Could not find devices, restarting adb server...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe kill-server
info: [debug] Getting connected devices...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe devices
info: [debug] 0 device(s) connected
info: [debug] Could not find devices, restarting adb server...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe kill-server
info: [debug] Getting connected devices...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe devices
info: [debug] 0 device(s) connected
info: [debug] Could not find devices, restarting adb server...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe kill-server
info: [debug] Getting connected devices...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe devices
info: [debug] 0 device(s) connected
info: [debug] Could not find devices, restarting adb server...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe kill-server
info: [debug] Getting connected devices...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe devices
info: [debug] 0 device(s) connected
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Could not find a conne
cted Android device.
info: [debug] Error: Could not find a connected Android device.
at [object Object].ADB.getDevicesWithRetry (C:\Program Files (x86)\Appium\no
de_modules\appium\node_modules\appium-adb\lib\adb.js:606:15)
at [object Object].androidCommon.prepareActiveDevice (C:\Program Files (x86)
\Appium\node_modules\appium\lib\devices\android\android-common.js:400:12)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\a
ppium\lib\devices\android\android-common.js:326:26)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:607:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:246:17
at iterate (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\a
sync\lib\async.js:146:13)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:157:25
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:248:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:612:34
at [object Object].androidCommon.ensureDeviceLocale (C:\Program Files (x86)\
Appium\node_modules\appium\lib\devices\android\android-common.js:371:45)
at [object Object].androidCommon.prepareEmulator (C:\Program Files (x86)\App
ium\node_modules\appium\lib\devices\android\android-common.js:364:10)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\a
ppium\lib\devices\android\android-common.js:325:26)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:607:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:246:17
at iterate (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\a
sync\lib\async.js:146:13)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:157:25
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:248:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:612:34
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\a
ppium\lib\devices\android\android-common.js:344:9)
at FSReqWrap.oncomplete (fs.js:82:15)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"
A new session could not be created. (Original error: Could not find a connected
Android device.)","origValue":"Could not find a connected Android device."},"ses
sionId":null}
info: <-- POST /wd/hub/session 500 20799.770 ms - 206
info: --> POST /wd/hub/session {"desiredCapabilities":{"deviceName":"SM-G7108V",
"unicodeKeyboard":true,"automationName":"Selendroid","noReset":true,"resetKeyboa
rd":true,"platformVersion":"4.3","platformName":"Android","app":"C:\Program Fil
es (x86)\Appium\golo.apk"}}
info: Client User-Agent string: Python-urllib/2.7
info: [debug] No appActivity desired capability or server param. Parsing from ap
k.
info: [debug] No appPackage desired capability or server param. Parsing from apk
.
info: [debug] Using local app from desired caps: C:\Program Files (x86)\Appium\g
olo.apk
info: [debug] Creating new appium session 1c0ef176-1fc1-472a-ac26-b4d9eb7f1766
info: [debug] Starting selendroid server
info: [debug] Getting Java version
info: Java version is: 1.8.0_91
info: [debug] Checking whether adb is present
info: [debug] Using adb from C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe
info: [debug] Checking whether selendroid is built yet
info: [debug] Selendroid server exists!
info: [debug] Using fast reset? false
info: [debug] Preparing device for session
info: [debug] Checking whether app is actually present
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: Found device 278f9869
info: [debug] Setting device id to 278f9869
info: [debug] Waiting for device to be ready and to respond to shell commands (t
imeout = 5)
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe -s 278f9869 wait-for-device
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe -s 278f9869 shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from C:\Users\Win-Attack\AppData\Local\Android\sdk\buil
d-tools\24.0.0-preview\aapt.exe
info: [debug] Checking if has internet permission from manifest.
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\build
-tools\24.0.0-preview\aapt.exe dump badging "C:\Program Files (x86)\Appium\golo.
apk"
info: [debug] Parsing package and activity from app manifest
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from C:\Users\Win-Attack\AppData\Local\Android\sdk\buil
d-tools\24.0.0-preview\aapt.exe
info: [debug] Extracting package and launch activity from manifest.
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\build
-tools\24.0.0-preview\aapt.exe dump badging "C:\Program Files (x86)\Appium\golo.
apk"
info: [debug] badging package: com.cnlaunch.golo3
info: [debug] badging act: com.cnlaunch.golo3.activity.WelcomeActivity
info: [debug] Parsed package and activity are: com.cnlaunch.golo3/com.cnlaunch.g
olo3.activity.WelcomeActivity
info: [debug] Rebuilt selendroid server does not exist, inserting modified manif
est
info: [debug] Inserting selendroid manifest
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from C:\Users\Win-Attack\AppData\Local\Android\sdk\buil
d-tools\24.0.0-preview\aapt.exe
info: [debug] Compiling manifest C:\Users\WIN-AT~1\AppData\Local\Temp\com.cnlaun
ch.golo3\AndroidManifest.xml
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Required platform does
n't exist (API level >= 17)
info: [debug] Error: Required platform doesn't exist (API level >= 17)
at [object Object].ADB.compileManifest (C:\Program Files (x86)\Appium\node_m
odules\appium\node_modules\appium-adb\lib\adb.js:306:15)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\a
ppium\lib\devices\android\selendroid.js:444:16)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:607:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:246:17
at iterate (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\a
sync\lib\async.js:146:13)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:157:25
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:248:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:612:34
at [object Object].ADB.checkSdkBinaryPresent (C:\Program Files (x86)\Appium\
node_modules\appium\node_modules\appium-adb\lib\adb.js:116:5)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\a
ppium\lib\devices\android\selendroid.js:442:30)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:607:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:246:17
at iterate (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\a
sync\lib\async.js:146:13)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:157:25
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:248:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:612:34
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\mkdirp\ind
ex.js:48:26
at FSReqWrap.oncomplete (fs.js:82:15)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"
A new session could not be created. (Original error: Required platform doesn't e
xist (API level >= 17))","origValue":"Required platform doesn't exist (API level
= 17)"},"sessionId":null}
info: <-- POST /wd/hub/session 500 607.013 ms - 220
info: --> POST /wd/hub/session {"desiredCapabilities":{"deviceName":"SM-G7108V",
"unicodeKeyboard":true,"automationName":"Selendroid","noReset":true,"resetKeyboa
rd":true,"platformVersion":"4.1","platformName":"Android","app":"C:\Program Fil
es (x86)\Appium\golo.apk"}}
info: Client User-Agent string: Python-urllib/2.7
info: [debug] No appActivity desired capability or server param. Parsing from ap
k.
info: [debug] No appPackage desired capability or server param. Parsing from apk
.
info: [debug] Using local app from desired caps: C:\Program Files (x86)\Appium\g
olo.apk
info: [debug] Creating new appium session 3b1b3b79-f95b-4175-9d15-a22d68178251
info: [debug] Starting selendroid server
info: [debug] Getting Java version
info: Java version is: 1.8.0_91
info: [debug] Checking whether adb is present
info: [debug] Using adb from C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe
info: [debug] Checking whether selendroid is built yet
info: [debug] Selendroid server exists!
info: [debug] Using fast reset? false
info: [debug] Preparing device for session
info: [debug] Checking whether app is actually present
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: Found device 278f9869
info: [debug] Setting device id to 278f9869
info: [debug] Waiting for device to be ready and to respond to shell commands (t
imeout = 5)
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe -s 278f9869 wait-for-device
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\platf
orm-tools\adb.exe -s 278f9869 shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from C:\Users\Win-Attack\AppData\Local\Android\sdk\buil
d-tools\24.0.0-preview\aapt.exe
info: [debug] Checking if has internet permission from manifest.
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\build
-tools\24.0.0-preview\aapt.exe dump badging "C:\Program Files (x86)\Appium\golo.
apk"
info: [debug] Parsing package and activity from app manifest
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from C:\Users\Win-Attack\AppData\Local\Android\sdk\buil
d-tools\24.0.0-preview\aapt.exe
info: [debug] Extracting package and launch activity from manifest.
info: [debug] executing cmd: C:\Users\Win-Attack\AppData\Local\Android\sdk\build
-tools\24.0.0-preview\aapt.exe dump badging "C:\Program Files (x86)\Appium\golo.
apk"
info: [debug] badging package: com.cnlaunch.golo3
info: [debug] badging act: com.cnlaunch.golo3.activity.WelcomeActivity
info: [debug] Parsed package and activity are: com.cnlaunch.golo3/com.cnlaunch.g
olo3.activity.WelcomeActivity
info: [debug] Rebuilt selendroid server does not exist, inserting modified manif
est
info: [debug] Inserting selendroid manifest
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from C:\Users\Win-Attack\AppData\Local\Android\sdk\buil
d-tools\24.0.0-preview\aapt.exe
info: [debug] Compiling manifest C:\Users\WIN-AT~1\AppData\Local\Temp\com.cnlaun
ch.golo3\AndroidManifest.xml
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Required platform does
n't exist (API level >= 17)
info: [debug] Error: Required platform doesn't exist (API level >= 17)
at [object Object].ADB.compileManifest (C:\Program Files (x86)\Appium\node_m
odules\appium\node_modules\appium-adb\lib\adb.js:306:15)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\a
ppium\lib\devices\android\selendroid.js:444:16)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:607:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:246:17
at iterate (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\a
sync\lib\async.js:146:13)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:157:25
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:248:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:612:34
at [object Object].ADB.checkSdkBinaryPresent (C:\Program Files (x86)\Appium\
node_modules\appium\node_modules\appium-adb\lib\adb.js:116:5)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\a
ppium\lib\devices\android\selendroid.js:442:30)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:607:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:246:17
at iterate (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\a
sync\lib\async.js:146:13)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:157:25
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:248:21
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\
async.js:612:34
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\mkdirp\ind
ex.js:48:26
at FSReqWrap.oncomplete (fs.js:82:15)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"
A new session could not be created. (Original error: Required platform doesn't e
xist (API level >= 17))","origValue":"Required platform doesn't exist (API level
= 17)"},"sessionId":null}
info: <-- POST /wd/hub/session 500 602.264 ms - 220
@seveniruby 请教大神,最近在学习 Appium 看到您自动化遍历的工具,之前自己也思考过实现遍历功能,想了解下实现的思路是怎样的~还望赐教!