# -*- coding: UTF-8 -*- import configparser import copy import os import time import uuid import pytest from common.read_data.read_data import ReadData from common.ui_common.objects.accounts import Accounts from common.ui_common.objects.objects_public_operations import ObjectsPublicOperations, download_files from config.workpath import workdir data = ReadData() # def my_custom_method(): # print("Test case failed! Executing custom method.") # # @pytest.fixture # def demo_fixture(request): # yield # # 在测试用例执行后检查结果 # if hasattr(request.node, 'rep_call') and request.node.rep_call.failed: # # 打印路径以确保正确 # print(f"Test failed in: {request.node.location[0]}") # # 仅在 test_a.py 中执行自定义方法 # if 'test_a.py' in request.node.location[0]: # my_custom_method() class TestAccounts: @pytest.mark.parametrize("data", data.read_data_object(r"Accounts\\base_accounts.json"), ids=data.generate_id) def test_accounts(self, demo_fixture, data): acc = Accounts(demo_fixture) acc.acc_case(data) @pytest.mark.parametrize("data", data.read_data_object(r"Accounts\\nested_accgroup.json"), ids=data.generate_id) # test case 008 def test_nested_urlgroup(self, demo_fixture, data): acc = Accounts(demo_fixture) search_value = data["Name"][0][:int((len(data["Name"][0])) / 3)] try: acc._create_mutiLayer_nested_accGroup(data) print("search_value:{}".format(search_value)) except Exception as e: raise e finally: # 清理测试数据 # acc._simpe_query(data, search_value=search_value) acc._del(data, search_value=search_value, del_flag=1) @pytest.mark.parametrize("data", data.read_data_object(r"Accounts\\del_quoted_objects.json"), ids=data.generate_id) def test_del_quoted_objects(self, demo_fixture, data): acc = Accounts(demo_fixture) try: acc._del_quoted_objects(data) except Exception as e: raise e finally: # 清理测试数据 acc.driver.refresh() # 刷新页面 # acc._query(data) # 刷新后查询 acc._del(data) @pytest.mark.parametrize("data", [ { "ids": "创建Account Group、查询Account Group、删除Account Group| T002", "Model": "create", "Type": 1, "Search type": "Name", "Name": "", "Items": [ ], "Description": "", "Subordinate Objects": { "subName": "", "subItems": [ "asdcesd->", "[random][search]->" ], "subDescription": "" }, "Exclude Objects": { "subName": "", "subItems": [ "[random][search]->", "^shdjilluhiasdh->" ], "subDescription": "" } }, ]) def passtest_reference_count(self, demo_fixture, data): acc = Accounts(demo_fixture) # assert False try: acc.create(data) acc._reference_count() finally: acc.delete(data) #未修改 # @pytest.mark.parametrize("data", [ # { # "ids": "test_reference_by_object", # "Model": "create", # "Type": 0, # "Search type": "Name", # "Name": "", # "Items": [ # "[random]->" # ], # "Description": "" # }, # ]) # def test_reference_by_object(self, demo_fixture, data): # acc = Accounts(demo_fixture) # acc._reference_by_object(data) def test_operate_columns(self, demo_fixture): acc = Accounts(demo_fixture) acc._operate_columns() # @pytest.mark.parametrize("data", # [ # { # "ids": "创建accObject并导出验证|T012", # "Model": "create", # "Type": 0, # "Name": "", # "Search type": "", # "Items": [ # "[random]->" # ], # "Description": "", # "Subordinate Objects": [ # ] # }, # ]) # def test_export_objects_and_verify(self, demo_fixture,data): # acc = Accounts(demo_fixture) acc._export_objects_and_verify(data) # # driver.quit() @pytest.mark.parametrize("data", [ { "ids": "创建accObject并查看验证Total |T017", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "*example->", "[random]->", "$acbsuduh->" ], "Description": "", "Subordinate Objects": [ ], "SubType": "multi_export", "multi_type": "all", }, { "ids": "创建accObject并查看验证Total |T017", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "*example->", "[random]->", "$acbsuduh->" ], "Description": "", "Subordinate Objects": [ ], "SubType": "multi_export", "multi_type": "part", }, { "ids": "创建accObject并查看验证Total |T017", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "*example->", "[random]->", "$acbsuduh->" ], "Description": "", "Subordinate Objects": [ ], "SubType": "multi_export", "multi_type": " ", }, { "ids": "创建interval_Group--test_View_statistics_case", "Model": "create", "Type": 1, "Search type": "Name", "Name": "", "Items": [ ], "Description": "", "Subordinate Objects": { "subName": "", "subItems": [ "^shdjilluhiasdh->" ], "subDescription": "" }, "SubType": "multi_export", "multi_type": " ", }, ]) def test_export_multi_condition_test(self, demo_fixture, data): acc = Accounts(demo_fixture) acc.export_multi_condition_test(data) @pytest.mark.parametrize("data", data.read_data_object(r"URLs\\pages_turning.json"), ids=data.generate_id) def test_pages_turning(self, demo_fixture, data): acc = Accounts(demo_fixture) # objects下的对象页 acc._goto_accountsPage() acc.objects_po.pages_turning(data) def passed_test_operate_watch(self, demo_fixture): acc = Accounts(demo_fixture) acc._goto_accountsPage() acc._add_to_watchList() #未修改 # @pytest.mark.parametrize("data", [ # { # "ids": "创建urlObject并查看验证审计日志-T016/创建并修改urlObject查看验证审计日志-T041/23.09版本新功能:右侧页面增加Audit Logs功能-T073", # "Model": "create", # "Type": 0, # "Name": "", # "Search type": "", # "Items": [ # "[random]->*asruhau" # ], # "Description": "", # } # ]) # def test_verify_audit_logs(self, demo_fixture, data): # acc = Accounts(demo_fixture) # acc._goto_accountsPage() # acc._verify_audit_logs(data) @pytest.mark.parametrize("data", [ { "ids": "创建accObject并查看验证Total |T017", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "*example->", "[random]->", "$acbsuduh->" ], "Description": "", "Subordinate Objects": [ ] }, ]) def test_verify_items_total(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._verify_items_total(data) @pytest.mark.parametrize("data", [ { "ids": "Item增量导入错误文件| T018&T019-1", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "acc_item导入内容名称错误文件.txt[ImportFromFile]->" ], "Description": "" }, { "ids": "Item增量导入错误文件| T018&T019-3", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "acc_item导入内容重复文件.txt[ImportFromFile]->" ], "Description": "" } ] ) def test_verify_item_value_from_file(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._verify_item_value_from_file(data) @pytest.mark.parametrize("data", [ { "ids": "创建accObject——Name-T021-1", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "[random]" ], "Description": "", "Subordinate Objects": "" }, { "ids": "创建accObject——Name-T021-2", "Model": "create", "Type": 0, "Name": "tes", "Search type": "", "Items": [ "[random]" ], "Description": "", "Subordinate Objects": "" }, { "ids": "创建accObject——Name-T021-3", "Model": "create", "Type": 1, "Name": "test_url_ObjectDetailPage_nameLenthNumber_posXpath--url_ObjectDetailPage_nameLenthNumber_posXpath-url_ObjectDetailPage_nameLenthNumber_posXpathurl_ObjectDetailPage_nameLenthNumber_posXpath", "Search type": "", "Items": [ "[random]" ], "Description": "", "Subordinate Objects": "" }, ]) def test_verify_object_name_input(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._verify_object_name_input(data) @pytest.mark.parametrize("data", [{ "ids": "不输入必要数据——Item-T022", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "" ], "Description": "", "Subordinate Objects": "" }, ]) def test_verify_item_value_input(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._verify_item_value_input(data) @pytest.mark.parametrize("data", data.read_data_object(r"Accounts\\select_and_export.json"), ids=data.generate_id) def test_export_and_verify_checkbox(self, data): driver = download_files() acc = Accounts(driver) acc._export_and_verify_checkbox(data) driver.quit() @pytest.mark.parametrize("data", data.read_data_object(r"Accounts\\switch_page_after_selected.json"), ids=data.generate_id) def test_switch_page_after_selected(self, demo_fixture, data): acc = Accounts(demo_fixture) # profile_pub = ProfilesPublicOperations(demo_fixture) # profile_pub.change_vsys(vsys_name='PerformanceTestVsys') acc._switch_page_after_selected(data) @pytest.mark.parametrize("data", [ { "ids": "Item在编辑状态下,上传文件按钮置灰-T055", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "abcd" ], "Description": "", "Subordinate Objects": [ "abcd$->" ] }, ] ) def test_importFromFile_whenItemEditing(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._importFromFile_whenItemEditing(data) @pytest.mark.parametrize("data", [ { "ids": "未删除上传的文件时,无法在Item框中手动添加数据-T056", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "accounts_single_item导入文件.txt[ImportFromFile]" ], "Description": "", "Subordinate Objects": [ "abcd$->" ] } ]) def test_addItem_before_uploadFileDeleted(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._addItem_before_uploadFileDeleted(data) @pytest.mark.parametrize("data", [ { "ids": "用户上传、验证、修改成功的文件展示文件名,鼠标悬浮在文件名上可以下载和删除-T057", "Model": "create", "Type": 0, "Name": "", "Search type": "", "Items": [ "accounts_single_item导入文件.txt[ImportFromFile]" ] } ]) def test_itemFile_downloadAndDelete(self, data): driver = download_files() acc = Accounts(driver) acc._itemFile_downloadAndDelete(data) driver.quit() @pytest.mark.parametrize("data", [ { "ids": "创建Group,引用子对象,可以选择Exclude或Include-T063 ", "Model": "create", "Type": 1, "Name": "", "Search type": "", } ]) def test_groupAddIncludeAndExcludeItem(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._groupAddIncludeAndExcludeItem(data) @pytest.mark.parametrize("data", [ { "ids": "一个对象至少包含一个子对象,即必须有一个是Include类型-T064&T065 ", "Model": "create", "Type": 1, "Name": "", "Search type": "", "Subordinate Objects": { "subName": "", "subItems": [ "[random]->" ], "subDescription": "" } } ]) def test_only_exclude_item(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._only_exclude_item(data) @pytest.mark.parametrize("data", data.read_data_object(r"URLs\\pages_turning.json"), ids=data.generate_id) def test_turnPagesInSubObjectsDrawer(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._turnPagesInSubObjectsDrawer(data) # @pytest.mark.repeat(10) @pytest.mark.parametrize("data", data.read_data_object(r"Accounts\\clear_counter.json"), ids=data.generate_id) def test_clear_counter(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._clear_counter(data) @pytest.mark.parametrize("data", [ { "ids": "创建Account_View_statistics_case", "Model": "create", "Type": 0, "Search type": "Name", "Name": "test_ui-account 4 statistics", "Object Statistics": "Elaborate", "Items": [ "^abcd->", "^abcd.com$->", "abcd&efgh->" ], "Description": "" }, ]) def test_view_statistics_case(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._view_statistics_case(data) @pytest.mark.parametrize("data", [ { "ids": "test_ui_itemDuplicateCheck--Create时校验", "Model": "create", "Type": 0, "Search type": "Name", "Name": "test_ui_itemDuplicateCheck", "Items": [ "itemDuplicateCheck->" ], "Description": "" }, { "ids": "test_ui_itemDuplicateCheck--仅在本Object中重复", "Model": "create", "Type": 0, "Search type": "Name", "Name": "test_ui_itemDuplicateCheck", "Items": [ "[random]->", "[random]->" ], "Description": "", "repetition_type": "1" }, { "ids": "test_ui_itemDuplicateCheck--Edit时校验", "Model": "modify", "Type": 0, "Search type": "Name", "Name": "test_ui_itemDuplicateCheck", "Items": [ "itemDuplicateCheck->", "->itemDuplicateCheck" ], "Description": "" } ]) def test_item_duplicate_check(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._item_duplicate_check(data) def pass_test_onlyViewPermission(self, demo_fixture): acc = Accounts(demo_fixture) acc._onlyViewPermission() # @pytest.mark.parametrize("data", [ # { # "ids": "创建Account,并于列表页筛选Item", # "Model": "create", # "Type": 0, # "Search type": "Name", # "Name": "", # "Items": [ # "[random]->", # "askjdjkj$" # ], # "Description": "" # }, # { # "ids": "创建Account Group,并于列表页筛选Item", # "Model": "create", # "Type": 1, # "Search type": "Name", # "Name": "", # "Items": [ # ], # "Description": "", # "Subordinate Objects": { # "subName": "", # "subItems": [ # "[random]->" # ], # "subDescription": "" # } # } # ]) # def test_list_page_item_search(self, demo_fixture, data): # acc = Accounts(demo_fixture) # acc._list_page_item_search(data) @pytest.mark.parametrize("data", [ { "ids": "test_sub_objects_drawer_search", "Model": "create", "Type": 1, "Search type": "Name", "Name": "", "Items": [ ], "Description": "", "Subordinate Objects": { "subName": "", "subItems": [ "[random]->" ], "subDescription": "" } } ]) def test_sub_objects_drawer_search(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._sub_objects_drawer_search(data) @pytest.mark.parametrize("data", [ { "ids": "test_different_vsys_check", "Model": "create", "Type": 0, "Search type": "Name", "Name": "", "Items": [ "^skjdjkj$" ], "Description": "" } ]) def test_different_vsys_check(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._different_vsys_check(data) #未修改 @pytest.mark.parametrize("data", [ { "ids": "test_audit_log_all_operation", "Model": "modify", "Type": 0, "Search type": "Name", "Name": "", "Items": [ "[random]->accounts_item导入文件.txt[ImportFromFile]" ], "Description": "" } ]) def test_audit_log_all_operation(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._audit_log_all_operation(data) @pytest.mark.parametrize("data", [ { "ids": "组合查询", "Model": "create", "Type": 0, "Name": "", "Search type": "Name&Description", "Items": [ "[random]->" ], "Description": "", "Subordinate Objects": "" } ]) def test_multiple_search(self, demo_fixture, data): acc = Accounts(demo_fixture) acc._multiple_search(data) if __name__ == '__main__': a = time.time() print(111111111111) pytest.main(['-sv', 'test_accounts.py::TestAccounts::test_nested_urlgroup', '--check-max-tb=60000']) b = time.time() c = b - a print("用时:::", c) print(3333333333333) """ # 在测试文件的当前路径执行如下命令执行测试用例: pytest –cache-clear -v pytest_json.py --alluredir ./allure # 执行如下命令生成测试报告(自动打开浏览器): allure serve allure """