def get_locate(self, command):
     doms = None
     try:
         selector = command.element_selector
         value = command.element_value
         if util.similar('id', selector):
             doms = (By.ID, value)
         elif util.similar('name', selector):
             doms = (By.NAME, value)
         elif util.similar('css_selector', selector):
             doms = (By.CSS_SELECTOR, value)
         elif util.similar('css', selector):
             doms = (By.CSS_SELECTOR, value)
         elif util.similar('link_text', selector):
             doms = (By.LINK_TEXT, value)
         elif util.similar('xpath', selector):
             doms = (By.XPATH, value)
         elif util.similar('partial_link_text', selector):
             doms = (By.PARTIAL_LINK_TEXT, value)
         elif util.similar('tag_name', selector):
             doms = (By.TAG_NAME, value)
         elif util.similar('class_name', selector):
             doms = (By.CLASS_NAME, value)
     except Exception as e:
         self.create_error(command, e)
     pass
     return doms
 def _element(self, command):
     doms = None
     try:
         selector = command.element_selector
         value = command.element_value
         if util.similar('id', selector):
             doms = self.driver.find_elements_by_id(value)
         elif util.similar('name', selector):
             doms = self.driver.find_elements_by_name(value)
         elif util.similar('css_selector', selector):
             doms = self.driver.find_elements_by_css_selector(value)
         elif util.similar('css', selector):
             doms = self.driver.find_elements_by_css_selector(value)
         elif util.similar('link_text', selector):
             doms = self.driver.find_elements_by_link_text(value)
         elif util.similar('xpath', selector):
             doms = self.driver.find_elements_by_xpath(value)
         elif util.similar('partial_link_text', selector):
             doms = self.driver.find_elements_by_partial_link_text(value)
         elif util.similar('tag_name', selector):
             doms = self.driver.find_elements_by_tag_name(value)
         elif util.similar('class_name', selector):
             doms = self.driver.find_elements_by_class_name(value)
         if doms is None:
             self.create_error(command, None, " 未找到有效命令:" + selector)
         elif doms.__len__() == 0:
             self.create_error(command, None,
                               " 选择器未找到任何元素:[" + command.element + "]")
     except Exception as e:
         self.create_error(command, e)
     return doms
Exemple #3
0
 def run_before_condition(self, command):
     dom = None
     action = command.action
     if action is not None:
         for one in action:
             if util.similar('sleep', one.name):
                 condition = self.get_locate(command)
                 dom = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(condition))
             if util.similar('deleteCookies', one.name):
                 self.driver.delete_all_cookies()
     return dom
Exemple #4
0
 def run_no_ele_action(self, command_action):
     for action in command_action:
         if util.similar('sleep', action.name):
             # sleep 命令暂时不生效, 现在是全局等待上限时间10秒
             #time.sleep(command_action.value)
             #self.driver.implicity_wait(10)
             #WebDriverWait(self.driver, 10)
             #dom = self.driver.find_element_by_link_text("登录")
             #WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.LINK_TEXT, "日程")))
             #WebDriverWait(self.driver, 10).until(EC.presence_of_element_located())
             pass
         if util.similar('logout', action.name):
             self.logout()
     pass
 def _no_element_action(self, command):
     try:
         actions = command.action
         if actions is not None:
             for action in actions:
                 if util.similar('sleep', action.name):
                     # sleep 命令暂时不生效, 现在是全局等待上限时间10秒
                     #WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.LINK_TEXT, "日程")))
                     pass
                 if util.similar('logout', action.name):
                     mc_logout(self.driver)
                 elif util.similar('homepage', action.name):
                     mc_homepage(self.driver, self.url)
                 elif util.similar('homepageWithCookie', action.name):
                     mc_homepage_with_cookie(self.driver, self.url)
     except Exception as e:
         self.create_error(command, e)
     pass
 def _before_action(self, command):
     dom = None
     try:
         action = command.action
         # 需要元素的命令
         if command.element_selector:
             if action is not None:
                 for one in action:
                     if util.similar('sleep', one.name):
                         sleep_time = get_int(one.value)
                         if not sleep_time:
                             sleep_time = 10
                         condition = self.get_locate(command)
                         dom = WebDriverWait(self.driver, sleep_time).until(
                             EC.presence_of_element_located(condition))
         # 不需要元素的命令
         if action is not None:
             for one in action:
                 if util.similar('deleteCookies', one.name):
                     self.driver.delete_all_cookies()
     except Exception as e:
         self.create_error(command, e)
     return dom
Exemple #7
0
 def run_dom(self, command):
     doms = None
     selector = command.element_selector
     value = command.element_value
     if util.similar('id',selector):
         doms = self.driver.find_elements_by_id(value)
     elif util.similar('name',selector):
         doms = self.driver.find_elements_by_name(value)
     elif util.similar('css_selector',selector):
         doms = self.driver.find_elements_by_css_selector(value)
     elif util.similar('link_text',selector):
         doms = self.driver.find_elements_by_link_text(value)
     elif util.similar('xpath', selector):
         doms = self.driver.find_elements_by_xpath(value)
     elif util.similar('partial_link_text', selector):
         doms = self.driver.find_elements_by_partial_link_text(value)
     elif util.similar('tag_name', selector):
         doms = self.driver.find_elements_by_tag_name(value)
     elif util.similar('class_name', selector):
         doms = self.driver.find_elements_by_class_name(value)
     return doms
 def _action(self, doms, command):
     try:
         actions = command.action
         if actions is not None:
             for action in actions:
                 self.action_value_parse(action, command)
                 if doms:
                     for dom in doms:
                         if util.similar('click', action.name):
                             dom.click()
                         elif util.similar('send_keys', action.name):
                             dom.send_keys(action.value)
                         elif util.similar('clear', action.name):
                             dom.clear()
                         elif util.similar('is_selected', action.name):
                             result = dom.is_selected()
                             if util.similar('false', action.value):
                                 if result:
                                     self.create_error(
                                         command, None, "选择状态判断错误,当前是" +
                                         result + "期待是false")
                                     return
                             elif util.similar('true', action.value):
                                 if not result:
                                     self.create_error(
                                         command, None, "选择状态判断错误,当前是" +
                                         result + "期待是true")
                                     return
                         elif util.similar('check', action.name):
                             if not action.name:
                                 self.create_error(command, None,
                                                   "行为check缺少检查对象")
                                 return
                             if not dom.text == action.value:
                                 self.create_error(command, None,
                                                   "check行为无法完全匹配value值")
                                 return
     except Exception as e:
         self.create_error(command, e)
     pass
Exemple #9
0
 def run_one_action(self, doms, command_action):
     # 合法性检测,其实不该在这,应该在受查异常中进行检测,但受查异常目前只写了通用基类,没有写单属于selenium的受查异常类
     self.action_value_parse(command_action)
     if doms:
         for dom in doms:
             if util.similar('click', command_action.name):
                 dom.click()
             elif util.similar('send_keys', command_action.name):
                 dom.send_keys(command_action.value)
             elif util.similar('clear', command_action.name):
                 dom.clear()
             elif util.similar('is_selected', command_action.name):
                 result = dom.is_selected()
                 if util.similar('false', command_action.value):
                     if result:
                         self.fail_log = "命令" + self.command_entity.command + "选择状态判断错误,当前是"+ result + "期待是false"
                 elif util.similar('true', command_action.value):
                     if not result:
                         self.fail_log = "命令" + self.command_entity.command + "选择状态判断错误,当前是"+ result + "期待是true"
     pass