user_title)def test_login_success_(self):username = XXXXXpa
标签:
一、Unittest用例组织在test_case目录下创建test*.py,组织测试用例
├── test_case │?? ├── __init__.py │?? └── test_login.pytest_login.py
import unittest from pages.login_page import LoginPageAction from utils.constants import LOGIN_URL class TestLoginCase(unittest.TestCase): def test_login_success(self): username = 'XXXXX' password = 'XXXXX' login_page = LoginPageAction(path=LOGIN_URL) home_page = login_page.login(username=username, password=password) user_title = home_page.get_user_title expect_ret = 'XXXXXX' self.assertEqual(expect_ret, user_title) def test_login_success_(self): username = 'XXXXX' password = 'XXXXX' login_page = LoginPageAction(path=LOGIN_URL) home_page = login_page.login(username=username, password=password) user_title = home_page.get_user_title expect_ret = 'XXXXXX' self.assertEqual(expect_ret, user_title) if __name__ == '__main__': unittest.main() 二、组织测试用例戳我获取 —> 组织用例的姿势
在run_case目录下创建run_login_case.py,,用于运行登陆用例集
├── run_case │?? ├── __init__.py │?? └── run_login_case.pyrun_login_case.py
import unittest from test_case.test_login import TestLoginCase from utils.se_utils import Driver if __name__ == '__main__': cases = unittest.TestLoader().loadTestsFromTestCase(TestLoginCase) runner = unittest.TextTestRunner(verbosity=2) runner.run(cases) # 所有用例运行完后封锁浏览器 Driver.quit_driver() 三、添加Python引包路径创建module_path.py,存放所有引包的绝对路径 放在run_case下,
所有的执行计谋均先挪用module_path.py,防备找到模块的异常: ModuleNotFoundError: No module named ‘XXXXXX‘
module_path.py
# 添加Python存放模块的路径 import os import sys web_auto_test_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) pages_dir_path = web_auto_test_path + '/pages' config_dir_path = web_auto_test_path + '/config' run_case_dir_path = web_auto_test_path + '/run_case' test_case_dir_path = web_auto_test_path + '/test_case' utils_dir_path = web_auto_test_path + '/utils' sys.path.extend([ web_auto_test_path, pages_dir_path, config_dir_path, run_case_dir_path, test_case_dir_path, utils_dir_path, ]) from pprint import pprint print('python引包路径:') pprint(sys.path)run_login_case.py
# 在执行入口添加引包路径 from module_path import * · · ·
Web自动化测试项目(三)用例的组织与运行
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30961.html