diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0d904dce6..1689ccc25 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: CI -# Controls when the action will run. +# Controls when the action will run. on: # Triggers the workflow on push or pull request events but only for the master branch push: @@ -59,11 +59,11 @@ jobs: run: tox -e lint - name: Run Selenium Remote tests - run: | + run: | echo "Start Selenium Server" xvfb-run java -jar selenium-server.jar > /dev/null 2>&1 & sleep 3 & tox -e tests -- tests/test_webdriver_remote.py; # Runs a set of commands using the runners shell - name: Run tests run: | - tox -e tests -- -n 4 tests/test_browser.py tests/test_djangoclient.py tests/test_element_list.py tests/test_flaskclient.py tests/test_request_handler.py tests/test_xpath_concat.py tests/test_zopetestbrowser.py tests/test_webdriver.py tests/test_webdriver_firefox.py tests/test_webdriver_chrome.py; + tox -e tests -- -n 4 tests/test_browser.py tests/test_djangoclient.py tests/test_element_list.py tests/test_flaskclient.py tests/test_request_handler.py tests/test_xpath_concat.py tests/test_zopetestbrowser.py tests/test_webdriver.py tests/test_popups.py tests/test_webdriver_firefox.py tests/test_webdriver_chrome.py; diff --git a/tests/base.py b/tests/base.py index f882cb0bd..313cd63d8 100644 --- a/tests/base.py +++ b/tests/base.py @@ -28,11 +28,12 @@ from .screenshot import ScreenshotTest from .html_snapshot import HTMLSnapshotTest from .type import SlowlyTypeTest -from .popups import PopupWindowsTest def get_browser(browser_name, **kwargs): - if browser_name == 'chrome': + if browser_name in ['chrome', 'chrome_fullscreen']: + if browser_name == 'chrome_fullscreen': + kwargs['fullscreen'] = True options = webdriver.chrome.options.Options() options.add_argument("--disable-dev-shm-usage") return Browser( @@ -41,7 +42,11 @@ def get_browser(browser_name, **kwargs): options=options, **kwargs ) - elif browser_name == 'firefox': + + elif browser_name in ['firefox', 'firefox_fullscreen']: + if browser_name == 'firefox_fullscreen': + kwargs['fullscreen'] = True + return Browser( "firefox", headless=True, @@ -163,7 +168,6 @@ class WebDriverTests( IsElementVisibleTest, AsyncFinderTests, MouseInteractionTest, - PopupWindowsTest, ScreenshotTest, HTMLSnapshotTest, ): diff --git a/tests/popups.py b/tests/popups.py deleted file mode 100644 index ee68c1bda..000000000 --- a/tests/popups.py +++ /dev/null @@ -1,90 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2015 splinter authors. All rights reserved. -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file. - - -class PopupWindowsTest(object): - def test_lists_all_windows_as_window_instances(self): - browser = self.get_new_browser() - browser.visit(self.EXAMPLE_APP) - browser.find_by_id("open-popup").click() - - assert 2 == len(browser.windows) - - for window, handle in zip( - browser.windows, browser.driver.window_handles - ): - assert window.name == handle - - browser.quit() - - def test_current_is_a_window_instance_pointing_to_current_window(self): - assert self.browser.windows.current.name == self.browser.driver.current_window_handle - - def test_set_current_to_window_instance_sets_current_window(self): - self.browser.find_by_id("open-popup").click() - - last_current_window = self.browser.windows.current - self.browser.windows.current = self.browser.windows.current.next - assert self.browser.windows.current != last_current_window - - def test_next_prev_return_next_prev_windows(self): - browser = self.get_new_browser() - browser.visit(self.EXAMPLE_APP) - browser.find_by_id("open-popup").click() - - assert browser.windows.current.next == browser.windows.current.prev - assert browser.windows.current != browser.windows.current.next - - browser.quit() - - def test_is_current_returns_true_if_current_window_else_false(self): - self.browser.find_by_id("open-popup").click() - - assert self.browser.windows.current.is_current - assert not self.browser.windows.current.next.is_current - - # Close popup window - self.browser.windows.current.close_others() - - def test_set_is_current_to_true_sets_window_to_current(self): - self.browser.find_by_id("open-popup").click() - next_window = self.browser.windows.current.next - assert not next_window.is_current - next_window.is_current = True - assert self.browser.windows.current == next_window - assert next_window.is_current - - def test_get_window_by_index(self): - self.browser.find_by_id("open-popup").click() - assert self.browser.windows[0].name == self.browser.driver.window_handles[0] - - def test_get_window_by_name(self): - self.browser.find_by_id("open-popup").click() - window_handle = self.browser.driver.window_handles[0] - assert self.browser.windows[window_handle].name == window_handle - - def test_close_closes_window(self): - self.browser.find_by_id("open-popup").click() - current = self.browser.windows.current - current.next.close() - assert 1 == len(self.browser.windows) - assert self.browser.windows.current == current - - def test_close_current_window_expect_previous_window_becomes_current(self): - self.browser.find_by_id("open-popup").click() - prev = self.browser.windows.current - current = prev.next - prev.next.is_current = True - current.close() - assert 1 == len(self.browser.windows) - assert self.browser.windows.current == prev - - def test_close_others_expect_close_all_other_open_windows(self): - current = self.browser.windows.current - self.browser.find_by_id("open-popup").click() - current.close_others() - assert self.browser.windows[0] == current - assert 1 == len(self.browser.windows) diff --git a/tests/test_popups.py b/tests/test_popups.py new file mode 100644 index 000000000..1f91d57ac --- /dev/null +++ b/tests/test_popups.py @@ -0,0 +1,151 @@ +# -*- coding: utf-8 -*- + +# Copyright 2015 splinter authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +from .base import get_browser +from .fake_webapp import EXAMPLE_APP + +import pytest + + +supported_browsers = [ + 'chrome', 'firefox', 'chrome_fullscreen', 'firefox_fullscreen', +] + + +@pytest.fixture +def get_new_browser(request): + def new_browser(browser_name): + browser = get_browser(browser_name) + request.addfinalizer(browser.quit) + return browser + return new_browser + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_lists_all_windows_as_window_instances(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + browser.find_by_id("open-popup").click() + + assert 2 == len(browser.windows) + + for window, handle in zip( + browser.windows, browser.driver.window_handles + ): + assert window.name == handle + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_current_is_a_window_instance_pointing_to_current_window(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + + assert browser.windows.current.name == browser.driver.current_window_handle + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_set_current_to_window_instance_sets_current_window(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + browser.find_by_id("open-popup").click() + + last_current_window = browser.windows.current + browser.windows.current = browser.windows.current.next + assert browser.windows.current != last_current_window + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_next_prev_return_next_prev_windows(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + browser.find_by_id("open-popup").click() + + assert browser.windows.current.next == browser.windows.current.prev + assert browser.windows.current != browser.windows.current.next + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_is_current_returns_true_if_current_window_else_false(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + browser.find_by_id("open-popup").click() + + assert browser.windows.current.is_current + assert not browser.windows.current.next.is_current + + # Close popup window + browser.windows.current.close_others() + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_set_is_current_to_true_sets_window_to_current(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + browser.find_by_id("open-popup").click() + + next_window = browser.windows.current.next + assert not next_window.is_current + next_window.is_current = True + assert browser.windows.current == next_window + assert next_window.is_current + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_get_window_by_index(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + browser.find_by_id("open-popup").click() + + assert browser.windows[0].name == browser.driver.window_handles[0] + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_get_window_by_name(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + browser.find_by_id("open-popup").click() + + window_handle = browser.driver.window_handles[0] + assert browser.windows[window_handle].name == window_handle + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_close_closes_window(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + browser.find_by_id("open-popup").click() + + current = browser.windows.current + current.next.close() + assert 1 == len(browser.windows) + assert browser.windows.current == current + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_close_current_window_expect_previous_window_becomes_current(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + browser.find_by_id("open-popup").click() + + prev = browser.windows.current + current = prev.next + prev.next.is_current = True + current.close() + assert 1 == len(browser.windows) + assert browser.windows.current == prev + + +@pytest.mark.parametrize('browser_name', supported_browsers) +def test_close_others_expect_close_all_other_open_windows(browser_name, get_new_browser): + browser = get_new_browser(browser_name) + browser.visit(EXAMPLE_APP) + + current = browser.windows.current + browser.find_by_id("open-popup").click() + current.close_others() + + assert browser.windows[0] == current + assert 1 == len(browser.windows)