代码如下:

# -*- coding: utf-8 -*-import osimport sysimport timeimport unittestfrom HTMLTestRunner import HTMLTestRunnerfrom unittest import runnerfrom appium import webdriver# from selenium import webdriverfrom selenium.webdriver.common.by import Bysys.path.append('D:/Py-workspace/test/appium_test/appium_test1.py')ABSPATH = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))global driverclass MyTests(unittest.TestCase):    @classmethod    def setUpClass(cls):    # def setUp(self):        # 初始化测试平台        desired_caps = {}        desired_caps['platformName'] = 'Android'        desired_caps['platformVersion'] = '6.0'        desired_caps['deviceName'] = '78d358ad'        desired_caps['appPackage'] = 'com.nuomi'        desired_caps['appActivity'] = 'com.baidu.bainuo.dex.InstallDexActivity'        desired_caps['appWaitActivity'] = 'com.baidu.bainuo.home.HomeTabActivity'        desired_caps["unicodeKeyboard"] = "True"  # 输入中文        desired_caps["resetKeyboard"] = "True"    # 输入中文        cls.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)        cls.driver.implicitly_wait(8)    def test_user_center(self):        """进入个人中心"""        self.driver.find_element_by_name("我的").click()        # 个人中心个人信息模块是否显示,显示表示进入个人中心成功        ds = self.driver.find_element_by_id("com.nuomi:id/mine_set_comp")  # 设置按钮是否可见        # assert ds.is_displayed() == 'true'    def test_swipe(self):        """滑动元素"""        self.driver.swipe(100, 0, 100, 500)        time.sleep(5)    def test_search(self):        """首页搜索框输入"""        self.driver.find_element_by_name("首页").click()  # 点击返回首页        self.driver.find_element_by_id("com.nuomi:id/native_home_actionbar_searchbox").click()  # 点击搜索框        self.driver.find_element_by_id("com.nuomi:id/search_bussness_key_words").send_keys(u"电影")  # 搜索框输入中文        self.driver.get_screenshot_as_file("./screenshot/"+time+"_nuomi.png")        # 截屏    def test_shake(self):        """摇晃手机"""        self.driver.shake()    @classmethod    def tearDownClass(cls):        cls.driver.quit()if __name__ == '__main__':    # unittest.main(verbosity=2)    """"""    # 构造测试集    suite = unittest.TestSuite()     # 构造测试集    suite.addTest(MyTests("test_user_center"))  # 加入测试用例    suite.addTest(MyTests("test_shake"))    suite.addTest(MyTests("test_swipe"))    suite.addTest(MyTests("test_search"))    # unittest.runner(suite)    # 执行测试    date = time.strftime("%Y%m%d")      # 定义date为日期,time为时间    time = time.strftime("%Y%m%d-%H%M%S")    path = "./report/"+date+"/"    # 判断是否定义的路径目录存在,不能存在则创建    if not os.path.exists(path):        os.makedirs(path)    else:        pass    # report_path = path+time+"report.html"      # 将运行结果保存到report,名字为定义的路径和文件名,运行脚本    report_path = path + time +"app_report.html"   # 不添加时间的测试报告名    report_title = u"测试报告"    desc = u'Appium自动化测试报告详情:'    with open(report_path, 'wb') as report:        runner = HTMLTestRunner(stream=report, title=report_title, description=desc)        runner.run(suite)    # 关闭report,脚本结束    report.close()

更多相关文章

  1. 解析json格式数据
  2. Android(安卓)3G 拨号脚本
  3. 测试手机多点触摸
  4. 多线程下载测试TestDownload
  5. httpclient测试代码
  6. Android(安卓)TabActivity实现多页显示效果
  7. android下截屏
  8. Andorid中Fragment简单切换案例
  9. autoMonkey框架原理与应用(一):Monkey基础知识与测试场景

随机推荐

  1. 【Android开发】android最全的颜色对应的
  2. Android(安卓)拖拽
  3. Android(安卓)Http基础:图片下载并显示和W
  4. android好文章或博客地址收藏
  5. Android(安卓)AlertDialog.Builder进入和
  6. 〖Android〗/system/etc/media_codecs.xm
  7. 什么是Android?
  8. Android(安卓)Error: Conversion to Dalv
  9. android 判断真机或者模拟器
  10. Android(安卓)系统应用调用,intent 的使用