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
138
139
140
141
142
143
import random
 
from base.base_page import BasePage
from elements.vaq_answer_elements import VAQAnswerElements
from selenium.common.exceptions import *
from selenium.webdriver.common.by import By
import time
import re
 
 
class VAQAnswerPage(BasePage):
    """
    答题页面
    """
    loading_count = 0
 
    elements = VAQAnswerElements
 
    slice_count = 9
 
    def answer(self):
        time.sleep(3)
        # 点击开始测试
        self.click(self.elements.start_btn)
        time.sleep(2)
        # 点击继续测试
        self.click(self.elements.start_btn)
 
        pre_pictures = self.get_eles(self.elements.pre_picture_btn, 10)
 
        print("VAQ预选图片中...")
        time.sleep(1)
        for pre_picture in pre_pictures:
            self.driver.execute_script("arguments[0].click();", pre_picture)
            time.sleep(0.5)
 
        # 点击下一步
        self.click(self.elements.start_btn)
 
        time.sleep(1)
        for i in range(0, self.slice_count):
            print(f"当前是VAQ第{i+1}步")
            # 获取当前所需图片数量的文字
            picture_count_text = self.get_ele(self.elements.current_require_picture_count)
            pictures = self.get_eles(self.elements.picture_btn, 10)
            match = re.search(r"(\d+) / (\d+)", picture_count_text.text)
            total = int(match.group(2))
            if (i + 1) != self.slice_count:
                for k in range(0, total):
                    self.driver.execute_script("arguments[0].click();", pictures[k])
                    time.sleep(0.2)
            if i == 0:
                self.click(self.elements.start_btn)
            else:
                self.click(self.elements.next_btn)
                time.sleep(1)
        time.sleep(2)
        # 提交
        self.click(self.elements.submit_btn)
 
    def upload_is_success(self):
        """
        判断数据是否上传完成
        :return:
        """
        i = 0
        while i < 60:
            try:
                self.get_element_wait(Answer.upload_success_title)
                return True
            except TimeoutException:
                i += 1
                time.sleep(1)
        return False
 
    def submit_btn_is_display(self):
        """
        判断提交按钮是否存在
        :return:
        """
        try:
            button = self.get_element(Answer.submit_btn)
            if button.is_enabled():
                return True
            else:
                return False
        except NoSuchElementException:
            return False
 
    def continue_btn_is_display(self):
        """
        判断继续测试按钮是否出现
        :return: bool
        """
        try:
            # 点击继续测试按钮
            button = self.get_element(Answer.continue_testing_btn)
            if button.is_enabled():
                return True
            else:
                return False
        except NoSuchElementException:
            return False
 
    def title_is_display(self):
        """
        判断标题是否出现
        :return: bool
        """
        try:
            # 获取标题
            self.get_element_wait(Answer.title)
            return True
        except TimeoutException:
            return False
 
    def loadin_text(self):
        """
        判断加载框加载,如果加载超过10秒直接退出当前测试
        :return:
        """
        i = 0
        while i < 10:
            try:
                self.get_element(Answer.loading_text)
                i += 1
                time.sleep(1)
            except:
                return False
        else:
            return True
 
    def start_btn(self):
        """
        开始测试按钮
        :return:
        """
        self.click_wait(Answer.start_btn)
        time.sleep(1)
        self.click_wait(Answer.start_btn)
        time.sleep(1)
        self.click_wait(Answer.start_btn)
        time.sleep(1)