예제 #1
0
 def setUpClass(cls):
     element = ElementState(locators=[Locator(by=By.NAME, value="q")])
     element.save()
     command = Command(command=Command.SENDKEYS,
                       element=element,
                       params="Something")
     cls.element_id = command.element.id
예제 #2
0
    def test_save_action(self):
        element = ElementState(locators=[Locator(by=By.NAME, value="q")])
        element.save()
        google_home = State(url=self.driver.current_url, elements=[element])
        google_home.save()
        action = action_builder.get_nav_action("http://www.google.com/",
                                               google_home)
        action.save()

        state1 = State(elements=[element], url="http://www.google.com")
        state1.save()

        state2 = State(elements=[element], url="http://www.google.com")

        state2.save()
        commands = [
            Command(command=Command.NAVIGATE, params="http://www.google.com/"),
            Command(command=Command.SENDKEYS,
                    element=element,
                    params="Something")
        ]
        action = Action(name="Some Action",
                        steps=commands,
                        start_state=state1,
                        end_state=state2)
        action.save()
        state1.actions = [action]
        state1.save()
        print state1.id
        assert state1.actions[0].steps == commands
        assert state1.actions[0].end_state == state2
예제 #3
0
    def test_local_suite(self):
        element = ElementState(locators=[Locator(by=By.NAME, value="q")])
        element.save()
        state1 = State(elements=[], url="")
        state2 = State(elements=[element], url="http://www.google.com")
        state1.save()
        state2.save()
        params = {}
        params["url"] = "http://www.google.com/"
        params["search"] = "Something"
        commands = [
            Command(command=Command.NAVIGATE, config_key="url"),
            Command(command=Command.SENDKEYS,
                    element=element,
                    config_key="search")
        ]
        action = Action(name="Some Action",
                        steps=commands,
                        start_state=state1,
                        end_state=state2)
        action.save()
        test = Test(name="Some test", actions=[action])
        test.save()
        suite = TestSuite(tests=[test], url="http://www.google.com/")

        config1 = RunConfig(browser="Firefox", params=params)
        config2 = RunConfig(browser="Chrome", params=params)
        configs = SuiteConfig(configs=[config1, config2], suite=suite)
        configs.save()
        suite.suite_config = configs
        suite.save()
        executor = SuiteExecutor(suite)
        executor.execute()
예제 #4
0
 def test_save_test(self):
     element = ElementState(locators=[Locator(by=By.NAME, value="q")])
     element.save()
     state1 = State(elements=[], url="")
     state2 = State(elements=[element], url="http://www.google.com")
     state1.save()
     state2.save()
     config = RunConfig(params={
         "url": "http://www.google.com/",
         "search": "Something"
     })
     commands = [
         Command(command=Command.NAVIGATE, config_key="url"),
         Command(command=Command.SENDKEYS,
                 element=element,
                 config_key="search")
     ]
     action = Action(name="Some Action",
                     steps=commands,
                     start_state=state1,
                     end_state=state2)
     action.save()
     test = Test(name="Some test", actions=[action])
     test.save()
     suite = Suite(tests=[test], url="http://www.google.com/")
     suite.execute(self.driver, config)
     suite.save()
     assert suite.suite_results[-1].passed, suite.suite_results[-1].message
예제 #5
0
 def test_invalid_command(self):
     element = ElementState(locators=[Locator(by=By.NAME, value="q")])
     element.save()
     command = Command(command="INVALID",
                       element=element,
                       params="Something")
     response = command.execute(self.driver, config=RunConfig())
     assert not response.passed, response.exception
예제 #6
0
    def setUpClass(cls):
        cls.locator = Locator(by=By.NAME, value="q")
        element = ElementState(locators = [cls.locator])
        element.save()

        state = State(elements = [element], url="http://www.google.com")
        state.save()
        cls.state_id = state.id
예제 #7
0
    def test_verify_state_action(self):

        element = ElementState(locators=[Locator(by=By.NAME, value="q")])
        element2 = ElementState(locators=[Locator(by=By.NAME, value="btnK")])
        element.save()
        element2.save()
        state1 = State(elements=[], url="")
        state1.save()

        state = State(elements=[element], url="http://www.google.com")
        state.save()
        verify_state = action_builder.get_verify_state_action(state)
        commands = [Command(command=Command.NAVIGATE, config_key="url")]
        action = Action(name="Google Nav",
                        steps=commands,
                        start_state=state1,
                        end_state=state)
        action.save()
        state.actions = []

        results = action.execute(
            self.driver,
            config=RunConfig(params={
                "url": "http://www.google.com/",
                "search": "Something"
            }))
예제 #8
0
    def test_execute(self):

        element = ElementState(locators=[Locator(by=By.NAME, value="q")])
        element2 = ElementState(locators=[Locator(by=By.NAME, value="btnG")])
        element.save()
        element2.save()
        state1 = State(elements=[], url="")
        state2 = State(elements=[element], url="http://www.google.com")
        state3 = State(elements=[element2], url="http://www.google.com")
        state1.save()
        state2.save()
        state3.save()
        commands = [
            Command(command=Command.NAVIGATE, config_key="url"),
            Command(command=Command.SENDKEYS,
                    element=element,
                    config_key="search"),
            Command(command=Command.CLICK, element=element2)
        ]
        action = Action(name="Google Search",
                        steps=commands,
                        start_state=state1,
                        end_state=state3)
        action.save()
        results = action.execute(
            self.driver,
            config=RunConfig(params={
                "url": "http://www.google.com/",
                "search": "Something"
            }))
예제 #9
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)
예제 #10
0
    def test_sauce_suite(self):
        element = ElementState(locators=[Locator(by=By.NAME, value="q")])
        element.save()
        state1 = State(elements=[], url="")
        state2 = State(elements=[element], url="http://www.google.com")
        state1.save()
        state2.save()
        params = {}
        params["url"] = "http://www.google.com/"
        params["search"] = "Something"
        commands = [
            Command(command=Command.NAVIGATE, config_key="url"),
            Command(command=Command.SENDKEYS,
                    element=element,
                    config_key="search")
        ]
        action = Action(name="Some Action",
                        steps=commands,
                        start_state=state1,
                        end_state=state2)
        action.save()
        test = Test(name="Some test", actions=[action])
        test.save()
        suite = TestSuite(tests=[test], url="http://www.google.com/")

        config1 = RunConfig(browser="iphone",
                            sauce_user="******",
                            host="sauce",
                            sauce_key="c479e821-57e7-4b3f-8548-48e520585187",
                            params=params)
        config2 = RunConfig(browser="ipad",
                            sauce_user="******",
                            shost="sauce",
                            auce_key="c479e821-57e7-4b3f-8548-48e520585187",
                            params=params)
        configs = SuiteConfig(configs=[config1], suite=suite)
        configs.save()
        suite.suite_config = configs
        suite.save()
        executor = SuiteExecutor(suite)
        executor.execute()
예제 #11
0
    def test_get_compare(self):

        element = ElementState(
            locators=[Locator(by=By.LINK_TEXT, value="Images")])
        element.save()
        element2 = ElementState(
            locators=[Locator(by=By.NAME, value="INVALID")])
        element2.save()
        state2 = State(elements=[element, element2],
                       url="http://www.google.com")
        state2.save()

        self.driver.get("http://www.google.com")
        comparer = StateComparer(self.driver)
        comparison = comparer.compare_to_live_state(state2)

        assert comparison == (1, 20), comparison
예제 #12
0
def build_element(driver, element):
    builder = LocatorBuilder(driver, element)
    locators = builder.get_locators()
    if(len(locators)) > 0:
        new_element = ElementState(locators=locators, html=element.html, screenshot=element.screenshot_as_base64)
        new_element.set_location(element)
        # new_element.type = ElementMatcher().match(element)
        new_element.save()
        WebElement(driver,new_element.locators).highlight()
        return new_element
예제 #13
0
    def test_update_element_locator(self):
        state = State.objects(id=self.state_id).first()
        element = state.elements[0]
        old_locator = element.locators[0]
        element_id = element.id
        new_locator = Locator(by=By.XPATH,value="//something")
        new_element = ElementState.objects(id=element_id).first()
        new_element.locators[0] = new_locator
        new_element.save()

        newstate = State.objects(id=self.state_id).first()
        element = newstate.elements[0]
        newlocator = element.locators[0]

        assert newlocator == new_locator
        assert newlocator != old_locator
예제 #14
0
 def test_failure_report(self):
     element = ElementState(locators=[Locator(by=By.NAME, value="INVALID")])
     element2 = ElementState(
         locators=[Locator(by=By.NAME, value="INVALID")])
     element.save()
     element2.save()
     state1 = State(elements=[], url="")
     state2 = State(elements=[element], url="http://www.google.com")
     state3 = State(elements=[element2], url="http://www.google.com")
     state1.save()
     state2.save()
     state3.save()
     commands = [
         Command(command=Command.NAVIGATE,
                 config_key="http://www.google.com/"),
         Command(command=Command.SENDKEYS,
                 element=element,
                 config_key="search"),
         Command(command=Command.CLICK, element=element2)
     ]
     action = Action(name="Google Search",
                     steps=commands,
                     start_state=state1,
                     end_state=state3)
     action.save()
     test = Test(name="Some test", actions=[action])
     test.save()
     suite = Suite(name="some name", tests=[test])
     suite.execute(self.driver,
                   config=RunConfig(params={
                       "url": "http://www.google.com/",
                       "search": "Something"
                   }))
     suite.save()
     assert not suite.suite_results[-1].passed
     assert suite.suite_results[-1].actual_state is not None
     assert suite.suite_results[-1].failed_state is not None
     assert suite.suite_results[-1].html is not None and not ""
     assert suite.suite_results[-1].screenshot is not None and not ""
예제 #15
0
 def get_state(self, driver):
     parser = PageParser(driver)
     locator_elements = []
     elements = parser.get_all_elements()
     print "Found %s elements " % len(elements)
     for element in elements:
         builder = LocatorBuilder(driver, element)
         locators = builder.get_locators()
         if(len(locators)) > 0:
             new_element = ElementState(locators=locators, html=element.html[:255], screenshot=element.screenshot_as_base64)
             new_element.set_location(element)
             new_element.save()
             locator_elements.append(new_element)
             WebElement(driver,new_element.locators).highlight()
     screenshot = driver.get_screenshot_as_base64()
     state = State(elements=locator_elements,url=driver.current_url, html=driver.html, screenshot = screenshot)
     return state
예제 #16
0
    def test_send_keys(self):
        self.driver.get("http://www.google.com/")
        command = Command(driver=self.driver, command=Command.SENDKEYS,element=ElementState(locators=[Locator(by=By.NAME,value="q")]),config_key="search")
        command.execute(self.driver, config=RunConfig(params={"search":"Something"}))

        assert WebElement(self.driver, [Locator(by=By.NAME,value="q")]).value == "Something"
예제 #17
0
 def setUpClass(cls):
     element = ElementState(locators=[Locator(by=By.NAME, value="q")])
     element.save()
     cls.element_id = element.id
예제 #18
0
 def test_params(self):
     element = ElementState(locators=[Locator(by=By.NAME, value="q")])
     element.save()
     command = Command(command=Command.SENDKEYS,
                       element=element,
                       params="Something")
예제 #19
0
 def test_get_element(self):
     elements = ElementState.objects(id=self.element_id)
     for element in elements:
         print element.id
예제 #20
0
 def test_click(self):
     self.driver.get("http://www.google.com/")
     command = Command(driver=self.driver, command=Command.CLICK,element=ElementState(locators=[Locator(by=By.NAME,value="q")]))
     command.execute(self.driver, config=RunConfig())