Skip to content

Commit

Permalink
Refactor popups tests to ensure they run isolated from other tests. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfehler authored Jun 30, 2021
1 parent efde24e commit 5014794
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 97 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
12 changes: 8 additions & 4 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -163,7 +168,6 @@ class WebDriverTests(
IsElementVisibleTest,
AsyncFinderTests,
MouseInteractionTest,
PopupWindowsTest,
ScreenshotTest,
HTMLSnapshotTest,
):
Expand Down
90 changes: 0 additions & 90 deletions tests/popups.py

This file was deleted.

151 changes: 151 additions & 0 deletions tests/test_popups.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 5014794

Please sign in to comment.