python 自动化测试

1 篇文章 0 订阅
1 篇文章 0 订阅

项目源码:https://github.com/yicaifenchen8/autotest.git  

1.驱动配置

class Driver(object):

    # 防止多个用例执行时-重启app
    @staticmethod
    def getInstance():
        if (hasattr(Driver, 'instance')): #返回单一实例
            return Driver.instance

        # os.system('adb uninstall io.appium.settings')
        # os.system('adb uninstall io.appium.unlock')

        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        # desired_caps['platformVersion'] = '7.0'
        desired_caps['deviceName'] = 'samsung'
        desired_caps['app'] = r'D:\proj\testDP\app\build\outputs\apk\debug\app-debug.apk'
        desired_caps['appPackage'] = 'cn.ycf.testdp'
        desired_caps['appActivity'] = 'cn.ycf.testdp.TestDPActivity'
        desired_caps['noReset'] = True # 不清除数据,不会重新安装
        driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

        driver.quit = lambda : {} #不关闭app
        Driver.instance = driver
        return driver

2.测试用例

class MyTestCase(unittest.TestCase):

    def setUp(self):
        print('setUp')
        self.driver = Driver.getInstance()

    def test_click(self):
        print('test_click')
        time.sleep(1)

        # R.login

        # self.driver.find_element_by_xpath("//android.widget.ListView/android.widget.TextView[contains(@text,'测试')]").click()
        # self.driver.find_element_by_id('cn.ycf.testdp:id/msg').click()

    def tearDown(self):
        self.driver.quit()
        print('tearDown')


if __name__ == '__main__':
    unittest.main()

3.运行测试用例

# 获取所有测试用例
def get_allcase():
    discover = unittest.defaultTestLoader.discover('./test_case', pattern="test*.py")
    suite = unittest.TestSuite()
    suite.addTest(discover)
    return suite

if __name__ == '__main__':
    # 运行测试用例
    runner = unittest.TextTestRunner()
    runner.run(get_allcase())

项目源码:https://github.com/yicaifenchen8/autotest.git 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值