unittest用例封装

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/dengachao/article/details/101210449

一、测试环境

Win 10
java version "1.8.0_181"
Appium v1.14.1(不能低于1.6.3)
selenium:3.141.0
测试设备:Android 5.1.1
Python:3.6
测试App:考研帮Android app V3.1.0

二、测试场景
对以下账号进行登录测试

用户名

密码

正确的账号1

正确的密码1

正确的账号2

正确的密码2

错误的账号3

错误的密码3

三、参考代码
封装用例启动结束时的配置: myunit.py

import unittest
from appium_advance.page_object.desired_caps import appium_desired
import logging
from time import sleep
class StartEnd(unittest.TestCase):
    def setUp(self):
        logging.info('======启动=======')
        self.driver = appium_desired()
    def tearDown(self):
        logging.info('======tearDown=====')
        sleep(5)
        self.driver.close_app()

用例 test_login.py

from appium_advance.unittest.myunil import StartEnd
from appium_advance.page_object.loggingView import LoggingView
import unittest
import logging

class TestLogin(StartEnd):
    def test_login_zxw2018(self):
        logging.info('=====test_login_zxw2018=====')
        l1 = LoggingView(self.driver)
        l1.login_action('正确的账号1','正确的密码1')

    def test_login_zxw2017(self):
        logging.info('=====test_login_zxw2017=====')
        l1 = LoggingView(self.driver)
        l1.login_action('正确的账号2','正确的密码2)

    def test_login_error(self):
        logging.info('=====test_login_error=====')
        l1 = LoggingView(self.driver)
        l1.login_action('错误的账号3','错误的密码3')

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

四、执行及结果

执行

运行结果

猜你喜欢

转载自blog.csdn.net/dengachao/article/details/101210449