python客户端和Appium服务端联调出现的问题解决办法

按照安装文档搭建完移动端自动化测试环境,包括:SDK、JDK、Node.js、Appium及客户端后,appium-doctor可以成功的检测到各配套版本。如下图:

可是,运行from appium import webdriver出错,上报:ImportError: cannot import name InvalidArgumentException错误。

我查看C:\Python27\Lib\site-packages\appium\webdriver\webdriver.py文件,发现该文件引用的是from selenium import webdriver

于是,我把代码中的这项from appium import webdriver改成from selenium import webdriver,查看Appium服务发现能够联调成功。

可是运行代码的时候,发现服务端上报如下错误:Android devices must be of API level 17 or higher.

查看我的模拟器,发现版本为:

于是果断再增加一个API17版本的模拟机,

再运行测试脚本:

#coding=utf-8
from appium import webdriver

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = '192.168.54.101:5555'
desired_caps['appPackage'] = 'com.android.calculator2'
desired_caps['appActivity'] = '.Calculator'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.find_element_by_name("1").click()
driver.find_element_by_name("5").click()
driver.find_element_by_name("9").click()
driver.find_element_by_name("9").click()
driver.find_element_by_name("5").click()
driver.find_element_by_name("+").click()
driver.find_element_by_name("6").click()
driver.find_element_by_name("=").click()
driver.quit()
成功连接到服务器启动模拟手机的计算器功能做自动化测试。

 

猜你喜欢

转载自www.cnblogs.com/Ladylittleleaf/p/9563221.html