zoukankan      html  css  js  c++  java
  • appium学习【四】:第一个appium脚本

    #coding=utf-8
    import os
    import HTMLTestRunner
    import unittest
    import time
    import sys
    from appium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.common.exceptions import TimeoutException
    
    reload(sys)
    sys.setdefaultencoding('utf8')
    
    
    #Returns abs path relative to this file and not cwd
    PATH = lambda p:os.path.abspath(
        os.path.join(os.path.dirname(__file__),p)
    )
    
    #类继承unittest.TestCase类,从TestCase类继承是告诉unittest模块的方式,这是一个测试案例。
    class BangbanAndroidTests(unittest.TestCase):
        #setUp 用于设置初始化的部分,在测试用例执行前,这个方法中的函数将先被调用。
        def setUp(self):
            desired_caps = {}
            desired_caps['deviceName'] = '127.0.0.1:62001'
            desired_caps['platformName'] = 'Android'
            desired_caps['platformVersion'] = '4.4.2'
            desired_caps['appPackage'] = 'com.cbwlkj.cyzb' #邦办达人App的包名
            desired_caps['appActivity'] = 'com.hsdzkj.husong.ui.activity.IndexActivity' #启动时的Activity
            self.driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
    
        #tearDown 方法在每个测试方法执行后调用,这个地方做所有清理工作,如退出
        def tearDown(self):
            self.driver.close_app()
            self.driver.quit()
    
        #放置的就是我们的测试脚本了,这部分我们并不陌生;因为我们执行的脚本就在这里。
        def test_bangban_login(self):
            try:
                WebDriverWait(self.driver,10).until(
                EC.presence_of_element_located((By.ID,'com.cbwlkj.cyzb:id/contact_phone1'))
                )
                self.driver.find_element_by_id('com.cbwlkj.cyzb:id/contact_phone1').send_keys('18602508223')
                time.sleep(5)
            except TimeoutException:
                print u'达人登录页面加载失败'
                funcName = sys._getframe().f_code.co_name
                print funcName
                pngfile = "E:\appium_code\png\" + funcName + timestr + ".png"
                print pngfile
                self.driver.get_screenshot_as_file(pngfile)
            raise
    
    
    
    #unitest.main()函数用来测试 类中以test开头的测试用例
    if __name__ == '__main__':
        suite = unittest.TestSuite()
        suite.addTest(
            unittest.defaultTestLoader.loadTestsFromTestCase(BangbanAndroidTests)
        )
        timestr = time.strftime('%Y-%m-%d_%H%M%S', time.localtime(time.time()))
        filename = "E:\appium_code\report\result_" + timestr + ".html"
        fp = open(filename, 'wb')
        runner = HTMLTestRunner.HTMLTestRunner(
            stream=fp,
            title='测试结果',
            description='测试报告'
        )
        runner.run(suite)
        fp.close()  # 测试报告关闭
  • 相关阅读:
    Salesforce和SAP Netweaver里数据库表的元数据设计
    Salesforce平台支持多租户Multi tenant的核心设计思路
    S/4HANA生产订单增强WORKORDER_UPDATE方法BEFORE_UPDATE参数分析
    S/4HANA生产订单的标准状态和透明工厂原型状态的映射
    1048. Find Coins (25)
    1101. Quick Sort (25)
    1009. Product of Polynomials (25)
    pta 奇数值结点链表&&单链表结点删除
    1007. Maximum Subsequence Sum (25)
    1006. Sign In and Sign Out (25)
  • 原文地址:https://www.cnblogs.com/yrxns/p/7049543.html
Copyright © 2011-2022 走看看