示例#1
0
 def crawl_state(self, state):
     for element in state.elements:
         try:
             state.initialize_state(self.driver)
             print "Loaded initial state %s" % state.id
             webelement = WebElement(self.driver, element.locators)
             if webelement.is_displayed():
                 webelement.click()
                 new_state = state_builder.get_current_state(self.driver)
                 if new_state == state:
                     print "looks like this is the same state"
                 else:
                     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()
             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
示例#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