示例#1
0
    def test_has_element_with_locator(self):
        driver = MockedWebDriver()
        driver.set_expected_command(Command.FIND_ELEMENTS, {"using": By.ID, "sessionId": driver.session_id,
                                                            "value": 'a_locator'})

        ATestPage(driver).has_element_with_locator([By.ID, 'a_locator'])

        assert_that(driver.has_fulfilled_expectations(), equal_to(True), "page should check if it element is present")
示例#2
0
    def test_can_load(self):
        driver = MockedWebDriver()

        driver.set_expected_command(Command.GET, {
            'url': 'http://www.example.com',
            'sessionId': driver.session_id
        })
        ATestPage(driver).load()
        assert_that(driver.has_fulfilled_expectations(), equal_to(True))
示例#3
0
    def test_has_element_with_locator(self):
        driver = MockedWebDriver()
        driver.set_expected_command(Command.FIND_ELEMENTS, {
            "using": By.ID,
            "sessionId": driver.session_id,
            "value": 'a_locator'
        })

        ATestPage(driver).has_element_with_locator([By.ID, 'a_locator'])

        assert_that(driver.has_fulfilled_expectations(), equal_to(True),
                    "page should check if it element is present")
示例#4
0
    def test_is_loaded(self):
        driver = MockedWebDriver()

        element = ALoadableElement(driver).load()
        assert_that(
            element.is_loaded(), equal_to(True),
            'when traits are present element is_loaded() returns True')
示例#5
0
class ButtonTest(unittest.TestCase):
    """
    Unit test for Image class.
    """
    def __init__(self, methodName='runTest'):
        super(ButtonTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_button_executes_click(self):
        self.driver.set_dom_element([By.ID, 'image'],
                                    return_values=[{
                                        'name': {
                                            'src': 'attr'
                                        }
                                    }])

        self.driver.set_expected_command(
            Command.GET_ELEMENT_ATTRIBUTE, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'image'])
            })
        #
        image_src = Image(self.driver, 'image', [By.ID, 'image']).get_src()
        #
        assert_that(image_src, equal_to('attr'))
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True))
示例#6
0
class LabelTest(unittest.TestCase):
    """
    Unit test for Label class.
    """
    def __init__(self, methodName='runTest'):
        super(LabelTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_get_for_attribute(self):
        self.driver.set_dom_element([By.ID, 'label'],
                                    return_values=[{
                                        'name': {
                                            'for': 'attr'
                                        }
                                    }])
        self.driver.set_expected_command(
            Command.GET_ELEMENT_ATTRIBUTE, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'label'])
            })
        #
        image_src = Label(self.driver, 'label',
                          [By.ID, 'label']).get_for_attribute()
        #
        assert_that(image_src, equal_to('attr'),
                    'attribute for image should match')
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True))
示例#7
0
class LabelTest(unittest.TestCase):
    """
    Unit test for Label class.
    """
    def __init__(self, methodName='runTest'):
        super(LabelTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_get_for_attribute(self):
        self.driver.set_dom_element([By.ID, 'label'], return_values=[{'name': {'for': 'attr'}}])
        self.driver.set_expected_command(Command.GET_ELEMENT_ATTRIBUTE, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'label'])})
        #
        image_src = Label(self.driver, 'label', [By.ID, 'label']).get_for_attribute()
        #
        assert_that(image_src, equal_to('attr'), 'attribute for image should match')
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True))
示例#8
0
class ButtonTest(unittest.TestCase):
    """
    Unit test for Button class.
    """
    def __init__(self, methodName='runTest'):
        super(ButtonTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_button_executes_click(self):
        self.driver.set_dom_element([By.ID, 'buttonlocator'])

        self.driver.set_expected_command(Command.CLICK_ELEMENT, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'buttonlocator'])})
        #
        Button(self.driver, 'button', [By.ID, 'buttonlocator']).click()
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "clicking on button should result in executing Command.CLICK_ELEMENT")
示例#9
0
class ButtonTest(unittest.TestCase):
    """
    Unit test for Image class.
    """

    def __init__(self, methodName='runTest'):
        super(ButtonTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_button_executes_click(self):
        self.driver.set_dom_element([By.ID, 'image'], return_values=[{'name': {'src': 'attr'}}])

        self.driver.set_expected_command(Command.GET_ELEMENT_ATTRIBUTE, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'image'])})
        #
        image_src = Image(self.driver, 'image', [By.ID, 'image']).get_src()
        #
        assert_that(image_src, equal_to('attr'))
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True))
示例#10
0
class CheckboxTest(unittest.TestCase):
    """
    Unit test for Checkbox class.
    """

    def __init__(self, methodName='runTest'):
        super(CheckboxTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_checkbox_executes_select(self):
        self.driver.set_dom_element([By.ID, 'checkbox'])

        self.driver.set_expected_command(Command.CLICK_ELEMENT, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'checkbox'])})
        #
        Checkbox(self.driver, 'checkbox', [By.ID, 'checkbox']).select()
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "selecting a checkbox should result in executing Command.CLICK_ELEMENT")
示例#11
0
class CheckboxTest(unittest.TestCase):
    """
    Unit test for Checkbox class.
    """
    def __init__(self, methodName='runTest'):
        super(CheckboxTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_checkbox_executes_select(self):
        self.driver.set_dom_element([By.ID, 'checkbox'])

        self.driver.set_expected_command(
            Command.CLICK_ELEMENT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element(
                    [By.ID, 'checkbox'])
            })
        #
        Checkbox(self.driver, 'checkbox', [By.ID, 'checkbox']).select()
        #
        assert_that(
            self.driver.has_fulfilled_expectations(), equal_to(True),
            "selecting a checkbox should result in executing Command.CLICK_ELEMENT"
        )
示例#12
0
 def construct_from_foo():
     driver = MockedWebDriver()
     return UIComponent(driver, 'a component').from_web_element(Foo())
示例#13
0
class UiComponentTest(unittest.TestCase):
    """
    Unit test for UiComponent class.
    """
    def __init__(self, methodName='runTest'):
        super(UiComponentTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_component_can_be_created_from_web_element(self):
        component = UIComponent(self.driver, 'a component', [By.ID, 'theId'])
        a_web_element = WebElement(None, '')
        ##
        component.from_web_element(a_web_element)
        ##
        assert_that(
            component.locate(), equal_to(a_web_element),
            "fromWebElement should store a reference to passed WebElement")

    def test_raise_error_when_trying_to_construct_from_wrong_type(self):
        def construct_from_foo():
            driver = MockedWebDriver()
            return UIComponent(driver, 'a component').from_web_element(Foo())

        assert_that(construct_from_foo, raises(TypeError),
                    "passing unexpected type should causes exception")

    def test_web_element_is_stored_with_caching(self):
        component = UIComponent(self.driver, 'a component', [By.ID, 'theid'])
        self.driver.set_dom_element([By.ID, 'theid'])
        element_first_time = component.cache().locate()
        ##
        self.driver.reset_dom_elements()
        self.driver.set_dom_element([By.ID, 'theid'])
        element_second_time = component.locate()
        ##
        assert_that(
            element_first_time, equal_to(element_second_time),
            "when cached web_element() should return always the same WebElement object"
        )

    def test_web_element_is_evaluated_every_time_without_caching(self):
        component = UIComponent(self.driver, 'a component', [By.ID, 'theid'])
        self.driver.set_dom_element([By.ID, 'theid'])
        element_first_time = component.locate()
        ##
        self.driver.reset_dom_elements()
        self.driver.set_dom_element([By.ID, 'theid'])
        element_second_time = component.locate()
        ##
        assert_that(
            element_first_time, is_not(equal_to(element_second_time)),
            "when cached web_element() should return always the same WebElement object"
        )

    def test_component_is_found_when_has_all_traits(self):
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        ##
        component.add_trait(lambda: True, 'always true')
        ##
        assert_that(component.is_found(), equal_to(True),
                    "component should be found when all traits are present")

    def test_component_is_not_found_when_trait_raises_an_exception(self):
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        ##
        component.add_trait(raise_exception, 'always true')
        ##
        assert_that(
            component.is_found(), equal_to(False),
            "component should not be found when evaluating traits throws an exception"
        )

    def test_is_present(self):
        self.driver.set_dom_element([By.ID, 'an_id'])
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])

        component.is_present()

        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "component should be able to locate element it is scope")

    def test_component_can_be_clicked(self):
        self.driver.set_dom_element([By.ID, 'an_id'])

        self.driver.set_expected_command(
            Command.CLICK_ELEMENT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'an_id'])
            })

        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        ##
        component.click()
        ##
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "clicking on component should result in click command")

    def test_component_can_be_hovered(self):
        self.driver.set_dom_element([By.ID, 'an_id'])
        self.driver.set_expected_command(
            Command.MOVE_TO, {
                'sessionId': self.driver.session_id,
                'element': self.driver.get_id_for_stored_element(
                    [By.ID, 'an_id'])
            })
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        ##
        component.hover()
        ##
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "clicking on component should result in hoover command")

    def test_has_element(self):
        self.driver.set_dom_element([By.ID, 'an_id'])
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        self.driver.set_dom_element([By.XPATH, './/option'],
                                    parent_id=[By.ID, 'dropdownlocator'],
                                    children=1,
                                    return_values=[])

        self.driver.set_expected_command(
            Command.FIND_CHILD_ELEMENTS, {
                'using': By.ID,
                'value': self.driver.get_id_for_stored_element(
                    [By.ID, 'an_id']),
                'id': 'id',
                "sessionId": self.driver.session_id
            })
        ##
        component.has_element([By.ID, 'another_id'])
        ##
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "component should be able to locate element it is scope")

    def test_can_cache_element(self):
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        component.cache()
        cached_element = MockedWebElement(self.driver, 'another_id')
        ##
        component._cache_web_element(cached_element)
        ##
        assert_that(component.locate(), equal_to(cached_element))
示例#14
0
 def __init__(self, methodName='runTest'):
     super(UiComponentTest, self).__init__(methodName)
     self.driver = MockedWebDriver()
示例#15
0
class TableTest(unittest.TestCase):
    """
    Unit test for Table class.
    """

    def __init__(self, methodName='runTest'):
        super(TableTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def setUp(self):
        self.driver.reset_dom_elements()

    def test_get_items_with_language(self):
        self.driver.set_dom_element([By.ID, 'table'])
        self.driver.set_dom_element([By.XPATH, './/tr'], parent_id=[By.ID, 'table'], children=4,
                                    return_values=[{'text': 'first'}, {'text': 'second'}, {'text': 'third'},
                                                   {'text': 'fourth'}])
        self.driver.set_expected_command(Command.GET_ELEMENT_TEXT, {'sessionId': self.driver.session_id,
                                                                    'id': self.driver.get_id_for_stored_element(
                                                                        [By.XPATH, './/tr'], 1)})
        self.driver.set_expected_command(Command.GET_ELEMENT_TEXT, {'sessionId': self.driver.session_id,
                                                                    'id': self.driver.get_id_for_stored_element(
                                                                        [By.XPATH, './/tr'], 2)})
        self.driver.set_expected_command(Command.GET_ELEMENT_TEXT, {'sessionId': self.driver.session_id,
                                                                    'id': self.driver.get_id_for_stored_element(
                                                                        [By.XPATH, './/tr'], 3)})
        self.driver.set_expected_command(Command.GET_ELEMENT_TEXT, {'sessionId': self.driver.session_id,
                                                                    'id': self.driver.get_id_for_stored_element(
                                                                        [By.XPATH, './/tr'], 4)})

        #
        items = Table(self.driver, 'table', [By.XPATH, './/tr'], ItemWithLanguage, 'item', [By.ID, 'table']).get_items()
        labels = [i.get_text() for i in items]

        assert_that(labels, equal_to(['first', 'second', 'third', 'fourth']),
                    "It should retrieve labels from stored elements")
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "exercising get_items should result in calling Command.GET_ELEMENT_TEXT a number of times.")

    def test_detects_wrong_item_class(self):
        assert_that(calling(Table).with_args(self.driver, 'table', [By.ID, './/tr'], NonUiComponentItem, 'item',
                                             [By.ID, 'table']), raises(TypeError))

    def test_get_items_without_language(self):
        self.driver.set_dom_element([By.ID, 'table'])
        self.driver.set_dom_element([By.XPATH, './/tr'], parent_id=[By.ID, 'table'], children=4,
                                    return_values=[{'text': 'first'}, {'text': 'second'}, {'text': 'third'},
                                                   {'text': 'fourth'}])
        self.driver.set_expected_command(Command.GET_ELEMENT_TEXT, {'sessionId': self.driver.session_id,
                                                                    'id': self.driver.get_id_for_stored_element(
                                                                        [By.XPATH, './/tr'], 1)})
        self.driver.set_expected_command(Command.GET_ELEMENT_TEXT, {'sessionId': self.driver.session_id,
                                                                    'id': self.driver.get_id_for_stored_element(
                                                                        [By.XPATH, './/tr'], 2)})
        self.driver.set_expected_command(Command.GET_ELEMENT_TEXT, {'sessionId': self.driver.session_id,
                                                                    'id': self.driver.get_id_for_stored_element(
                                                                        [By.XPATH, './/tr'], 3)})
        self.driver.set_expected_command(Command.GET_ELEMENT_TEXT, {'sessionId': self.driver.session_id,
                                                                    'id': self.driver.get_id_for_stored_element(
                                                                        [By.XPATH, './/tr'], 4)})
        #
        items = Table(self.driver, 'table', [By.XPATH, './/tr'], Item, 'item', [By.ID, 'table']).get_items()
        #
        labels = [i.get_text() for i in items]

        assert_that(labels, equal_to(['first', 'second', 'third', 'fourth']),
                    "It should retrieve labels from stored elements")
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "exercising get_items should result in calling Command.GET_ELEMENT_TEXT a number of times.")
示例#16
0
 def __init__(self, methodName='runTest'):
     super(TableTest, self).__init__(methodName)
     self.driver = MockedWebDriver()
示例#17
0
class UiComponentTest(unittest.TestCase):
    """
    Unit test for UiComponent class.
    """

    def __init__(self, methodName='runTest'):
        super(UiComponentTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_component_can_be_created_from_web_element(self):
        component = UIComponent(self.driver, 'a component', [By.ID, 'theId'])
        a_web_element = WebElement(None, '')
        ##
        component.from_web_element(a_web_element)
        ##
        assert_that(component.locate(), equal_to(a_web_element),
                    "fromWebElement should store a reference to passed WebElement")

    def test_raise_error_when_trying_to_construct_from_wrong_type(self):
        def construct_from_foo():
            driver = MockedWebDriver()
            return UIComponent(driver, 'a component').from_web_element(Foo())
        assert_that(construct_from_foo, raises(TypeError), "passing unexpected type should causes exception")

    def test_web_element_is_stored_with_caching(self):
        component = UIComponent(self.driver, 'a component', [By.ID, 'theid'])
        self.driver.set_dom_element([By.ID, 'theid'])
        element_first_time = component.cache().locate()
        ##
        self.driver.reset_dom_elements()
        self.driver.set_dom_element([By.ID, 'theid'])
        element_second_time = component.locate()
        ##
        assert_that(element_first_time, equal_to(element_second_time),
                    "when cached web_element() should return always the same WebElement object")

    def test_web_element_is_evaluated_every_time_without_caching(self):
        component = UIComponent(self.driver, 'a component', [By.ID, 'theid'])
        self.driver.set_dom_element([By.ID, 'theid'])
        element_first_time = component.locate()
        ##
        self.driver.reset_dom_elements()
        self.driver.set_dom_element([By.ID, 'theid'])
        element_second_time = component.locate()
        ##
        assert_that(element_first_time, is_not(equal_to(element_second_time)),
                    "when cached web_element() should return always the same WebElement object")

    def test_component_is_found_when_has_all_traits(self):
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        ##
        component.add_trait(lambda: True, 'always true')
        ##
        assert_that(component.is_found(), equal_to(True), "component should be found when all traits are present")

    def test_component_is_not_found_when_trait_raises_an_exception(self):
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        ##
        component.add_trait(raise_exception, 'always true')
        ##
        assert_that(component.is_found(), equal_to(False),
                    "component should not be found when evaluating traits throws an exception")

    def test_is_present(self):
        self.driver.set_dom_element([By.ID, 'an_id'])
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])

        component.is_present()

        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "component should be able to locate element it is scope")

    def test_component_can_be_clicked(self):
        self.driver.set_dom_element([By.ID, 'an_id'])

        self.driver.set_expected_command(Command.CLICK_ELEMENT, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'an_id'])})

        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        ##
        component.click()
        ##
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "clicking on component should result in click command")

    def test_component_can_be_hovered(self):
        self.driver.set_dom_element([By.ID, 'an_id'])
        self.driver.set_expected_command(Command.MOVE_TO, {'sessionId': self.driver.session_id,
                                                           'element': self.driver.get_id_for_stored_element(
                                                               [By.ID, 'an_id'])})
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        ##
        component.hover()
        ##
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "clicking on component should result in hoover command")

    def test_has_element(self):
        self.driver.set_dom_element([By.ID, 'an_id'])
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        self.driver.set_dom_element([By.XPATH, './/option'], parent_id=[By.ID, 'dropdownlocator'], children=1,
                                    return_values=[])

        self.driver.set_expected_command(Command.FIND_CHILD_ELEMENTS, {'using': By.ID, 'value': self.driver.
                                         get_id_for_stored_element([By.ID, 'an_id']),
                                         'id': 'id', "sessionId": self.driver.session_id})
        ##
        component.has_element([By.ID, 'another_id'])
        ##
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "component should be able to locate element it is scope")

    def test_can_cache_element(self):
        component = UIComponent(self.driver, 'a_component', [By.ID, 'an_id'])
        component.cache()
        cached_element = MockedWebElement(self.driver, 'another_id')
        ##
        component._cache_web_element(cached_element)
        ##
        assert_that(component.locate(), equal_to(cached_element))
示例#18
0
class DropdownTest(unittest.TestCase):
    """
    Unit test for Dropdown class.
    """
    def __init__(self, methodName='runTest'):
        super(DropdownTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def setUp(self):
        self.driver.reset_dom_elements()

    def test_dropdown_executes_select_option_by_name(self):
        self.driver.set_dom_elements([[By.ID, 'dropdownlocator'],
                                      [By.XPATH,
                                       "./option[text()='thename']"]])
        self.driver.set_expected_command(
            Command.CLICK_ELEMENT, {
                'sessionId':
                self.driver.session_id,
                'id':
                self.driver.get_id_for_stored_element(
                    [By.ID, 'dropdownlocator'])
            })
        self.driver.set_expected_command(
            Command.CLICK_ELEMENT, {
                'sessionId':
                self.driver.session_id,
                'id':
                self.driver.get_id_for_stored_element(
                    [By.XPATH, "./option[text()='thename']"])
            })
        #
        Dropdown(self.driver, 'dropdown',
                 [By.ID, 'dropdownlocator']).select_option_by_name('thename')
        assert_that(
            self.driver.has_fulfilled_expectations(), equal_to(True),
            "fetching option labels should result in executing Comman.CLICK and Command.FIND_CHILD_ELEMENTS"
        )

    def test_dropdown_executes_select_option_by_value(self):
        self.driver.set_dom_elements(
            [[By.ID, 'dropdownlocator'],
             [By.XPATH, "./option[@value='anoption']"]])

        self.driver.set_expected_command(
            Command.CLICK_ELEMENT, {
                'sessionId':
                self.driver.session_id,
                'id':
                self.driver.get_id_for_stored_element(
                    [By.ID, 'dropdownlocator'])
            })

        self.driver.set_expected_command(
            Command.CLICK_ELEMENT, {
                'sessionId':
                self.driver.session_id,
                'id':
                self.driver.get_id_for_stored_element(
                    [By.XPATH, "./option[@value='anoption']"])
            })
        #
        Dropdown(self.driver, 'dropdown',
                 [By.ID, 'dropdownlocator']).select_option_by_value('anoption')
        #
        assert_that(
            self.driver.has_fulfilled_expectations(), equal_to(True),
            "fetching option labels should result in executing Comman.CLICK and Command.FIND_CHILD_ELEMENTS"
        )

    def test_dropdown_executes_get_options_label(self):
        self.driver.set_dom_element([By.ID, 'dropdownlocator'])
        self.driver.set_dom_element([By.XPATH, './/option'],
                                    parent_id=[By.ID, 'dropdownlocator'],
                                    children=4,
                                    return_values=[{
                                        'text': 'first'
                                    }, {
                                        'text': 'second'
                                    }, {
                                        'text': 'third'
                                    }, {
                                        'text': 'fourth'
                                    }])
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId':
                self.driver.session_id,
                'id':
                self.driver.get_id_for_stored_element([By.XPATH, './/option'],
                                                      1)
            })
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId':
                self.driver.session_id,
                'id':
                self.driver.get_id_for_stored_element([By.XPATH, './/option'],
                                                      2)
            })
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId':
                self.driver.session_id,
                'id':
                self.driver.get_id_for_stored_element([By.XPATH, './/option'],
                                                      3)
            })
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId':
                self.driver.session_id,
                'id':
                self.driver.get_id_for_stored_element([By.XPATH, './/option'],
                                                      4)
            })
        #
        labels = Dropdown(self.driver, 'dropdown',
                          [By.ID, 'dropdownlocator']).get_option_labels()
        #
        assert_that(labels, equal_to(['first', 'second', 'third', 'fourth']),
                    "It should retrieve labels from stored elements")
示例#19
0
class TableTest(unittest.TestCase):
    """
    Unit test for Table class.
    """
    def __init__(self, methodName='runTest'):
        super(TableTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def setUp(self):
        self.driver.reset_dom_elements()

    def test_get_items_with_language(self):
        self.driver.set_dom_element([By.ID, 'table'])
        self.driver.set_dom_element([By.XPATH, './/tr'],
                                    parent_id=[By.ID, 'table'],
                                    children=4,
                                    return_values=[{
                                        'text': 'first'
                                    }, {
                                        'text': 'second'
                                    }, {
                                        'text': 'third'
                                    }, {
                                        'text': 'fourth'
                                    }])
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element(
                    [By.XPATH, './/tr'], 1)
            })
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element(
                    [By.XPATH, './/tr'], 2)
            })
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element(
                    [By.XPATH, './/tr'], 3)
            })
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element(
                    [By.XPATH, './/tr'], 4)
            })

        #
        items = Table(self.driver, 'table', [By.XPATH, './/tr'],
                      ItemWithLanguage, 'item', [By.ID, 'table']).get_items()
        labels = [i.get_text() for i in items]

        assert_that(labels, equal_to(['first', 'second', 'third', 'fourth']),
                    "It should retrieve labels from stored elements")
        assert_that(
            self.driver.has_fulfilled_expectations(), equal_to(True),
            "exercising get_items should result in calling Command.GET_ELEMENT_TEXT a number of times."
        )

    def test_detects_wrong_item_class(self):
        assert_that(
            calling(Table).with_args(self.driver, 'table', [By.ID, './/tr'],
                                     NonUiComponentItem, 'item',
                                     [By.ID, 'table']), raises(TypeError))

    def test_get_items_without_language(self):
        self.driver.set_dom_element([By.ID, 'table'])
        self.driver.set_dom_element([By.XPATH, './/tr'],
                                    parent_id=[By.ID, 'table'],
                                    children=4,
                                    return_values=[{
                                        'text': 'first'
                                    }, {
                                        'text': 'second'
                                    }, {
                                        'text': 'third'
                                    }, {
                                        'text': 'fourth'
                                    }])
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element(
                    [By.XPATH, './/tr'], 1)
            })
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element(
                    [By.XPATH, './/tr'], 2)
            })
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element(
                    [By.XPATH, './/tr'], 3)
            })
        self.driver.set_expected_command(
            Command.GET_ELEMENT_TEXT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element(
                    [By.XPATH, './/tr'], 4)
            })
        #
        items = Table(self.driver, 'table', [By.XPATH, './/tr'], Item, 'item',
                      [By.ID, 'table']).get_items()
        #
        labels = [i.get_text() for i in items]

        assert_that(labels, equal_to(['first', 'second', 'third', 'fourth']),
                    "It should retrieve labels from stored elements")
        assert_that(
            self.driver.has_fulfilled_expectations(), equal_to(True),
            "exercising get_items should result in calling Command.GET_ELEMENT_TEXT a number of times."
        )
示例#20
0
 def __init__(self, methodName='runTest'):
     super(UiComponentTest, self).__init__(methodName)
     self.driver = MockedWebDriver()
示例#21
0
    def test_can_load(self):
        driver = MockedWebDriver()

        driver.set_expected_command(Command.GET, {'url': 'http://www.example.com', 'sessionId': driver.session_id})
        ATestPage(driver).load()
        assert_that(driver.has_fulfilled_expectations(), equal_to(True))
示例#22
0
 def __init__(self, methodName='runTest'):
     super(RadioButtonTest, self).__init__(methodName)
     self.driver = MockedWebDriver()
示例#23
0
class TextIputTest(unittest.TestCase):
    """
    Unit test for TextInput class.
    """

    def __init__(self, methodName='runTest'):
        super(TextIputTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_clear(self):
        self.driver.set_dom_element([By.ID, 'input'])
        self.driver.set_expected_command(Command.CLEAR_ELEMENT, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'input'])})
        #
        TextInput(self.driver, 'input', [By.ID, 'input']).clear()
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "clearing text input should fulfill test expectations")

    def test_focus(self):
        self.driver.set_dom_element([By.ID, 'input'])
        self.driver.set_expected_command(Command.CLICK_ELEMENT, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'input'])})
        self.driver.set_expected_command(Command.CLICK_ELEMENT, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'input'])})
        self.driver.set_expected_command(Command.GET_ACTIVE_ELEMENT, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'input'])})
        #
        TextInput(self.driver, 'input', [By.ID, 'input']).focus()
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "focusing on element should fulfill expectations")

    def test_input_text(self):
        self.driver.set_dom_element([By.ID, 'input'])
        self.driver.set_expected_command(Command.SEND_KEYS_TO_ELEMENT, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'input']),
                                                                        'value': Keys.CLEAR})
        self.driver.set_expected_command(Command.SEND_KEYS_TO_ELEMENT, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'input']),
                                                                        'value': 'text'})
        #
        TextInput(self.driver, 'input', [By.ID, 'input']).input_text('text')
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "inputting text should fulfill expectations")

    def test_get_placeholder_text(self):
        self.driver.set_dom_element([By.ID, 'input'], return_values=[{'name': {'placeholder': 'placeholder text'}}])
        self.driver.set_expected_command(Command.GET_ELEMENT_ATTRIBUTE, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'input'])})
        #
        text = TextInput(self.driver, 'input', [By.ID, 'input']).get_placeholder_text()
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "getting placeholder value should fulfill expectations")
        assert_that(text, equal_to('placeholder text'))

    def test_get_current_value(self):
        self.driver.set_dom_element([By.ID, 'input'], return_values=[{'name': {'value': 'current value'}}])
        self.driver.set_expected_command(Command.GET_ELEMENT_ATTRIBUTE, {'sessionId': self.driver.session_id,
                                         'id': self.driver.get_id_for_stored_element([By.ID, 'input'])})
        #
        text = TextInput(self.driver, 'input', [By.ID, 'input']).get_current_value()
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "getting current value should fulfill expectations")
        assert_that(text, equal_to('current value'))

    def test_input_text_with_keyboard_emulation(self):
        self.driver.set_dom_element([By.ID, 'input'])
        self.driver.set_expected_command(Command.SEND_KEYS_TO_ACTIVE_ELEMENT,
                                         {'sessionId': self.driver.session_id,
                                          'id': self.driver.get_id_for_stored_element([By.ID, 'input']),
                                          'value': 'text to send'})
        self.driver.set_expected_command(Command.SEND_KEYS_TO_ACTIVE_ELEMENT,
                                         {'sessionId': self.driver.session_id,
                                          'id': self.driver.get_id_for_stored_element([By.ID, 'input']),
                                          'value': Keys.CONTROL})
        #
        TextInput(self.driver, 'input', [By.ID, 'input']).input_text_with_keyboard_emulation('text to send')
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "getting current value should fulfill expectations")
示例#24
0
class TextIputTest(unittest.TestCase):
    """
    Unit test for TextInput class.
    """
    def __init__(self, methodName='runTest'):
        super(TextIputTest, self).__init__(methodName)
        self.driver = MockedWebDriver()

    def test_clear(self):
        self.driver.set_dom_element([By.ID, 'input'])
        self.driver.set_expected_command(
            Command.CLEAR_ELEMENT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'input'])
            })
        #
        TextInput(self.driver, 'input', [By.ID, 'input']).clear()
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "clearing text input should fulfill test expectations")

    def test_focus(self):
        self.driver.set_dom_element([By.ID, 'input'])
        self.driver.set_expected_command(
            Command.CLICK_ELEMENT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'input'])
            })
        self.driver.set_expected_command(
            Command.CLICK_ELEMENT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'input'])
            })
        self.driver.set_expected_command(
            Command.GET_ACTIVE_ELEMENT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'input'])
            })
        #
        TextInput(self.driver, 'input', [By.ID, 'input']).focus()
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "focusing on element should fulfill expectations")

    def test_input_text(self):
        self.driver.set_dom_element([By.ID, 'input'])
        self.driver.set_expected_command(
            Command.SEND_KEYS_TO_ELEMENT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'input']),
                'value': Keys.CLEAR
            })
        self.driver.set_expected_command(
            Command.SEND_KEYS_TO_ELEMENT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'input']),
                'value': 'text'
            })
        #
        TextInput(self.driver, 'input', [By.ID, 'input']).input_text('text')
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "inputting text should fulfill expectations")

    def test_get_placeholder_text(self):
        self.driver.set_dom_element([By.ID, 'input'],
                                    return_values=[{
                                        'name': {
                                            'placeholder': 'placeholder text'
                                        }
                                    }])
        self.driver.set_expected_command(
            Command.GET_ELEMENT_ATTRIBUTE, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'input'])
            })
        #
        text = TextInput(self.driver, 'input',
                         [By.ID, 'input']).get_placeholder_text()
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "getting placeholder value should fulfill expectations")
        assert_that(text, equal_to('placeholder text'))

    def test_get_current_value(self):
        self.driver.set_dom_element([By.ID, 'input'],
                                    return_values=[{
                                        'name': {
                                            'value': 'current value'
                                        }
                                    }])
        self.driver.set_expected_command(
            Command.GET_ELEMENT_ATTRIBUTE, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'input'])
            })
        #
        text = TextInput(self.driver, 'input',
                         [By.ID, 'input']).get_current_value()
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "getting current value should fulfill expectations")
        assert_that(text, equal_to('current value'))

    def test_input_text_with_keyboard_emulation(self):
        self.driver.set_dom_element([By.ID, 'input'])
        self.driver.set_expected_command(
            Command.SEND_KEYS_TO_ACTIVE_ELEMENT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'input']),
                'value': 'text to send'
            })
        self.driver.set_expected_command(
            Command.SEND_KEYS_TO_ACTIVE_ELEMENT, {
                'sessionId': self.driver.session_id,
                'id': self.driver.get_id_for_stored_element([By.ID, 'input']),
                'value': Keys.CONTROL
            })
        #
        TextInput(self.driver, 'input',
                  [By.ID, 'input'
                   ]).input_text_with_keyboard_emulation('text to send')
        #
        assert_that(self.driver.has_fulfilled_expectations(), equal_to(True),
                    "getting current value should fulfill expectations")
示例#25
0
 def test_set_driver(self):
     driver = MockedWebDriver()
     wait = Wait(10).with_driver(driver)
     assert_that(wait._driver.session_id, equal_to(driver.session_id))
示例#26
0
 def __init__(self, methodName='runTest'):
     super(TextIputTest, self).__init__(methodName)
     self.driver = MockedWebDriver()
示例#27
0
 def __init__(self, methodName='runTest'):
     super(CheckboxTest, self).__init__(methodName)
     self.driver = MockedWebDriver()