基于Appium、Python的自动化测试环境部署和实践(6)

发表于:2017-04-20来源:cnblogs作者:bacon刘点击数: 标签:pythonAppium
from appium import webdriver import time from selenium.common.exceptions import NoSuchElementException class driverObject: def __init__(self, host, port, platform, version, deviceName, noReset, unicod
复制代码
from appium import webdriver import time from selenium.common.exceptions import NoSuchElementException class driverObject: def __init__(self, host, port, platform, version, deviceName, noReset, unicodeK, resetK, appPath ,appP_bdId, appA_udid, localPort): #__appP_bdId = "com.yitong.fjnx.mbank.android"
        __appP_bdId = appP_bdId #__appA_udid = ".Splash"
        __appA_udid = appA_udid self.pwmode = 'lower' self.model='Appium' self.desired_caps = {} self.desired_caps['platformName'] = platform self.desired_caps['platformVersion'] = version self.desired_caps['noReset'] = noReset self.desired_caps['unicodeKeyboard'] = unicodeK self.desired_caps['resetKeyboard'] = resetK self.desired_caps['app'] = appPath self.desired_caps['udid'] = deviceName self.desired_caps['deviceName'] = deviceName # Android - ignored, iOS - iPhone name
        if platform == "Android": self.desired_caps['appPackage'] = __appP_bdId self.desired_caps['appActivity'] = __appA_udid
        if platform == "iOS": self.desired_caps['bundleId'] = __appP_bdId self.desired_caps['automationName'] = 'XCUITest' self.desired_caps['wdaLocalPort'] = localPort url = "http://" + host + ":" + str(port) + "/wd/hub" self.driver = webdriver.Remote(url, self.desired_caps) time.sleep(5) def get_driver(self): return self.driver def quit(self): self.driver.quit()
复制代码
主类
复制代码
from testClass import driverObject if __name__ == '__main__': driver = driverObject(参数...)   ele = self.driver.find_elements_by_class_name("android.widget.Button") ele[0].click() time.sleep(5) ele = self.driver.find_elements_by_class_name("android.widget.EditText") ele[1].send_keys("account") ele[2].send_keys("password") ele = self.driver.find_elements_by_class_name("android.widget.Button") time.sleep(2) ele[0].click() driver.quit()
复制代码
 关于Appium、Python的测试脚本公共函数可以查阅Appium-Python-Api文档,里面记录Appium提供给python的公共函数。其实,测试脚本的大部分内容就是找控件、点击控件、输入内容、线程等待这些操作。
 

原文转自:http://www.cnblogs.com/baconLiu/p/6735441.html

...

热门标签