Ejemplo n.º 1
0
 def find_input(self, start_state, element_types):
     for element in start_state.elements:
         if "<input" in element.html:
             field = WebElement(self.driver, element.locators)
             field.highlight(color="green")
             if field.is_editable() and element.type in element_types:
                 return element
     # raise Exception("Could find %s field in state : %s" % (element_types,start_state.id))
     return None
Ejemplo n.º 2
0
 def crawl_state(self, state):
     for element in state.elements[:20]:
         try:
             state.initialize_state(self.driver)
             print "Loaded initial state %s" % state.id
             webelement = WebElement(self.driver, element.locators)
             if webelement.is_displayed():
                 print "Clicking %s" % element
                 webelement.highlight(length=2, color="red")
                 webelement.click()
                 domain = url_parser.get_domain_from_url(
                     self.driver.current_url)
                 if domain not in state.url:
                     print "State is different domain"
                     break
                 if state.is_state_present(self.driver):
                     print "looks like this is the same state"
                 else:
                     new_state = state_builder.get_current_state(
                         self.driver)
                     new_state.save()
                     print 'new state found at %s %s' % (
                         self.driver.current_url, new_state.id)
                     click_action = action_builder.get_click_action(
                         element, state, new_state)
                     new_state.init_actions = state.init_actions
                     new_state.init_actions.append(click_action)
                     new_state.save()
                     state.actions.append(click_action)
                     state.save()
                     self.put(new_state)
             else:
                 logging.error(
                     "Could not reproduce state %s element %s not present" %
                     (state, element))
         except Exception as e:
             print "Couldn't crawl element %s %s" % (element.locators,
                                                     str(e))
     return state