Exemplo n.º 1
0
def test_proxies_access_to_dom_element(browser):
    class DomElementMock(object):
        @property
        def some_property(self):
            return 'some value'

        def some_method(self, x):
            return x

    dom_element_mock = DomElementMock()
    browser.find_elements_by_xpath = Mock(return_value=[dom_element_mock])

    el = WebElement(browser, "some_tag[@some_attr='some_value']")
    assert el.some_property == 'some value'
    assert el.some_method('some other value') == 'some other value'
Exemplo n.º 2
0
def test_refreshes_dom_element_on_method_call_when_stale(browser):
    class DomElementMock(object):
        def some_method(self, x):
            return x

    dom_element_mock = DomElementMock()
    stale_element_mock = Mock(spec=DomElementMock)
    stale_element_mock.some_method = Mock(
        side_effect=StaleElementReferenceException)
    browser.find_elements_by_xpath.side_effect = ([stale_element_mock],
                                                  [dom_element_mock])

    el = WebElement(browser, "some_tag[@some_attr='some_value']")
    assert el.dom_element is stale_element_mock
    assert el.some_method('some value') == 'some value'
    assert el.dom_element is dom_element_mock