下载
test.py
from appium import webdriver import time import unittest import HTMLTestRunner class SearchCls(unittest.TestCase): def setUp(self): desired_caps = { 'platformName': 'Android', 'deviceName': 'Galaxy Note4', 'platformVersion': '5.1.1', 'appPackage': 'com.baidu.searchbox', 'appActivity': 'MainActivity', 'unicodeKeyboard': True, 'resetKeyboard': True } self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) def search_info(self): driver = self.driver driver.find_element_by_id("com.baidu.searchbox:id/baidu_searchbox").click() driver.find_element_by_id("com.baidu.searchbox:id/SearchTextInput").clear() driver.find_element_by_id("com.baidu.searchbox:id/SearchTextInput").send_keys('appium test') driver.find_element_by_id("float_search_or_cancel").click() time.sleep(2) driver.find_element_by_id("com.baidu.searchbox:id/redtip_icon").click() time.sleep(2) driver.find_element_by_id("com.baidu.searchbox:id/common_menu_item_icon").click() def search_two(self): driver = self.driver driver.find_element_by_id("com.baidu.searchbox:id/baidu_searchbox").click() driver.find_element_by_id("com.baidu.searchbox:id/SearchTextInput").clear() driver.find_element_by_id("com.baidu.searchbox:id/SearchTextInput").send_keys('HTML5') driver.find_element_by_id("float_search_or_cancel").click() if __name__ == '__main__': suite = unittest.TestSuite() suite.addTest(SearchCls('search_two')) suite.addTest(SearchCls('search_info')) filename = 'E:\testTool\pyFile\app.html' fb = open(filename, 'wb') runner = HTMLTestRunner.HTMLTestRunner(stream=fb, title='search', description='search') runner.run(suite) fb.close()
这个要勾选,在测试多个case不选会出问题。
测试结果