yj
2024-07-25 c0dc1bc9676d0bc15355cfd16e9bb92a31518aa8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import os
from datetime import datetime
import time
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
 
import pytest
from comm.comm import *
from comm.read_data import *
from comm.write_data import *
from selenium import webdriver
from po.login_page import LoginPage
from po.home_page import HomePage
from po.group_report_page import GroupReportPage
from po.member_detail_page import MemberDetailPage
from po.report_page import ReportPage
from po.share_add_page import ShareAddPage
from po.maq_answer_page import MAQAnswerPage
from po.caq_answer_page import CAQAnswerPage
from comm.my_random import *
 
 
class TestGroupReport:
    driver = None
    name = "MAQV2自动测试包-20230727155906"
    member_email = None
 
    @pytest.mark.parametrize('data_read', ["groupReport"], indirect=True)
    def test_add(self, data_read: dict, driver):
        home = HomePage(driver)
        home.menu_select("测试包管理/组别报告")
        group = GroupReportPage(driver)
        # 点击新增按钮
        group.click(group.es.add_btn)
        # 切换iframe
        group.switch_iframe(group.es.add_iframe)
        # 获取随机名称
        name = "组别报告-" + random_string(8)
        TestGroupReport.name = name
        # 输入名称
        group.fill(group.es.add_name_input, name)
        # 文件路径
        # 获取当前项目根路径
        root_path = os.getcwd()
        # 拼接文件路径
        if "\\testcase" in root_path:
            root_path = root_path[0:root_path.rfind("\\testcase")]
        file_path = root_path + r"\data\MAQ_group_data.xlsx"
        # 传入文件
        group.fill(group.es.add_load_file_input, file_path)
        # 切换iframe
        group.switch_parent_iframe()
        # 点击确认按钮
        group.click(group.es.layer_confirm_btn)
        time.sleep(10)
 
    @pytest.mark.parametrize('data_read', ["testPackageList"], indirect=True)
    def test_group_data(self, data_read: dict, driver):
        group = GroupReportPage(driver)
        # 输入名称
        group.fill(group.es.add_name_input, TestGroupReport.name)
        # 点击搜索按钮
        group.click(group.es.search_btn)
 
        # 获取当前项目根路径
        root_path = os.getcwd()
        # 拼接下载文件目录
        if "\\testcase" in root_path:
            root_path = root_path[0:root_path.rfind("\\testcase")]
        dir_path = root_path + r"\download"
        # 获取目录下所有文件
        old_file_names = []
        for filename in os.listdir(dir_path):
            if os.path.isfile(os.path.join(dir_path, filename)):
                old_file_names.append(filename)
 
        # 点击组别数据
        group.click(group.es.group_data_btn)
 
        i = 0
        while i < data_read["downloadWaitTime"]:
            # 获取目录下所有文件
            new_file_names = []
            for filename in os.listdir(dir_path):
                if os.path.isfile(os.path.join(dir_path, filename)):
                    new_file_names.append(filename)
            # 判断旧文件的数量与新文件的数量是否相同,相同则睡眠一秒
            if len(old_file_names) == len(new_file_names):
                time.sleep(1)
                i += 1
                continue
            else:
                # 否则直接退出循环
                break
        else:
            assert False
 
    @pytest.mark.parametrize('data_read', ["testPackageList"], indirect=True)
    def test_group_report(self, data_read: dict, driver):
        group = GroupReportPage(driver)
        # 获取当前项目根路径
        root_path = os.getcwd()
        # 拼接下载文件目录
        if "\\testcase" in root_path:
            root_path = root_path[0:root_path.rfind("\\testcase")]
        dir_path = root_path + r"\download"
        # 获取目录下所有文件
        old_file_names = []
        for filename in os.listdir(dir_path):
            if os.path.isfile(os.path.join(dir_path, filename)):
                old_file_names.append(filename)
 
        # 点击组别数据
        group.click(group.es.group_report_btn)
 
        i = 0
        while i < data_read["downloadWaitTime"]:
            # 获取目录下所有文件
            new_file_names = []
            for filename in os.listdir(dir_path):
                if os.path.isfile(os.path.join(dir_path, filename)):
                    new_file_names.append(filename)
            # 判断旧文件的数量与新文件的数量是否相同,相同则睡眠一秒
            if len(old_file_names) == len(new_file_names):
                time.sleep(1)
                i += 1
                continue
            else:
                # 否则直接退出循环
                break
        else:
            assert False
 
 
if __name__ == '__main__':
    pytest.main(["-s", __file__])