Exemplo n.º 1
0
def get_nav_action(url, end_state):
    command1 = Command(command=Command.NAVIGATE, config_key="url")
    action = Action(name="Get %s" % url,
                    steps=[command1],
                    start_state=state_builder.get_blank_state(),
                    end_state=end_state)
    action.save()
    return action
Exemplo n.º 2
0
    def test_init_state(self):
        self.url = "http://www.google.com"
        blank_state = state_builder.get_blank_state()
        blank_state.save()
        self.driver.get(self.url)
        state = state_builder.get_current_state(self.driver)
        state.save()
        element = ElementState(locators=[Locator(by=By.NAME, value="q")])
        element2 = ElementState(locators=[Locator(by=By.NAME, value="btnG")])
        element.save()
        element2.save()
        nav_command = [Command(command=Command.NAVIGATE, config_key="url")]
        type_command = [
            Command(command=Command.SENDKEYS,
                    element=element,
                    config_key="search"),
            Command(command=Command.SENDKEYS,
                    element=element,
                    config_key="enter")
        ]

        action = Action(name="Navigate",
                        steps=nav_command,
                        start_state=blank_state,
                        end_state=state)
        action.save()
        action2 = Action(name="Search",
                         steps=type_command,
                         start_state=state,
                         end_state=blank_state)
        action2.save()
        config = RunConfig(
            params={
                "url": "http://www.google.com/",
                "search": "Something",
                "enter": Keys.ENTER
            })
        action.execute(self.driver, config)
        action2.execute(self.driver, config)
        time.sleep(5)
        new_state = state_builder.get_current_state(self.driver)
        new_state.save()
        action2.end_state = new_state
        action2.save()

        new_state.init_actions = [action, action2]
        new_state.save()
        state_id = new_state.id

        print state_id

        self.driver.get("http://www.msn.com/")

        new_state.initialize_state(self.driver, config)
Exemplo n.º 3
0
 def crawl_url(self, url):
     self.driver.get(url)
     initial_state = state_builder.get_current_state(self.driver)
     initial_state.save()
     blank_state = state_builder.get_blank_state()
     blank_state.save()
     nav_action = action_builder.get_nav_action(url, initial_state)
     nav_action.save()
     initial_state.init_actions = [nav_action]
     initial_state.save()
     print "Saved initial state %s" % initial_state.id
     return initial_state
Exemplo n.º 4
0
    def test_compare_state(self):
        self.driver.get("http://www.google.com/")
        state1 = state_builder.get_blank_state()
        state1.save()
        state2 = state_builder.get_current_state(self.driver)
        state2.save()
        self.driver.get("https://www.google.com/#q=something")
        state3 = state_builder.get_current_state(self.driver)
        state3.save()
        config = RunConfig(params={
            "url": "http://www.google.com/",
            "search": "Something"
        })
        search_fields = element_filter.filter_contains_text(
            state2.elements, "Search")
        search_field = search_fields[0]
        commands1 = [Command(command=Command.NAVIGATE, config_key="url")]
        commands2 = [
            Command(command=Command.SENDKEYS,
                    element=search_field,
                    config_key="search")
        ]
        nav_action = Action(name="Google Nav",
                            steps=commands1,
                            start_state=state1,
                            end_state=state2)
        search_action = Action(name="Google Search",
                               steps=commands2,
                               start_state=state2,
                               end_state=state3)
        nav_action.save()
        search_action.save()
        test = Test(name="Google Search Failure",
                    actions=[nav_action, search_action])
        test.save()
        suite = Suite(name="Failure Example", tests=[test])
        suite.execute(self.driver, config)
        suite.save(cascade=True)
        print suite.id
        assert suite.suite_results[-1].passed

        search_field.locators = [Locator(by=By.CLASS_NAME, value="INVALID")]
        search_field.save()
        suite.execute(self.driver, config=config)
        results = suite.suite_results[-1]
        assert not results.passed

        comparison = StateComparer(self.driver).compare_states(
            results.failed_state, results.actual_state)

        assert len(comparison[0].elements) == len(comparison[1].elements)