def mark_status(flag): if flag: all_logs(Fail) testlink(Fail + '\n') else: all_logs(Pass) testlink(Pass + '\n')
def log_assert(self, log_text='', expected_text=list(), end=''): all_logs('期望结果:操作触发生成的log中包括' + str(expected_text)) for text in expected_text: if text not in log_text: self.FailedFlag = True all_logs('实际结果:操作触发生成的log:\n' + log_text.replace('[01;31m[K', '').replace('[m[K', '')) testlink('操作触发生成的log:\n' + log_text.replace('[01;31m[K', '').replace('[m[K', '')) testlink(end)
def click_action(self, path, location, locator=By.XPATH, response_time=3): try: self.driver.find_element(locator, path).click() time.sleep(response_time) except Exception as e: print(e) self.FailedFlag = True all_logs(location + ' is not found') testlink(location + ' is not found')
def mark_status(self): if self.FailedFlag: all_logs('-*- The case is executed -*-\n') all_logs(self.Fail) testlink(self.Fail + '\n') self.FailedFlag = False else: all_logs('-*- The case is executed -*-\n') all_logs(self.Pass) testlink(self.Pass + '\n')
def fill_action(self, path, value, location, locator=By.XPATH, response_time=1): try: self.driver.find_element(locator, path).clear() self.driver.find_element(locator, path).send_keys(value) time.sleep(response_time) except Exception as e: print(e) self.FailedFlag = True all_logs(location + ' is not found') testlink(location + ' is not found')
def element_not_exist_assert(self, path, location, end='', locator=By.XPATH): try: all_logs('期望结果: ' + location + '不存在') self.driver.find_element(locator, path) except: all_logs('实际结果: ' + location + '不存在') testlink(location + '不存在') testlink(end) else: self.FailedFlag = True all_logs('实际结果: ' + location + ' 存在') testlink(location + ' 存在') testlink(end)
def equal_text_assert(self, path, location, expected_text, end='', locator=By.XPATH): try: all_logs('期望结果: ' + location + ': ' + expected_text) actual_text = self.driver.find_element(locator, path).text all_logs('实际结果: ' + location + ': ' + actual_text) testlink(location + ': ' + actual_text) testlink(end) if actual_text != expected_text: self.FailedFlag = True except Exception as e: self.FailedFlag = True all_logs('实际结果: ' + str(e)) testlink(str(e)) testlink(end) all_logs(location + ' is not found\n')
def element_attribute(self, path, location, attr_name, expected, end='', locator=By.XPATH): try: attr = self.driver.find_element(locator, path).get_attribute(attr_name) all_logs('期望结果:' + location + '的' + attr_name + '属性值为' + expected) all_logs('实际结果:' + location + '的' + attr_name + '属性值为' + attr) testlink(location + '的' + attr_name + '属性值为' + attr) testlink(end) if attr != expected: self.FailedFlag = True except Exception as e: self.FailedFlag = True all_logs('实际结果: ' + str(e)) testlink(str(e)) testlink(end) all_logs(location + ' is not found\n')
def no_text_assert(self, path, location, expected_text=list(), end='', locator=By.XPATH): try: all_logs('期望结果: ' + location + '中不包括' + str(expected_text)) page_text = self.driver.find_element(locator, path).text all_logs('实际结果: ' + location + '中内容为”\n' + page_text + '"') testlink(location + '中内容为”\n' + page_text + '"') testlink(end) for t in expected_text: if t in page_text: self.FailedFlag = True except Exception as e: self.FailedFlag = True all_logs('实际结果: ' + str(e)) testlink(str(e)) testlink(end) all_logs(location + ' is not found\n')
def contained_text_assert(self, path, location, expected_text=list(), end='', locator=By.XPATH): try: all_logs('期望结果: ' + location + '包括: ' + str(expected_text)) actual_text = self.driver.find_element(locator, path).text all_logs('实际结果: ' + location + ': \n' + actual_text) testlink(location + ': ' + actual_text) testlink(end) for t in expected_text: if t not in actual_text: self.FailedFlag = True except Exception as e: self.FailedFlag = True all_logs('实际结果: ' + str(e)) testlink(str(e)) testlink(end) all_logs(location + ' is not found\n')