Beispiel #1
0
 def test_func_returns_true_after_html_change(self):
     old_htmls = [object()]
     new_htmls = [object()]
     sut = Browser()
     self.stub_webdriver.html_elements = old_htmls
     change_detected = sut.func_that_detects_new_page()
     self.stub_webdriver.html_elements = new_htmls
     assert change_detected(), "Failed to detect a change"
 def test_returns_a_browser_with_the_remote_driver(self):
     get_spy = FunctionSpy(return_value=EndlessFake())
     remote_stub = EndlessFake()
     remote_stub.get = get_spy
     self.webdriver_stub.Remote = lambda *args, **kwargs: remote_stub
     self.context.set_env(BROWSER_LOCATION="selenium_grid", SELENIUM_GRID_HUB_URL="http://fang")
     Browser().get("http://stuffed")
Beispiel #3
0
 def test_does_not_quit_when_debugging_and_test_failed(self):
     self.set_debug_flag()
     sut = Browser()
     sut
     EventBroker.publish(event=TestEvent.test_failed)
     EventBroker.publish(event=TestEvent.suite_ended)
     assert not self.quit_was_called(), "quit() was called"
Beispiel #4
0
 def test_sets_full_screen(self):
     remote_spy = MasterSpy(EndlessFake())
     self.webdriver_spy.Remote = lambda *a, **k: remote_spy
     Browser()
     expect(remote_spy.attribute_spies.keys()).to(
         contain("fullscreen_window"))
     calls = remote_spy.attribute_spies["fullscreen_window"].call_history
     assert calls, "fullscreen_window was not called"
 def test_sets_browser_version_if_specified(self):
     version = "8.67.5309"
     self.context.set_env(
         BROWSER_LOCATION="selenium_grid", SELENIUM_GRID_HUB_URL="fish", USE_BROWSER_VERSION=version
     )
     Browser()
     requested_capabilities = self.remote_spy["desired_capabilities"]
     expect(requested_capabilities["version"]).to(equal(version))
 def test_sets_specified_browser_name(self):
     browser_name = "Yogurt"
     self.context.set_env(
         BROWSER_LOCATION="selenium_grid", SELENIUM_GRID_HUB_URL="something", USE_BROWSER=browser_name
     )
     Browser()
     requested_capabilities = self.remote_spy["desired_capabilities"]
     expect(requested_capabilities["browserName"]).to(equal(browser_name))
 def setUp(self):
     self.context = open_dependency_context(supply_env=True)
     fake_webdriver = FakeWebdriver()
     self.context.inject(webdriver, fake_webdriver)
     self.events_captured = []
     EventBroker.subscribe(event=TestEvent.artifact_created,
                           func=self.capture_event)
     self.sut = Browser()
Beispiel #8
0
 def test_closes_tunnel_on_suite_end(self):
     self.context.set_env(browser_locaton="BrowserStack",
                          BROWSERSTACK_SET_LOCAL="true")
     spy = MasterSpy(TunnelToNowhere())
     self.context.inject_as_class(BrowserStackTunnel, spy)
     sut = Browser()  # noqa: F841
     assert not spy.was_closed, "close was called prematurely."
     EventBroker.publish(event=TestEvent.suite_ended)
     assert spy.was_closed, "close was not called."
Beispiel #9
0
 def setUp(self):
     EventBroker.reset()
     EventBroker.subscribe(event=TestEvent.artifact_created,
                           func=self.catch_artifact_event)
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.fake_webdriver = FakeWebdriver()
     self.context.inject(webdriver, self.fake_webdriver)
     self.sut = Browser()
     self.artifact_events = []
 def setUp(self):
     self.context = open_dependency_context(supply_env=True)
     EventBroker.reset()
     EventBroker.subscribe(event=TestEvent.artifact_created, func=self.catch_artifact_event)
     self.artifact_events_caught = []
     self.fake_webdriver = FakeWebdriver()
     self.context.inject(webdriver, self.fake_webdriver)
     self.fake_dump = "yaddayaddayadda"
     self.context.inject(dump_dom, lambda x: self.fake_dump)
     self.sut = Browser()
Beispiel #11
0
 def test_uses_configured_browserstack_url(self):
     expected = "https://a.b.c/1"
     self.context.set_env(BROWSERSTACK_URL=expected)
     Browser()
     parsed = self.parse_command_executor()
     scheme, netloc, path, query, fragment = tuple(parsed)
     without_credentials = netloc.split("@")[-1]
     actual = urlunsplit(
         (scheme, without_credentials, path, query, fragment))
     expect(actual).to(equal(expected))
Beispiel #12
0
 def test_specifies_fullscreen_option(self):
     Browser()
     spy = self.fake_webdriver.driver_spy
     expect(spy).not_to(equal(None))
     expect(spy.call_history).to(have_length(1))
     _, kwargs = spy.call_history[0]
     expect(kwargs.keys()).to(contain("chrome_options"))
     opts = kwargs["chrome_options"]
     expect(opts).to(be_a(webdriver.chrome.options.Options))
     expect(opts.arguments).to(contain("start-fullscreen"))
 def test_returns_list_from_find_elements(self):
     thing1 = object()
     thing2 = object()
     expected = [thing1, thing2]
     self.fake_webdriver.matching_elements = expected
     expect(Browser().find_all_matching_elements(id="spam")).to(equal(expected))
 def test_does_not_set_browser_version_if_not_specified(self):
     self.context.set_env(BROWSER_LOCATION="selenium_grid", SELENIUM_GRID_HUB_URL="http://biggles")
     Browser()
     caps = self.remote_spy["desired_capabilities"]
     expect(caps.keys()).not_to(contain("version"))
Beispiel #15
0
 def test_uses_configured_browserstack_debug(self):
     expected = True
     Browser()
     self.context.set_env(BROWSERSTACK_SET_DEBUG=expected)
     expect(self.retrieve_desired_capabilities()).to(
         contain_key_with_value("browserstack.debug", expected))
Beispiel #16
0
 def test_uses_configured_browserstack_local(self):
     expected = False
     self.context.set_env(BROWSERSTACK_SET_LOCAL=expected)
     Browser()
     expect(self.retrieve_desired_capabilities()).to(
         contain_key_with_value("browserstack.local", expected))
Beispiel #17
0
 def test_does_not_specify_browser_version_if_not_configured(self):
     self.context.unset_env("USE_BROWSER_VERSION")
     Browser()
     expect(self.retrieve_desired_capabilities().keys()).not_to(
         contain("browser_version"))
Beispiel #18
0
 def test_uses_configured_browser_version(self):
     expected = "nineteen"
     self.context.set_env(USE_BROWSER_VERSION=expected)
     Browser()
     expect(self.retrieve_desired_capabilities()).to(
         contain_key_with_value("browser_version", expected))
Beispiel #19
0
 def test_uses_configured_browser_type(self):
     expected = "smoking"
     self.context.set_env(USE_BROWSER=expected)
     Browser()
     expect(self.retrieve_desired_capabilities()).to(
         contain_key_with_value("browser", expected))
 def test_transforms_qa_id_selector(self):
     Browser().find_all_matching_elements(qa_id="sausage")
     expect(self.fake_webdriver.last_find_args).to(equal((By.XPATH, "//*[@data-qa='sausage']")))
Beispiel #21
0
 def test_uses_configured_screen_resolution(self):
     expected = "8x10"
     self.context.set_env(BROWSERSTACK_SCREEN_RESOLUTION=expected)
     Browser()
     expect(self.retrieve_desired_capabilities()).to(
         contain_key_with_value("resolution", expected))
Beispiel #22
0
 def test_uses_configured_os(self):
     expected = "OS/irus"
     self.context.set_env(BROWSERSTACK_OS=expected)
     Browser()
     expect(self.retrieve_desired_capabilities()).to(
         contain_key_with_value("os", expected))
Beispiel #23
0
 def test_uses_urlencoded_configured_username(self):
     expected = "*****@*****.**"
     self.context.set_env(BROWSERSTACK_USERNAME=expected)
     Browser()
     parsed = self.parse_command_executor()
     expect(parsed.username).to(equal(quote_plus(expected)))
 def test_passes_other_selector_through_to_find_elements(self):
     tag_name = "center"
     Browser().find_all_matching_elements(tag_name=tag_name)
     expect(self.fake_webdriver.last_find_args).to(equal((By.TAG_NAME, tag_name)))
Beispiel #25
0
 def test_uses_urlencoded_configured_access_key(self):
     expected = "PleaseOhPlease"
     self.context.set_env(BROWSERSTACK_ACCESS_KEY=expected)
     Browser()
     parsed = self.parse_command_executor()
     expect(parsed.password).to(equal(expected))
 def test_raises_no_such_element_when_list_empty(self):
     self.fake_webdriver.matching_elements = []
     expect(partial(Browser().find_all_matching_elements, id="spam")).to(raise_ex(NoSuchElementException))
Beispiel #27
0
 def test_uses_configured_os_version(self):
     expected = "14.7.1"
     self.context.set_env(BROWSERSTACK_OS_VERSION=expected)
     Browser()
     expect(self.retrieve_desired_capabilities()).to(
         contain_key_with_value("os_version", expected))
Beispiel #28
0
class TestFindUniqueElement(TestCase):
    def setUp(self):
        self.context = open_dependency_context(supply_env=True)
        self.fake = FakeWebDriver()
        self.context.inject(webdriver, self.fake)
        self.sut = Browser()

    def tearDown(self):
        self.context.close()

    def test_returns_element_if_only_one_present(self):
        element = object()
        self.fake.elements = [element]
        expect(self.sut.find_unique_element(id="whatever")).to(equal(element))

    def test_raises_no_such_element_if_none_present(self):
        def attempt():
            self.sut.find_unique_element(id="whatever", timeout=0)

        expect(attempt).to(raise_error(NoSuchElementException))

    def test_waits_up_to_timeout_for_element_to_appear(self):
        timeout = 42

        def find():
            return self.sut.find_unique_element(id="whatever", timeout=timeout)

        clock = TimeController(target=find)
        clock.start()
        clock.advance(seconds=timeout - 0.001)
        element = object()
        self.fake.elements = [element]
        clock.join()
        expect(clock.exception_caught).to(equal(None))
        expect(clock.value_returned).to(equal(element))

    def test_raises_too_many_elements_if_two_present(self):
        self.fake.elements = [object(), object()]

        def attempt():
            self.sut.find_unique_element(id="whatever")

        expect(attempt).to(raise_error(TooManyElements))

    def test_can_identify_by_class_name(self):
        self.fake.elements = [object()]
        selector = "whatever"
        self.sut.find_unique_element(class_name=selector)
        expect(self.fake.last_find).to(equal((By.CLASS_NAME, selector)))

    def test_can_identify_by_css_selector(self):
        self.fake.elements = [object()]
        selector = "whatever"
        self.sut.find_unique_element(css_selector=selector)
        expect(self.fake.last_find).to(equal((By.CSS_SELECTOR, selector)))

    def test_can_identify_by_id(self):
        self.fake.elements = [object()]
        selector = "whatever"
        self.sut.find_unique_element(id=selector)
        expect(self.fake.last_find).to(equal((By.ID, selector)))

    def test_can_identify_by_qa_id(self):
        self.fake.elements = [object()]
        selector = "fake-qa-id"
        self.sut.find_unique_element(qa_id=selector)
        expect(self.fake.last_find).to(
            equal((By.XPATH, "//*[@data-qa='%s']" % selector)))

    def test_can_identify_by_link_text(self):
        self.fake.elements = [object()]
        selector = "whatever"
        self.sut.find_unique_element(link_text=selector)
        expect(self.fake.last_find).to(equal((By.LINK_TEXT, selector)))

    def test_can_identify_by_tag_name(self):
        self.fake.elements = [object()]
        selector = "whatever"
        self.sut.find_unique_element(tag_name=selector)
        expect(self.fake.last_find).to(equal((By.TAG_NAME, selector)))

    def test_can_identify_by_name(self):
        self.fake.elements = [object()]
        selector = "whatever"
        self.sut.find_unique_element(name=selector)
        expect(self.fake.last_find).to(equal((By.NAME, selector)))

    def test_can_identify_by_partial_link_text(self):
        self.fake.elements = [object()]
        selector = "whatever"
        self.sut.find_unique_element(partial_link_text=selector)
        expect(self.fake.last_find).to(equal((By.PARTIAL_LINK_TEXT, selector)))

    def test_can_identify_by_xpath(self):
        self.fake.elements = [object()]
        selector = "whatever"
        self.sut.find_unique_element(xpath=selector)
        expect(self.fake.last_find).to(equal((By.XPATH, selector)))

    def test_raises_unknown_selector(self):
        def attempt():
            self.sut.find_unique_element(robins=2)

        expect(attempt).to(raise_error(UnknownSelector))
Beispiel #29
0
 def test_sends_local_id_from_tunnel_to_webdriver(self):
     local_id = "McGill"
     self.fake_tunnel.local_identifier = local_id
     Browser()
     expect(self.extract_capabilities()).to(
         contain_key_with_value("browserstack.localIdentifier", local_id))
Beispiel #30
0
 def setUp(self):
     self.context = open_dependency_context(supply_env=True)
     self.fake = FakeWebDriver()
     self.context.inject(webdriver, self.fake)
     self.sut = Browser()