コード例 #1
0
def init_login(init_driver):
    """
    login success
    :return:
    """
    myLog.info("开始执行测试:开启会话,打开网页,成功登陆")
    LoginPage(init_driver).login(C_D.user_01, C_D.passwd)
    yield init_driver
コード例 #2
0
ファイル: basepage.py プロジェクト: cxh214917/web_test
 def save_img(self, img_description):
     """
     :param img_description:图片描述,格式为:页面名称_功能名
     :return:
     """
     img_path = os.path.join(
         IMG_PATH,
         (img_description + time.strftime('%Y-%m-%d %H_%M_%S') + ".png"))
     try:
         self.drive.save_screenshot(img_path)
     except:
         myLog.exception('网页截图失败!')
         raise
     else:
         myLog.info("截图成功,截图存放在 {}".format(img_path))
コード例 #3
0
ファイル: basepage.py プロジェクト: cxh214917/web_test
 def wait_element_visible(self, loc, img_description):
     """
     等待元素可见方法
     :param loc: 元素定位表达式
     :param img_description: 图片描述,格式为:页面名称_功能名
     :return:
     """
     start = time.time()
     try:
         self.wait.until(EC.visibility_of_element_located(loc))
     except:
         myLog.exception("等待 {} 页面 {} 元素可见失败!".format(img_description, loc))
         self.save_img(img_description)
         raise
     else:
         end = time.time()
         myLog.info("等待 {} 页面 {} 元素可见成功,用时 {} 秒".format(
             img_description, loc, end - start))
コード例 #4
0
ファイル: basepage.py プロジェクト: cxh214917/web_test
 def wait_element_exist(self, loc, img_description):
     """
     等待元素存在方法
     :param loc: 元素定位表达式
     :param img_description: 图片描述,格式为:页面名称_功能名
     :return:
     """
     start = time.time()
     try:
         self.wait.until(EC.presence_of_element_located(loc))
     except:
         myLog.exception("{} 页面 {} 元素不存在".format(img_description, loc))
         self.save_img(img_description)
         raise
     else:
         end = time.time()
         myLog.info("{} 页面 {} 元素存在,用时 {} 秒".format(img_description, loc,
                                                   end - start))
コード例 #5
0
ファイル: basepage.py プロジェクト: cxh214917/web_test
 def get_element(self, loc, img_description):
     """
     查找元素方法
     :param loc: 元素定位表达式
     :param img_description: 图片描述,格式为:页面名称_功能名
     :return: element
     """
     start = time.time()
     try:
         element = self.drive.find_element(*loc)
     except:
         myLog.exception("查找 {} 页面 {} 元素失败!".format(img_description, loc))
         self.save_img(img_description)
         raise
     else:
         end = time.time()
         myLog.info("查找 {} 页面 {} 元素成功!用时 {} 秒".format(
             img_description, loc, end - start))
         return element
コード例 #6
0
ファイル: basepage.py プロジェクト: cxh214917/web_test
 def click_element(self, loc, img_description):
     """
     点击元素操作方法
     :param loc: 元素定位表达式
     :param img_description: 图片描述,格式为:页面名称_功能名
     :return: None
     """
     start = time.time()
     self.wait_element_visible(loc, img_description)
     element = self.get_element(loc, img_description)
     try:
         element.click()
     except:
         myLog.exception("点击 {} 页面 {} 元素失败!".format(img_description, loc))
         self.save_img(img_description)
         raise
     else:
         end = time.time()
         myLog.info("点击 {} 页面 {} 元素成功,用时 {} 秒".format(
             img_description, loc, end - start))
コード例 #7
0
ファイル: basepage.py プロジェクト: cxh214917/web_test
 def get_text(self, loc, img_description):
     """
     获取元素文本值方法
     :param loc: 元素定位表达式
     :param img_description: 图片描述,格式为:页面名称_功能名
     :return:text(文本值)
     """
     start = time.time()
     self.wait_element_exist(loc, img_description)
     ele = self.get_element(loc, img_description)
     try:
         text = ele.text
     except:
         myLog.exception("获取 {} 页面 {} 元素的文本值失败!".format(
             img_description, loc))
         self.save_img(img_description)
         raise
     else:
         end = time.time()
         myLog.info("获取 {} 页面 {} 元素的文本值成功,用时 {} 秒".format(
             img_description, loc, end - start))
         return text
コード例 #8
0
ファイル: basepage.py プロジェクト: cxh214917/web_test
 def input_text(self, loc, value, img_description):
     """
     输入文本值方法
     :param loc: 元素定位表达式
     :param img_description: 图片描述,格式为:页面名称_功能名
     :param value: 输入的文本值
     :return: None
     """
     start = time.time()
     self.wait_element_visible(loc, img_description)
     ele = self.get_element(loc, img_description)
     try:
         ele.send_keys(value)
     except:
         myLog.exception("在 {} 页面 {} 元素上输入文本值 {} 失败!".format(
             img_description, loc, value))
         self.save_img(img_description)
         raise
     else:
         end = time.time()
         myLog.info("在 {} 页面 {} 元素上输入文本值 {} 成功,用时 {} 秒".format(
             img_description, loc, value, end - start))
コード例 #9
0
ファイル: basepage.py プロジェクト: cxh214917/web_test
 def get_element_attribute(self, loc, name, img_description):
     """
     获取元素属性值方法
     :param loc: 元素定位表达式
     :param img_description: 图片描述,格式为:页面名称_功能名
     :param name: 属性名称
     :return: attr(属性值)
     """
     start = time.time()
     self.wait_element_exist(loc, img_description)
     ele = self.get_element(loc, img_description)
     try:
         attr = ele.get_attribute(name)
     except:
         myLog.exception("获取 {} 页面 {} 元素属性值失败!".format(
             img_description, loc))
         self.save_img(img_description)
         raise
     else:
         end = time.time()
         myLog.info("获取 {} 页面 {} 元素属性值成功,用时 {} 秒".format(
             img_description, loc, end - start))
         return attr
コード例 #10
0
def init(init_driver):
    myLog.info("开始执行测试:新建会话,最大化窗口,访问网址")
    yield init_driver
    myLog.info("测试执行完毕:退出会话")