Ejemplo n.º 1
0
 def click(self, idpro, value):
     el = self.webObject.testEle(idpro=idpro, value=value)
     try:
         el.click()
         log.info("单击,根据对象{0}[{1}],操作成功".format(idpro, value))
     except AssertionError as e:
         screenshotdir = saveScreenShot(self.driver)
         log.error("单击,根据对象{0}[{1}],单击失败,错误截图请见:{2}".format(
             idpro, value, screenshotdir))
         raise e
Ejemplo n.º 2
0
 def deselectIndex(self, idpro, value, selectIndex):
     el = self.webObject.testEle(idpro=idpro, value=value)
     try:
         s = Select(el)
         s.deselect_by_index(selectIndex)
         log.info("取消按index选择,根据对象{0}[{1}],取消选择成功".format(idpro, value))
     except AssertionError as e:
         screenshotdir = saveScreenShot(self.driver)
         log.error("取消按index选择,根据对象{0}[{1}],取消选择失败,错误截图请见:{2}".format(
             idpro, value))
         raise e
Ejemplo n.º 3
0
 def selectText(self, idpro, value, selectValue):
     el = self.webObject.testEle(idpro=idpro, value=value)
     try:
         s = Select(el)
         s.select_by_visible_text(selectValue)
         log.info("按显示文本选择,根据对象{0}[{1}],选择成功".format(idpro, value))
     except AssertionError as e:
         screenshotdir = saveScreenShot(self.driver)
         log.error("按显示文本选择,根据对象{0}[{1}],选择失败错误截图请见:{2}".format(
             idpro, value, screenshotdir))
         raise e
Ejemplo n.º 4
0
 def sendkey(self, idpro, value, inputv):
     el = self.webObject.testEle(idpro=idpro, value=value)
     try:
         el.clear()
         el.send_keys(inputv)
         log.info("输入,根据对象{0}[{1}],输入成功".format(idpro, value))
     except AssertionError as e:
         screenshotdir = saveScreenShot(self.driver)
         log.error("输入,根据对象{0}[{1}],输入失败,错误截图请见:{2}".format(
             idpro, value, screenshotdir))
         raise e
Ejemplo n.º 5
0
 def mouseOn(self, idpro, value):
     el = self.webObject.testEle(idpro=idpro, value=value)
     try:
         actions = ActionChains(self.webObject.driver)
         actions.move_to_element(el)
         actions.perform()
         log.info("鼠标悬停,根据对象{0}[{1}],鼠标悬停成功".format(idpro, value))
     except AssertionError as e:
         screenshotdir = saveScreenShot(self.driver)
         log.error("鼠标悬停,根据对象{0}[{1}],鼠标悬停失败,错误截图请见:{2}".format(
             idpro, value, screenshotdir))
         raise e
Ejemplo n.º 6
0
 def mouseDrag(self, idpro, value, target):
     el = self.webObject.testEle(idpro=idpro, value=value)
     try:
         target = self.webObject.testEle(idpro=idpro, value=target)
         actions = ActionChains(self.driver)
         actions.drag_and_drop(el, target).perform()
         actions.release()
         log.info("鼠标拖拽,根据对象{0}[{1}],鼠标拖拽成功".format(idpro, value))
     except AssertionError as e:
         screenshotdir = saveScreenShot(self.driver)
         log.error("鼠标拖拽,根据对象{0}[{1}],鼠标拖拽失败,错误截图请见:{2}".format(
             idpro, value, screenshotdir))
         raise e
Ejemplo n.º 7
0
 def mouseOperate(self, ovalue, idpro, value):
     el = self.webObject.testEle(idpro=idpro, value=value)
     try:
         actions = ActionChains(self.driver)
         if ovalue == "":
             screenshotdir = saveScreenShot(self.driver)
             log.error("鼠标操作,根据对象{0}[{1}],鼠标操作失败,错误截图请见:{2}".format(
                 idpro, value, screenshotdir))
             raise AssertionError
         else:
             if ovalue == "左击":
                 actions.click(el).perform()
             if ovalue == "右击":
                 actions.context_click(el).perform()
             if ovalue == "双击":
                 actions.double_click(el).perform()
             log.info("鼠标点击,根据对象{0}[{1}],鼠标点击操作成功".format(idpro, value))
     except AssertionError as e:
         screenshotdir = saveScreenShot(self.driver)
         log.error("鼠标点击操作,根据对象{0}[{1}],鼠标点击操作失败,错误截图请见:{2}".format(
             idpro, value, screenshotdir))
         raise e
Ejemplo n.º 8
0
 def testEle(self, idpro, value):
     try:
         if idpro.lower() == "id":
             el = self.driver.find_element_by_id(value)
         elif idpro.lower() == "xpath":
             el = self.driver.find_element_by_xpath(value)
         elif idpro.lower() == "class":
             el = self.driver.find_element_by_class_name(value)
         elif idpro.lower() == "css":
             el = self.driver.find_element_by_css_selector(value)
         elif idpro.lower() == "tagname":
             el = self.driver.find_element_by_tag_name(value)
         elif idpro.lower() == "linktext":
             el = self.driver.find_element_by_link_text(value)
         else:
             print("类型错误")
     except Exception as e:
         screenshotdir = saveScreenShot(self.driver)
         log.error("定位元素,根据对象{0}[{1}]定位失败,错误截图请见:{2}".format(
             idpro, value, screenshotdir))
         raise e
     return el