diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml
index 55b64b622..a911799c0 100644
--- a/.github/workflows/macos.yml
+++ b/.github/workflows/macos.yml
@@ -61,4 +61,4 @@ jobs:
run: |
gtimeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-standalone.log && exit 2)
- tox -e tests_selenium_safari -- --cache-clear -n 1 tests || tox -e tests_selenium_safari -- -n 1 --last-failed --last-failed-no-failures none
+ tox -e tests_selenium_remote_safari -- --cache-clear -n 1 || tox -e tests_selenium_remote_safari -- -n 1 --last-failed --last-failed-no-failures none
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index e6e6a4301..909e69e35 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -43,13 +43,15 @@ jobs:
- name: Install test dependencies
run: pip install tox
- - name: Run tests
+ - name: Run splinter tests
run: |
tox -e tests_splinter -- -n 4
- - name: Run non-webdriver driver tests
+ - name: Run lxml-based driver tests
run: |
- tox -e tests_lxml_drivers -- -n 4
+ tox -e tests_django -- -n 2;
+ tox -e tests_flask -- -n 2;
+ tox -e tests_zopetestbrowser -- -n 2;
tests_selenium_remote:
runs-on: ubuntu-latest
@@ -91,7 +93,8 @@ jobs:
xvfb-run java -jar selenium-server.jar standalone > selenium-server.log 2>&1 &
timeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-server.log && exit 2)
echo "Selenium server is ready, running tests"
- tox -e tests_selenium_remote
+ tox -e tests_selenium_remote_firefox
+ tox -e tests_selenium_remote_chrome
tests_selenium:
runs-on: ubuntu-latest
diff --git a/pytest.ini b/pytest.ini
index 1c51692a0..7a2de44dc 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -1,3 +1,2 @@
[pytest]
-markers =
- macos: tests can be runned only on MacOS (Safari)
+addopts = -v --durations=10
diff --git a/requirements/test.txt b/requirements/test.txt
index 626ba9d53..15ce89656 100644
--- a/requirements/test.txt
+++ b/requirements/test.txt
@@ -1,8 +1,6 @@
-Flask==3.0.3
-coverage==7.5.3
argparse
-Django>=2.0.6
+coverage==7.5.3
+Flask==3.0.3
pytest==8.2.2
-pytest-xdist==3.6.1
pytest-ignore-flaky==2.2.1
-zope.testbrowser==7.0
+pytest-xdist==3.6.1
diff --git a/ruff.toml b/ruff.toml
index d371afe04..34cd5d1fb 100644
--- a/ruff.toml
+++ b/ruff.toml
@@ -46,20 +46,16 @@ ignore = [
[lint.per-file-ignores]
"tests/**" = [
-"B015",
"B018",
"BLE001",
-"C901",
"S101",
"S105",
"S310",
-"PLR0911",
"PLW0603",
"PTH100",
"PTH113",
"PTH118",
"PTH120",
-"T201",
"TRY002",
]
"samples/**" = [
diff --git a/tests/base.py b/tests/base.py
deleted file mode 100644
index dc43689bb..000000000
--- a/tests/base.py
+++ /dev/null
@@ -1,311 +0,0 @@
-# Copyright 2012 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.
-import platform
-import time
-
-import pytest
-
-try:
- from selenium.common.exceptions import WebDriverException
-except ModuleNotFoundError:
- pass
-
-from splinter.config import Config
-
-from .click_elements import ClickElementsTest
-from .cookies import CookiesTest
-from .element_does_not_exist import ElementDoestNotExistTest
-from .fake_webapp import EXAMPLE_APP
-from .find_elements import FindElementsTest
-from .form_elements import FormElementsTest
-from .element import ElementTest
-from .is_element_present import IsElementPresentTest
-from .is_text_present import IsTextPresentTest
-from .type import SlowlyTypeTest
-from .get_browser import get_browser
-
-
-supported_browsers = [
- "chrome",
- "firefox",
- "chrome_fullscreen",
- "firefox_fullscreen",
-]
-
-if platform.system() == "Windows":
- supported_browsers = ["edge"]
-
-
-class BaseBrowserTests(
- ElementTest,
- FindElementsTest,
- FormElementsTest,
- ClickElementsTest,
- CookiesTest,
- SlowlyTypeTest,
- IsTextPresentTest,
-):
- EXAMPLE_APP = EXAMPLE_APP
-
- def get_new_browser(self):
- """Get a new browser instance."""
- driver_name = self.browser.driver_name.lower()
- return get_browser(driver_name)
-
- def test_should_support_with_statement(self):
- browser = self.get_new_browser()
- with browser as b:
- assert b is not None
-
- def test_can_open_page(self):
- """should be able to visit, get title and quit"""
- self.browser.visit(EXAMPLE_APP)
- assert "Example Title" == self.browser.title
-
- def test_can_back_on_history(self):
- """should be able to back on history"""
- self.browser.visit(EXAMPLE_APP)
- self.browser.visit(f"{EXAMPLE_APP}iframe")
- self.browser.back()
- assert EXAMPLE_APP == self.browser.url
-
- def test_can_forward_on_history(self):
- """User can forward history"""
- next_url = f"{EXAMPLE_APP}iframe"
-
- browser = self.get_new_browser()
-
- browser.visit(EXAMPLE_APP)
- browser.visit(next_url)
- browser.back()
-
- browser.forward()
- assert next_url == browser.url
-
- browser.quit()
-
- def test_should_have_html(self):
- self.browser.visit(EXAMPLE_APP)
- html = self.browser.html
- assert "
Example Title" in html
- assert '' in html
-
- def test_should_reload_a_page(self):
- self.browser.visit(EXAMPLE_APP)
- self.browser.reload()
- assert "Example Title" == self.browser.title
-
- def test_should_have_url(self):
- "should have access to the url"
- assert EXAMPLE_APP == self.browser.url
-
- def test_accessing_attributes_of_links(self):
- "should allow link's attributes retrieval"
- foo = self.browser.links.find_by_text("FOO")
- assert "http://localhost:5000/foo" == foo["href"]
-
- def test_accessing_attributes_of_inputs(self):
- "should allow input's attributes retrieval"
- button = self.browser.find_by_css('input[name="send"]')
- assert "send" == button["name"]
-
- def test_accessing_attributes_of_simple_elements(self):
- "should allow simple element's attributes retrieval"
- header = self.browser.find_by_css("h1")
- assert "firstheader" == header["id"]
-
- def test_links_should_have_value_attribute(self):
- foo = self.browser.links.find_by_href("http://localhost:5000/foo")
- assert "FOO" == foo.value
-
- def test_should_receive_browser_on_parent(self):
- 'element should contains the browser on "parent" attribute'
- element = self.browser.find_by_id("firstheader")
- assert self.browser == element.parent
-
- def test_redirection(self):
- """
- when visiting /redirected, browser should be redirected to /redirected-location?come=get&some=true
- browser.url should be updated
- """
- self.browser.visit(f"{EXAMPLE_APP}redirected")
- assert "I just been redirected to this location." in self.browser.html
- assert "redirect-location?come=get&some=true" in self.browser.url
-
-
-class WebDriverTests(
- BaseBrowserTests,
- ElementDoestNotExistTest,
- IsElementPresentTest,
-):
- def test_status_code(self):
- with pytest.raises(NotImplementedError):
- self.browser.status_code
-
- def test_can_open_page_in_new_tab(self):
- """should be able to visit url in a new tab"""
- self.browser.windows.current.new_tab(EXAMPLE_APP)
- self.browser.windows[1].is_current = True
- assert EXAMPLE_APP == self.browser.url
- assert 2 == len(self.browser.windows)
-
- self.browser.windows[0].is_current = True
- self.browser.windows[1].close()
-
- def test_can_execute_javascript(self):
- "should be able to execute javascript"
- self.browser.execute_script("$('body').empty()")
- assert "" == self.browser.find_by_tag("body").value
-
- def test_can_evaluate_script(self):
- "should evaluate script"
- assert 8 == self.browser.evaluate_script("4+4")
-
- def test_can_see_the_text_for_an_element(self):
- "should provide text for an element"
- assert self.browser.find_by_id("simple_text").text == "my test text"
-
- def test_the_text_for_an_element_strips_html_tags(self):
- "should show that the text attribute strips html"
- assert self.browser.find_by_id("text_with_html").text == "another bit of text"
-
- def test_can_verify_if_a_element_is_visible(self):
- "should provide verify if element is visible"
- assert self.browser.find_by_id("visible").visible
-
- def test_can_verify_if_a_element_is_invisible(self):
- "should provide verify if element is invisible"
- assert not self.browser.find_by_id("invisible").visible
-
- def test_default_wait_time(self):
- "should driver default wait time 2"
- assert 2 == self.browser.wait_time
-
- def test_access_alerts_and_accept_them(self):
- self.browser.visit(EXAMPLE_APP + "alert")
- self.browser.find_by_tag("h1").click()
- alert = self.browser.get_alert()
- assert "This is an alert example." == alert.text
- alert.accept()
-
- def test_access_prompts_and_be_able_to_fill_then(self):
- self.browser.visit(EXAMPLE_APP + "alert")
- self.browser.find_by_tag("h2").click()
-
- alert = self.browser.get_alert()
- assert "What is your name?" == alert.text
- alert.fill_with("Splinter")
- alert.accept()
-
- # Wait for alert
- time.sleep(2.5)
-
- response = self.browser.get_alert()
- assert "Splinter" == response.text
- response.accept()
-
- def test_access_confirm_and_accept_and_dismiss_them(self):
- self.browser.visit(EXAMPLE_APP + "alert")
-
- self.browser.find_by_tag("h3").click()
- alert = self.browser.get_alert()
-
- assert "Should I continue?" == alert.text
- alert.accept()
-
- # Wait for alert
- time.sleep(2.5)
-
- alert = self.browser.get_alert()
- assert "You say I should" == alert.text
- alert.accept()
-
- self.browser.find_by_tag("h3").click()
- alert = self.browser.get_alert()
- assert "Should I continue?" == alert.text
- alert.dismiss()
-
- # Wait for alert
- time.sleep(2.5)
-
- alert = self.browser.get_alert()
- assert "You say I should not" == alert.text
- alert.accept()
-
- def test_access_confirm_and_accept_and_dismiss_them_using_with(self):
- self.browser.visit(EXAMPLE_APP + "alert")
-
- self.browser.find_by_tag("h3").click()
- with self.browser.get_alert() as alert:
- assert "Should I continue?" == alert.text
- alert.accept()
-
- # Wait for alert
- time.sleep(2.5)
-
- with self.browser.get_alert() as alert:
- assert "You say I should" == alert.text
- alert.accept()
-
- self.browser.find_by_tag("h3").click()
- with self.browser.get_alert() as alert:
- assert "Should I continue?" == alert.text
- alert.dismiss()
-
- # Wait for alert
- time.sleep(2.5)
-
- with self.browser.get_alert() as alert:
- assert "You say I should not" == alert.text
- alert.accept()
-
- def test_access_alerts_using_with(self):
- "should access alerts using 'with' statement"
- self.browser.visit(EXAMPLE_APP + "alert")
- self.browser.find_by_tag("h1").click()
- with self.browser.get_alert() as alert:
- assert "This is an alert example." == alert.text
- alert.accept()
-
- def test_get_alert_return_none_if_no_alerts(self):
- "should return None if no alerts available"
- alert = self.browser.get_alert()
- assert alert is None
-
- def test_can_select_a_option_via_element_text(self):
- "should provide a way to select a option via element"
- assert not self.browser.find_option_by_value("rj").selected
- self.browser.find_by_name("uf").select_by_text("Rio de Janeiro")
- assert self.browser.find_option_by_value("rj").selected
-
- def test_should_be_able_to_change_user_agent(self):
- driver_name = self.browser.driver_name.lower()
-
- config = Config(user_agent="iphone")
- browser = get_browser(driver_name, config=config)
- browser.visit(EXAMPLE_APP + "useragent")
-
- assert "iphone" in browser.html
-
- browser.quit()
-
- def test_execute_script_returns_result_if_present(self):
- assert self.browser.execute_script("return 42") == 42
-
- def test_click_intercepted(self):
- """Intercepted clicks should retry."""
- self.browser.visit(EXAMPLE_APP + "click_intercepted")
- self.browser.wait_time = 10
- # Clicking this element adds a new element to the page.
- self.browser.find_by_id("overlapped").click()
- value = self.browser.find_by_id("added_container").value
- assert "Added" == value
- self.browser.wait_time = 2
-
- def test_click_intercepted_fails(self):
- """Intercepted clicks that never unblock should raise an error."""
- self.browser.visit(EXAMPLE_APP + "click_intercepted")
-
- with pytest.raises(WebDriverException):
- self.browser.find_by_id("overlapped2").click()
diff --git a/tests/click_elements.py b/tests/click_elements.py
deleted file mode 100644
index fec446f57..000000000
--- a/tests/click_elements.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright 2012 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 ClickElementsTest:
- def test_click_links(self):
- self.browser.links.find_by_text("FOO").click()
- assert "BAR!" in self.browser.html
-
- def test_click_element_by_css_selector(self):
- self.browser.find_by_css('a[href="http://localhost:5000/foo"]').click()
- assert "BAR!" in self.browser.html
-
- def test_click_input_by_css_selector(self):
- self.browser.find_by_css('input[name="send"]').click()
- assert "My name is: Master Splinter" in self.browser.html
diff --git a/tests/conftest.py b/tests/conftest.py
index effd5dd41..c5f62c97d 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,18 +1,34 @@
import os
import sys
from multiprocessing import Process
+from urllib import parse
from urllib.request import urlopen
import pytest
from tests.fake_webapp import EXAMPLE_APP
from tests.fake_webapp import start_flask_app
-from tests.get_browser import get_browser
import splinter
from splinter import Browser
from splinter.config import Config
+# Catch for when non-webdriver set of tests are run.
+try:
+ from selenium import webdriver
+except ModuleNotFoundError:
+ pass
+
+
+def selenium_server_is_running():
+ try:
+ from splinter.driver.webdriver.remote import WebDriver
+
+ page_contents = urlopen(WebDriver.DEFAULT_URL).read()
+ except OSError:
+ return False
+ return "WebDriver Hub" in page_contents
+
class Env:
def __init__(self):
@@ -71,16 +87,6 @@ def pytest_unconfigure(config):
stop_server()
-@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
-
-
def pytest_addoption(parser):
group = parser.getgroup(
"splinter",
@@ -93,6 +99,18 @@ def pytest_addoption(parser):
choices=list(splinter.browser._DRIVERS.keys()),
dest="browser_name",
)
+ group.addoption(
+ "--webdriver-remote-name",
+ help="Name of the driver to use when running Remote Webdriver.",
+ type=str,
+ dest="webdriver_remote_name",
+ )
+ group.addoption(
+ "--webdriver-fullscreen",
+ help="Run webdriver tests in fullscreen mode.",
+ type=bool,
+ dest="webdriver_fullscreen",
+ )
@pytest.fixture(scope="session")
@@ -101,15 +119,52 @@ def browser_name(request) -> str:
@pytest.fixture(scope="session")
-def browser_config():
- return Config(headless=True)
+def browser_config(request):
+ c = Config(headless=True)
+ if request.config.option.webdriver_fullscreen:
+ c.fullscreen = True
+ return c
@pytest.fixture(scope="session")
-def browser_kwargs():
+def browser_kwargs(request):
+ option = request.config.option
+
+ if option.webdriver_remote_name:
+ return {"browser": request.config.option.webdriver_remote_name}
+
+ if option.browser_name == "flask":
+ from tests.fake_webapp import app
+
+ return {"app": app, "wait_time": 0.1}
+
+ if option.browser_name == "django":
+ components = parse.urlparse("http://127.0.0.1:5000/")
+ return {
+ "wait_time": 0.1,
+ "client_SERVER_NAME": components.hostname,
+ "client_SERVER_PORT": components.port,
+ }
+
return {}
@pytest.fixture(scope="function")
-def browser(browser_name, browser_config, browser_kwargs):
- return Browser(browser_name, config=browser_config, **browser_kwargs)
+def browser(browser_name, browser_config, browser_kwargs, request):
+ b = Browser(browser_name, config=browser_config, **browser_kwargs)
+ request.addfinalizer(b.quit)
+
+ if not request.config.option.webdriver_fullscreen:
+ if browser_name in ["chrome", "firefox", "edge"]:
+ b.driver.set_window_size(1024, 768)
+
+ if browser_name == "chrome":
+ options = webdriver.chrome.options.Options()
+ options.add_argument("--disable-dev-shm-usage")
+
+ return b
+
+
+@pytest.fixture(scope="session")
+def app_url():
+ return "http://127.0.0.1:5000/"
diff --git a/tests/cookies.py b/tests/cookies.py
deleted file mode 100644
index eb5726088..000000000
--- a/tests/cookies.py
+++ /dev/null
@@ -1,120 +0,0 @@
-# Copyright 2012 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.
-import time
-
-
-class CookiesTest:
- def test_create_and_access_a_cookie(self):
- """Should be able to create and access a cookie"""
- browser = self.get_new_browser()
- browser.visit(self.EXAMPLE_APP)
-
- browser.cookies.add({"sha": "zam"})
-
- assert "zam" == browser.cookies["sha"]
-
- browser.quit()
-
- def test_create_many_cookies_at_once_as_dict(self):
- """Should be able to create many cookies at once as dict"""
- browser = self.get_new_browser()
- browser.visit(self.EXAMPLE_APP)
-
- cookies = {"sha": "zam", "foo": "bar"}
- browser.cookies.add(cookies)
-
- assert "zam" == browser.cookies["sha"]
- assert "bar" == browser.cookies["foo"]
-
- browser.quit()
-
- def test_create_some_cookies_and_delete_them_all(self):
- """Should be able to delete all cookies"""
- browser = self.get_new_browser()
- browser.visit(self.EXAMPLE_APP)
-
- browser.cookies.add({"whatever": "and ever"})
- browser.cookies.add({"anothercookie": "im bored"})
- browser.cookies.delete_all()
-
- assert {} == browser.cookies
-
- browser.quit()
-
- def test_create_and_delete_a_cookie(self):
- """Should be able to create and destroy a cookie"""
- browser = self.get_new_browser()
- browser.visit(self.EXAMPLE_APP)
-
- browser.cookies.delete_all()
- browser.cookies.add({"cookie": "with milk"})
- browser.cookies.delete("cookie")
-
- assert {} == browser.cookies
-
- browser.quit()
-
- def test_create_and_delete_many_cookies(self):
- """Should be able to create and destroy many cookies"""
- browser = self.get_new_browser()
- browser.visit(self.EXAMPLE_APP)
-
- browser.cookies.delete_all()
- browser.cookies.add({"acookie": "cooked"})
- browser.cookies.add({"anothercookie": "uncooked"})
- browser.cookies.add({"notacookie": "halfcooked"})
- browser.cookies.delete("acookie", "notacookie")
-
- assert "uncooked" == browser.cookies["anothercookie"]
-
- browser.quit()
-
- def test_try_to_destroy_an_absent_cookie_and_nothing_happens(self):
- browser = self.get_new_browser()
- browser.visit(self.EXAMPLE_APP)
-
- browser.cookies.delete_all()
- browser.cookies.add({"foo": "bar"})
- browser.cookies.delete("mwahahahaha")
-
- {"foo": "bar"} == browser.cookies
-
- browser.quit()
-
- def test_create_and_get_all_cookies(self):
- """Should be able to create some cookies and retrieve them all"""
- browser = self.get_new_browser()
- browser.visit(self.EXAMPLE_APP)
-
- browser.cookies.delete_all()
- browser.cookies.add({"taco": "shrimp"})
- browser.cookies.add({"lavar": "burton"})
-
- assert 2 == len(browser.cookies.all())
-
- browser.cookies.delete_all()
-
- assert {} == browser.cookies.all()
-
- browser.quit()
-
- def test_create_and_use_contains(self):
- """Should be able to create many cookies at once as dict"""
- browser = self.get_new_browser()
- browser.visit(self.EXAMPLE_APP)
-
- cookies = {"sha": "zam"}
- browser.cookies.add(cookies)
-
- assert "sha" in browser.cookies
- assert "foo" not in browser.cookies
-
- browser.quit()
-
- def test_cookies_extra_parameters(self):
- """Cookie can be created with extra parameters."""
- timestamp = int(time.time() + 120)
- self.browser.cookies.add({"sha": "zam"}, expiry=timestamp)
- cookie = self.browser.driver.get_cookie("sha")
- assert timestamp == cookie["expiry"]
diff --git a/tests/element.py b/tests/element.py
deleted file mode 100644
index 978c8087f..000000000
--- a/tests/element.py
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright 2012 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 ElementTest:
- def test_element_has_class_when_element_has_the_class_as_first_class(self):
- assert self.browser.find_by_css(".has-class-first").has_class("has-class-first")
-
- def test_element_has_class_when_element_has_the_class_as_middle_class(self):
- assert self.browser.find_by_css(".has-class-middle").has_class("has-class-middle")
-
- def test_element_has_class_when_element_has_the_class_as_end_class(self):
- assert self.browser.find_by_css(".has-class-end").has_class("has-class-end")
-
- def test_element_has_class_when_element_doesnt_have_the_class(self):
- assert not self.browser.find_by_css(".has-class-first").has_class("has-class")
-
- def test_element_outer_html(self):
- assert self.browser.find_by_id("html-property").outer_html == (
- ''
- 'inner
inner text
html test
'
- )
-
- def test_element_html_with_breakline(self):
- assert self.browser.find_by_id("html-property-with-breakline").html == "\\n some text here\\n"
-
- def test_element_html(self):
- assert (
- self.browser.find_by_id("html-property").html == 'inner inner text
html test'
- )
diff --git a/tests/element_does_not_exist.py b/tests/element_does_not_exist.py
deleted file mode 100644
index aac6dc41d..000000000
--- a/tests/element_does_not_exist.py
+++ /dev/null
@@ -1,52 +0,0 @@
-# Copyright 2012 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.
-import pytest
-
-from splinter.exceptions import ElementDoesNotExist
-
-
-class ElementDoestNotExistTest:
- def test_element_query_should_raises_when_element_first_doest_exists(self):
- with pytest.raises(ElementDoesNotExist):
- self.browser.find_by_css(".element-that-dont-exists").first
-
- def test_element_list_raises_when_element_last_does_not_exists(self):
- with pytest.raises(ElementDoesNotExist):
- self.browser.find_by_css(".element-that-dont-exists").last
-
- def test_element_list_raises_when_element_does_not_exists(self):
- with pytest.raises(ElementDoesNotExist):
- self.browser.find_by_css(".element-that-dont-exists")[2]
-
- def test_element_list_raises_with_unicode_query(self):
- with pytest.raises(ElementDoesNotExist):
- self.browser.find_by_css(".element[title=título]").last
-
- def test_element_list_contains_right_information_and_raises_right_exception(self):
- "element list contains right information about query and raises nice exception message"
- with pytest.raises(ElementDoesNotExist) as err:
- element_list = self.browser.find_by_css(".element-that-dont-exists")
- assert "css" == element_list.find_by
- assert ".element-that-dont-exists" == element_list.query
- element_list.first
-
- expected_message = 'No elements were found with css ".element-that-dont-exists"'
-
- assert expected_message == err.value.args[0]
-
- def test_element_list_raises_when_element_first_doesnt_exists_in_element_context(
- self,
- ):
- "element list raises exception with right information in element context"
- with pytest.raises(ElementDoesNotExist) as err:
- element_list = self.browser.find_by_css("#inside").find_by_css(
- ".inner-element-that-dont-exists",
- )
- assert "css" == element_list.find_by
- assert ".inner-element-that-dont-exists" == element_list.query
- element_list.first
-
- expected_message = 'No elements were found with css ".inner-element-that-dont-exists"'
-
- assert expected_message == err.value.args[0]
diff --git a/tests/find_elements.py b/tests/find_elements.py
deleted file mode 100644
index 892dfe3ce..000000000
--- a/tests/find_elements.py
+++ /dev/null
@@ -1,242 +0,0 @@
-# Copyright 2012 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 splinter.driver import ElementAPI
-from splinter.element_list import ElementList
-
-
-class FindElementsTest:
- def test_finding_by_css(self):
- value = self.browser.find_by_css("h1").value
- assert "Example Header" == value
-
- def test_finding_by_xpath(self):
- value = self.browser.find_by_xpath("//h1").value
- assert "Example Header" == value
-
- def test_finding_by_tag(self):
- value = self.browser.find_by_tag("h1").value
- assert "Example Header" == value
-
- def test_finding_by_value(self):
- value = self.browser.find_by_value("M").value
- element = self.browser.find_by_id("gender-m")
- assert element.value == value
-
- def test_finding_by_value_in_btn_elements(self):
- value = self.browser.find_by_value("some value").value
- btn = self.browser.find_by_id("button-value")
- assert btn.value == value
-
- def test_finding_by_text(self):
- element = self.browser.find_by_text("Complex")
- assert element.value == "Complex"
-
- def test_finding_by_text_with_quotation_marks(self):
- element = self.browser.find_by_text('Quotation " marks')
- assert element.value == 'Quotation " marks'
-
- def test_finding_by_id(self):
- value = self.browser.find_by_id("firstheader").value
- assert "Example Header" == value
-
- def test_finding_by_name(self):
- value = self.browser.find_by_name("query").value
- assert "default value" == value
-
- def test_finding_all_elements_by_css(self):
- value = self.browser.find_by_css("h1")[0].value
- assert "Example Header" == value
-
- def test_finding_all_elements_by_xpath(self):
- value = self.browser.find_by_xpath("//h1")[0].value
- assert "Example Header" == value
-
- def test_finding_all_elements_by_tag(self):
- value = self.browser.find_by_tag("h1")[0].value
- assert "Example Header" == value
-
- def test_finding_all_elements_by_id(self):
- value = self.browser.find_by_id("firstheader").value
- assert "Example Header" == value
-
- def test_finding_all_elements_by_name(self):
- value = self.browser.find_by_name("query").value
- assert "default value" == value
-
- def test_finding_all_links_by_text(self):
- link = self.browser.links.find_by_text("Link for Example.com")[0]
- assert "http://example.com/" == link["href"]
-
- def test_finding_all_links_by_href(self):
- link = self.browser.links.find_by_href("http://example.com/")[0]
- assert "http://example.com/" == link["href"]
-
- def test_finding_all_links_by_partial_href(self):
- link = self.browser.links.find_by_partial_href("example.c")[0]
- assert "http://example.com/" == link["href"]
-
- def test_finding_all_links_by_partial_text(self):
- link = self.browser.links.find_by_partial_text("FOO")[0]
- assert "http://localhost:5000/foo" == link["href"]
-
- def test_find_links_by_partial_text_nested_elements(self):
- """
- When text is split in multiple child elements of a parent link element
- Then the parent link element is found
- """
- expected = "http://localhost:5000/nested"
-
- link = self.browser.links.find_by_partial_text("Nested text")[0]
- assert expected == link["href"]
-
- link = self.browser.links.find_by_partial_text("in a link")[0]
- assert expected == link["href"]
-
- link = self.browser.links.find_by_partial_text("Nested text in")[0]
- assert expected == link["href"]
-
- link = self.browser.links.find_by_partial_text("text in a link")[0]
- assert expected == link["href"]
-
- link = self.browser.links.find_by_partial_text("Nested text in a link")[0]
- assert expected == link["href"]
-
- def test_finding_last_element_by_css(self):
- value = self.browser.find_by_css("h1").last.value
- assert "Example Last Header" == value
-
- def test_finding_last_element_by_xpath(self):
- value = self.browser.find_by_xpath("//h1").last.value
- assert "Example Last Header" == value
-
- def test_finding_last_element_by_tag(self):
- value = self.browser.find_by_tag("h1").last.value
- assert "Example Last Header" == value
-
- def test_finding_last_element_by_id(self):
- value = self.browser.find_by_id("firstheader").last.value
- assert "Example Header" == value
-
- def test_last_element_is_same_than_first_element_in_find_by_id(self):
- # a html page have contain one element by id
- first = self.browser.find_by_id("firstheader").value
- last = self.browser.find_by_id("firstheader").last.value
- assert first == last
-
- def test_finding_last_element_by_name(self):
- value = self.browser.find_by_name("input1").last.value
- assert "default last value" == value
-
- def test_finding_last_link_by_text(self):
- link = self.browser.links.find_by_text("Link for Example.com").last
- assert "http://example.com/last" == link["href"]
-
- def test_finding_last_link_by_href(self):
- link = self.browser.links.find_by_href("http://example.com/").last
- assert "Link for last Example.com" == link.text
-
- def test_finding_link_by_partial_href(self):
- link = self.browser.links.find_by_partial_href("example.c").last
- assert "Link for last Example.com" == link.text
-
- def test_finding_last_link_by_partial_text(self):
- link = self.browser.links.find_by_partial_text("FOO").last
- assert "A wordier (and last) link to FOO" == link.text
-
- def test_finding_element_by_css_using_slice(self):
- value = self.browser.find_by_css("h1")[-1].value
- assert "Example Last Header" == value
-
- def test_finding_element_by_xpath_using_slice(self):
- value = self.browser.find_by_xpath("//h1")[-1].value
- assert "Example Last Header" == value
-
- def test_finding_element_by_tag_using_slice(self):
- value = self.browser.find_by_tag("h1")[-1].value
- assert "Example Last Header" == value
-
- def test_finding_element_by_id_using_slice(self):
- value = self.browser.find_by_id("firstheader")[-1].value
- assert "Example Header" == value
-
- def test_all_elements_is_same_than_first_element_in_find_by_id(self):
- # a html page have contain one element by id
- first = self.browser.find_by_id("firstheader").value
- some = self.browser.find_by_id("firstheader")[-1].value
- assert first == some
-
- def test_finding_element_by_name_using_slice(self):
- value = self.browser.find_by_name("input1")[-1].value
- assert "default last value" == value
-
- def test_finding_link_by_text_using_slice(self):
- link = self.browser.links.find_by_text("Link for Example.com")[-1]
- assert "http://example.com/last" == link["href"]
-
- def test_finding_link_by_href_using_slice(self):
- "should find link by href using slice"
- link = self.browser.links.find_by_href("http://example.com/")[-1]
- assert "Link for last Example.com" == link.text
-
- def test_finding_links_by_text(self):
- "should find links by text"
- link = self.browser.links.find_by_text("Link for Example.com")
- assert "http://example.com/" == link["href"]
-
- def test_finding_links_by_href(self):
- "should find links by href"
- link = self.browser.links.find_by_href("http://example.com/")
- assert "http://example.com/" == link["href"]
-
- def test_find_by_css_in_element_context(self):
- "should find elements by css in element context and should return splinter driver element"
- elements = self.browser.find_by_css("#inside")
- decendent = elements[0].find_by_css("h2")
- assert decendent.text.strip() == "inside"
- assert isinstance(decendent, ElementList)
- assert isinstance(decendent[0], ElementAPI)
-
- def test_find_by_xpath_in_element_context(self):
- "should find elements by xpath in element context"
- elements = self.browser.find_by_css("#inside")
- decendent = elements[0].find_by_xpath("//h2")
- assert decendent.text.strip() == "inside"
- assert isinstance(decendent, ElementList)
- assert isinstance(decendent.first, ElementAPI)
-
- def test_find_by_name_in_element_context(self):
- elements = self.browser.find_by_css("#inside")
- decendent = elements[0].find_by_name("crazy-upload")
- assert len(decendent) == 1
- assert isinstance(decendent, ElementList)
- assert isinstance(decendent.first, ElementAPI)
-
- def test_find_by_tag_in_element_context(self):
- elements = self.browser.find_by_css("#inside")
- decendent = elements[0].find_by_tag("input")
- assert len(decendent) == 1
- assert isinstance(decendent, ElementList)
- assert isinstance(decendent.first, ElementAPI)
-
- def test_find_by_id_in_element_context(self):
- elements = self.browser.find_by_css("#inside")
- decendent = elements[0].find_by_id("visible")
- assert len(decendent) == 1
- assert isinstance(decendent, ElementList)
- assert isinstance(decendent.first, ElementAPI)
-
- def test_find_by_value_in_element_context(self):
- elements = self.browser.find_by_css("#inside")
- decendent = elements[0].find_by_value("crazy diamond")
- assert len(decendent) == 1
- assert isinstance(decendent, ElementList)
- assert isinstance(decendent.first, ElementAPI)
-
- def test_finding_by_text_in_element_context(self):
- inside = self.browser.find_by_id("inside")
- element = inside.find_by_text("Complex")
-
- assert len(element) == 1
- assert element["class"] == "inside"
- assert element.value == "Complex"
diff --git a/tests/form_elements.py b/tests/form_elements.py
deleted file mode 100644
index bbdb08be2..000000000
--- a/tests/form_elements.py
+++ /dev/null
@@ -1,304 +0,0 @@
-# Copyright 2012 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.
-import re
-import time
-
-import pytest
-
-from splinter.exceptions import ElementDoesNotExist
-
-
-def skip_if_zope(f):
- def wrapper(self, *args, **kwargs):
- if self.__class__.__name__ == "TestZopeTestBrowserDriver":
- return pytest.skip("skipping this test for zope testbrowser")
- else:
- f(self, *args, **kwargs)
-
- return wrapper
-
-
-def skip_if_django(f):
- def wrapper(self, *args, **kwargs):
- if self.__class__.__name__ == "TestDjangoClientDriver":
- return pytest.skip("skipping this test for django")
- else:
- f(self, *args, **kwargs)
-
- return wrapper
-
-
-class FormElementsTest:
- def test_fill(self):
- my_input = "LT-CS-01/2018"
- elem = self.browser.find_by_name("query")
- elem.fill(my_input)
- assert my_input == elem.value
-
- def test_fill_element(self):
- self.browser.find_by_name("q").fill("new query")
- time.sleep(1)
- value = self.browser.find_by_name("q").value
- assert "new query" == value
-
- @skip_if_zope
- def test_clicking_submit_input_doesnt_post_input_value_if_name_not_present(self):
- self.browser.find_by_css("input.submit-input-no-name").click()
- assert self.browser.find_by_xpath("/descendant-or-self::*").text.strip() == ""
-
- @skip_if_zope
- def test_clicking_submit_input_posts_empty_value_if_value_not_present(self):
- self.browser.find_by_css('input[name="submit-input-no-value"]').click()
- body_text = self.browser.find_by_xpath("/descendant-or-self::*").text.strip()
- assert re.match(r"^submit-input-no-value:(?:| Submit| Submit Query)$", body_text), repr(body_text)
-
- @skip_if_zope
- def test_clicking_submit_input_doesnt_post_input_value_if_empty(self):
- self.browser.find_by_css("input.submit-input-empty").click()
- assert self.browser.find_by_xpath("/descendant-or-self::*").text.strip() == ""
-
- def test_clicking_submit_input_posts_input_value_if_value_present(self):
- self.browser.find_by_css('input[name="submit-input"]').click()
- assert self.browser.find_by_xpath("/descendant-or-self::*").text == "submit-input: submit-input-value"
-
- @skip_if_zope
- def test_clicking_submit_button_doesnt_post_button_value_if_name_not_present(self):
- self.browser.find_by_css("button.submit-button-no-name").click()
- assert self.browser.find_by_xpath("/descendant-or-self::*").text == ""
-
- @skip_if_zope
- def test_clicking_submit_button_posts_empty_value_if_value_not_present(self):
- self.browser.find_by_css('button[name="submit-button-no-value"]').click()
- assert self.browser.find_by_xpath("/descendant-or-self::*").text.strip() == "submit-button-no-value:"
-
- @skip_if_zope
- def test_clicking_submit_button_doesnt_post_button_value_if_empty(self):
- self.browser.find_by_css("button.submit-button-empty").click()
- assert self.browser.find_by_xpath("/descendant-or-self::*").text.strip() == ""
-
- @skip_if_zope
- def test_clicking_submit_button_posts_button_value_if_value_present(self):
- self.browser.find_by_css('button[name="submit-button"]').click()
-
- assert self.browser.find_by_xpath("/descendant-or-self::*").text == "submit-button: submit-button-value"
-
- def test_submiting_a_form_and_verifying_page_content(self):
- self.browser.find_by_name("query").fill("my name")
- self.browser.find_by_name("send").click()
- assert "My name is: Master Splinter" in self.browser.html
-
- def test_can_choose_a_radio_button(self):
- "should provide a way to choose a radio button"
- assert not self.browser.find_by_id("gender-m").checked
- self.browser.choose("gender", "M")
- assert self.browser.find_by_id("gender-m").checked
-
- def test_can_find_textarea_by_tag(self):
- "should provide a way to find a textarea by tag_name"
- tag = self.browser.find_by_tag("textarea").first
- assert "" == tag.value
-
- def test_can_find_input_without_type(self):
- "should recognize an input element that doesn't have a `type` attribute"
- tag = self.browser.find_by_css('[name="typeless"]').first
- assert "default value" == tag.value
-
- def test_can_find_button(self):
- "should recognize a button"
- tag = self.browser.find_by_css(".just-a-button").first
- assert hasattr(tag, "click")
-
- def test_can_find_option_by_value(self):
- "should provide a way to find select option by value"
- assert "Rio de Janeiro" == self.browser.find_option_by_value("rj").text
-
- def test_can_get_value_attribute_for_a_option(self):
- "should option have a value attribute"
- assert "rj" == self.browser.find_option_by_value("rj")["value"]
-
- def test_can_find_option_by_text(self):
- "should provide a way to find select option by text"
- assert "rj" == self.browser.find_option_by_text("Rio de Janeiro").value
-
- def test_can_select_a_option(self):
- "should provide a way to select a option"
- assert not self.browser.find_option_by_value("rj").selected
- self.browser.select("uf", "rj")
- assert self.browser.find_option_by_value("rj").selected
-
- def test_can_select_an_option_in_an_optgroup(self):
- "should provide a way to select an option that is in an optgroup"
- assert self.browser.find_by_name("food").value == "apples"
- self.browser.select("food", "grapes")
- assert self.browser.find_by_name("food").value == "grapes"
-
- def test_can_select_a_option_via_element(self):
- "should provide a way to select a option via element"
- assert not self.browser.find_option_by_value("rj").selected
- self.browser.find_by_name("uf").select("rj")
- assert self.browser.find_option_by_value("rj").selected
-
- def test_can_check_a_checkbox(self):
- """should provide a way to check a radio checkbox"""
- elem = self.browser.find_by_name("some-check")
- assert not elem.checked
- elem.check()
- assert elem.checked
-
- def test_check_keeps_checked_if_called_multiple_times(self):
- """should keep a checkbox checked if check() is called multiple times"""
- elem = self.browser.find_by_name("some-check")
- assert not elem.checked
- elem.check()
- elem.check()
- assert elem.checked
-
- def test_can_uncheck_a_checkbox(self):
- """should provide a way to uncheck a radio checkbox"""
- elem = self.browser.find_by_name("checked-checkbox")
- assert elem.checked
- elem.uncheck()
- assert not elem.checked
-
- def test_uncheck_should_keep_unchecked_if_called_multiple_times(self):
- """should keep a checkbox unchecked if uncheck() is called multiple times"""
- elem = self.browser.find_by_name("checked-checkbox")
- assert elem.checked
- elem.uncheck()
- elem.uncheck()
- assert not elem.checked
-
- def test_can_fill_text_field_in_form(self):
- "should provide a away to change field value"
- self.browser.fill_form({"query": "new query"})
- value = self.browser.find_by_name("query").value
- assert "new query" == value
-
- def test_can_fill_password_field_in_form(self):
- "should provide a way to change password value"
- new_password = "new password"
- self.browser.fill_form({"password": new_password})
- value = self.browser.find_by_name("password").value
- assert new_password == value
-
- def test_can_fill_more_than_one_field_in_form(self):
- "should provide a away to change field value"
- self.browser.find_by_name("query").fill("my name")
- assert not self.browser.find_by_id("gender-m").checked
- assert not self.browser.find_option_by_value("rj").selected
- assert not self.browser.find_by_name("some-check").checked
- assert self.browser.find_by_name("checked-checkbox").checked
- self.browser.fill_form(
- {
- "query": "another new query",
- "description": "Just another description value in the textarea",
- "gender": "M",
- "uf": "rj",
- "some-check": True,
- "checked-checkbox": False,
- },
- )
- query_value = self.browser.find_by_name("query").value
- assert "another new query" == query_value
- desc_value = self.browser.find_by_name("description").value
- assert "Just another description value in the textarea" == desc_value
- assert self.browser.find_by_id("gender-m").checked
- assert self.browser.find_option_by_value("rj").selected
- assert self.browser.find_by_name("some-check").checked
- assert not self.browser.find_by_name("checked-checkbox").checked
-
- def test_can_fill_tel_text_field(self):
- "should provide a way to change a tel field value"
- new_telephone = "555-0042"
- self.browser.fill_form({"telephone": new_telephone})
- value = self.browser.find_by_name("telephone").value
- assert new_telephone == value
-
- def test_can_fill_unknown_text_field(self):
- "should provide a way to change a unknown text field type that isn't specifically defined"
- new_search_keyword = "foobar"
- self.browser.fill_form({"search_keyword": new_search_keyword})
- value = self.browser.find_by_name("search_keyword").value
- assert new_search_keyword == value
-
- def test_can_fill_form_by_id(self):
- "should be able to fill a form by its id"
- self.browser.fill_form(
- {"firstname": "John", "lastname": "Doe"},
- form_id="login",
- )
- value = self.browser.find_by_name("firstname").value
- assert "John" == value
-
- def test_fill_form_missing_values(self):
- """Missing values should raise an error."""
- with pytest.raises(ElementDoesNotExist) as e:
- self.browser.fill_form(
- {"query": "new query", "missing_form": "doesn't exist"},
- )
-
- assert "missing_form" in str(e.value)
-
- def test_fill_form_missing_values_ignore_missing(self):
- """Missing values are ignores when ignore_missing is True."""
- self.browser.fill_form(
- {"query": "new query", "missing_form": "doesn't exist"},
- ignore_missing=True,
- )
- value = self.browser.find_by_name("query").value
- assert "new query" == value
-
- def test_can_clear_text_field_content(self):
- my_input = "random query"
- elem = self.browser.find_by_name("query")
- elem.fill(my_input)
- assert my_input == elem.value
-
- elem.clear()
- assert not elem.value
-
- def test_can_clear_password_field_content(self):
- my_input = "1nF4m310"
- elem = self.browser.find_by_name("password")
- elem.fill(my_input)
- assert my_input == elem.value
-
- elem.clear()
- assert not elem.value
-
- def test_can_clear_tel_field_content(self):
- my_input = "5553743980"
- elem = self.browser.find_by_name("telephone")
- elem.fill(my_input)
- assert my_input == elem.value
-
- elem.clear()
- assert not elem.value
-
- @skip_if_django
- def test_can_clear_textarea_content(self):
- elem = self.browser.find_by_name("description")
- elem.fill("A box of widgets")
- assert "A box of widgets" == elem.value
-
- elem.clear()
- assert "" == elem.value
-
- @skip_if_django
- def test_can_clear_search_content(self):
- elem = self.browser.find_by_name("search_keyword")
- elem.fill("widgets")
- assert "widgets" == elem.value
-
- elem.clear()
- assert "" == elem.value
-
- @skip_if_django
- def test_can_clear_url_content(self):
- elem = self.browser.find_by_name("url_input")
- elem.fill("http://widgets.com")
- assert "http://widgets.com" == elem.value
-
- elem.clear()
- assert "" == elem.value
diff --git a/tests/get_browser.py b/tests/get_browser.py
deleted file mode 100644
index 457155c8b..000000000
--- a/tests/get_browser.py
+++ /dev/null
@@ -1,66 +0,0 @@
-import os
-from urllib import parse
-
-# Catch for when non-webdriver set of tests are run.
-try:
- from selenium import webdriver
-except ModuleNotFoundError:
- pass
-
-from splinter import Browser
-from splinter.config import Config
-
-from .fake_webapp import app, EXAMPLE_APP
-
-
-def get_browser(browser_name, config=None, **kwargs):
- config = config or Config()
- config.headless = True
-
- if browser_name in ["chrome", "chrome_fullscreen"]:
- if browser_name == "chrome_fullscreen":
- config.fullscreen = True
- options = webdriver.chrome.options.Options()
- options.add_argument("--disable-dev-shm-usage")
-
- return Browser("chrome", options=options, config=config, **kwargs)
-
- elif browser_name in ["firefox", "firefox_fullscreen"]:
- if browser_name == "firefox_fullscreen":
- config.fullscreen = True
-
- return Browser("firefox", config=config, **kwargs)
-
- elif browser_name == "remote":
- return Browser("remote")
-
- elif browser_name == "django":
- components = parse.urlparse(EXAMPLE_APP)
- return Browser(
- "django",
- wait_time=0.1,
- client_SERVER_NAME=components.hostname,
- client_SERVER_PORT=components.port,
- **kwargs,
- )
-
- elif browser_name == "flask":
- _app = kwargs.pop("app", app)
- return Browser("flask", app=_app, **kwargs)
-
- elif browser_name == "zope.testbrowser":
- return Browser("zope.testbrowser", **kwargs)
-
- elif browser_name == "edge":
- # Github Actions Windows EdgeDriver path
- service = None
- driver_path = os.getenv("EDGEWEBDRIVER")
- if driver_path:
- from selenium.webdriver.edge.service import Service as EdgeService
-
- edgedriver_path = os.path.join(driver_path, "msedgedriver.exe")
- service = EdgeService(executable_path=edgedriver_path)
-
- return Browser("edge", service=service, config=config, **kwargs)
-
- raise ValueError("Unknown browser name")
diff --git a/tests/is_element_present.py b/tests/is_element_present.py
deleted file mode 100644
index c20fd59cb..000000000
--- a/tests/is_element_present.py
+++ /dev/null
@@ -1,185 +0,0 @@
-# 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 IsElementPresentTest:
- def test_is_element_present_by_css(self):
- "should is element present by css verify if element is present"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_css(".async-element")
-
- def test_is_element_present_by_css_using_a_custom_wait_time(self):
- "should is element present by css verify if element is present using a custom wait time"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_css(".async-element2", wait_time=12)
-
- def test_is_element_present_by_css_returns_false_if_element_is_not_present(self):
- "should is element present by css returns False if element is not present"
- assert not self.browser.is_element_present_by_css(".async-elementzz")
-
- def test_is_element_not_present_by_css(self):
- "should is element not present by css verify if element is not present"
- assert self.browser.is_element_not_present_by_css(".async-element")
-
- def test_is_element_not_present_by_css_returns_false_if_element_is_present(self):
- "should is element not present by css returns False if element is present"
- assert not self.browser.is_element_not_present_by_css("h1")
-
- def test_is_element_not_present_by_css_using_a_custom_wait_time(self):
- "should is element not present by css verify if element is not present using a custom wait time"
- assert self.browser.is_element_not_present_by_css(".async-element", wait_time=12)
-
- def test_is_element_present_by_xpath(self):
- "should is element present by xpath verify if element is present"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_xpath("//h4")
-
- def test_is_element_present_by_xpath_using_a_custom_wait_time(self):
- "should is element present by xpath verify if element is present using a custom wait time"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_xpath("//h5", wait_time=12)
-
- def test_is_element_present_by_xpath_returns_false_if_element_is_not_present(self):
- "should is element present by xpath returns false if element is not present"
- assert self.browser.is_element_not_present_by_xpath("//h4")
-
- def test_is_element_not_present_by_xpath_returns_false_if_element_is_present(self):
- """should is_element_not_present_by_xpath returns False if element is present"""
- self.browser.find_by_css(".add-async-element").click()
- assert len(self.browser.find_by_xpath("//h4")) > 0
- assert not self.browser.is_element_not_present_by_xpath("//h4")
-
- def test_is_element_not_present_by_xpath_using_a_custom_wait_time(self):
- "should is element not present by xpath verify if element is not present using a custom wait time"
- assert self.browser.is_element_not_present_by_xpath("//h4", wait_time=12)
-
- def test_is_element_present_by_tag(self):
- "should is element present by tag verify if element is present"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_tag("h4")
-
- def test_is_element_present_by_tag_using_a_custom_wait_time(self):
- "should is element present by tag verify if element is present using a custom wait time"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_tag("h4", wait_time=12)
-
- def test_is_element_present_by_tag_returns_false_if_element_is_not_present(self):
- "should is element present by tag returns false if element is not present"
- assert not self.browser.is_element_present_by_tag("h4")
-
- def test_is_element_not_present_by_tag(self):
- "should is element not present by tag verify if element is not present"
- assert self.browser.is_element_not_present_by_tag("h4")
-
- def test_is_element_not_present_by_tag_using_a_custom_wait_time(self):
- "should is element not present by tag verify if element is not present using a custom wait time"
- assert self.browser.is_element_not_present_by_tag("h4", wait_time=12)
-
- def test_is_element_not_present_by_tag_returns_false_if_element_is_present(self):
- """should is_element_not_present_by_tag returns False if element is present"""
- self.browser.find_by_css(".add-async-element").click()
- self.browser.find_by_tag("h4")
- assert not self.browser.is_element_not_present_by_tag("h4")
-
- def test_is_element_present_by_text(self):
- "should is element present by text verify if element is present"
- assert self.browser.is_element_present_by_text("Complex")
-
- def test_is_element_present_by_text_returns_false_if_element_is_not_present(self):
- "should is element present by text verify if element is present"
- assert not self.browser.is_element_present_by_text("Not present")
-
- def test_is_element_not_present_by_text(self):
- "should is element not present by text verify if element is not present"
- assert self.browser.is_element_not_present_by_text("Not present")
-
- def test_is_element_not_present_by_text_returns_false_if_element_is_present(self):
- "should is element not present by text returns False if element is present"
- assert not self.browser.is_element_not_present_by_text("Complex")
-
- def test_is_element_present_by_value(self):
- "should is element present by value verify if element is present"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_value("async-header-value")
-
- def test_is_element_present_by_value_using_a_custom_wait_time(self):
- "should is element present by value verify if element is present using a custom wait time"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_value("async-header-value", wait_time=12)
-
- def test_is_element_present_by_value_returns_false_if_element_is_not_present(self):
- "should is element present by value returns False if element is not present"
- assert not self.browser.is_element_present_by_value("async-header-value")
-
- def test_is_element_not_present_by_value(self):
- "should is element not present by value verify if element is not present"
- assert self.browser.is_element_not_present_by_value("async-header-value")
-
- def test_is_element_not_present_by_value_using_a_custom_wait_time(self):
- "should is element not present by value verify if element is not present using a custom wait time"
- assert self.browser.is_element_not_present_by_value(
- "async-header-value",
- wait_time=12,
- )
-
- def test_is_element_not_present_by_value_returns_false_if_element_is_present(self):
- "should is element not present by value returns False if element is present"
- assert not self.browser.is_element_not_present_by_value("default value")
-
- def test_is_element_present_by_id(self):
- "should is element present by id verify if element is present"
- self.browser.find_by_css(".add-async-element").click()
- result = self.browser.is_element_present_by_id("async-header", wait_time=20)
- assert result
-
- def test_is_element_present_by_id_using_a_custom_wait_time(self):
- "should is element present by id verify if element is present using a custom wait time"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_id("async-header", wait_time=12)
-
- def test_is_element_present_by_id_returns_false_if_element_is_not_present(self):
- "should is element present by id returns False if element is not present"
- assert not self.browser.is_element_present_by_id("async-header")
-
- def test_is_element_not_present_by_id(self):
- "should is element not present by id verify if element is not present"
- assert self.browser.is_element_not_present_by_id("async-header")
-
- def test_is_element_not_present_by_id_using_a_custom_wait_time(self):
- "should is element not present by id verify if element is not present using a custom wait time"
- assert self.browser.is_element_not_present_by_id("async-header", wait_time=12)
-
- def test_is_element_not_present_by_id_returns_false_if_element_is_present(self):
- """should is_element_not_present_by_id returns False if element is present"""
- self.browser.find_by_css(".add-async-element").click()
- self.browser.find_by_id("async-header")
- assert not self.browser.is_element_not_present_by_id("async-header")
-
- def test_is_element_present_by_name(self):
- "should is element present by name verify if element is present"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_name("async-input")
-
- def test_is_element_present_by_name_using_a_custom_wait_time(self):
- "should is element present by name verify if element is present using a custom wait time"
- self.browser.find_by_css(".add-async-element").click()
- assert self.browser.is_element_present_by_name("async-input", wait_time=12)
-
- def test_is_element_present_by_name_returns_false_if_element_is_not_present(self):
- "should is element present by name returns false if element is not present"
- assert not self.browser.is_element_present_by_name("async-input")
-
- def test_is_element_not_present_by_name(self):
- "should is element not present by name verify if element is not present"
- assert self.browser.is_element_not_present_by_name("async-input")
-
- def test_is_element_not_present_by_name_using_a_custom_wait_time(self):
- "should is element not present by name verify if element is not present using a custom wait time"
- assert self.browser.is_element_not_present_by_name("async-input", wait_time=12)
-
- def test_is_element_not_present_by_name_returns_false_if_element_is_present(self):
- """should is_element_not_present_by_name returns False if element is present"""
- self.browser.find_by_css(".add-async-element").click()
- self.browser.find_by_name("async-input")
- assert not self.browser.is_element_not_present_by_name("async-input")
diff --git a/tests/is_text_present.py b/tests/is_text_present.py
deleted file mode 100644
index 065ae8b80..000000000
--- a/tests/is_text_present.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright 2012 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 .fake_webapp import EXAMPLE_APP
-
-
-class IsTextPresentTest:
- def test_is_text_present(self):
- "should verify if text is present"
- assert self.browser.is_text_present("Example Header")
-
- def test_is_text_present_and_should_return_false(self):
- "should verify if text is present and return false"
- assert not self.browser.is_text_present("Text that not exist")
-
- def test_is_text_present_and_should_wait_time(self):
- "should verify if text is present and wait for five seconds"
- self.browser.links.find_by_text("FOO").click()
- assert self.browser.is_text_present("BAR!", wait_time=20)
-
- def test_is_text_not_present(self):
- "should verify if text is not present"
- assert self.browser.is_text_not_present("Text that not exist")
-
- def test_is_text_not_present_and_should_return_false(self):
- "should verify if text is not present and return false"
- assert not self.browser.is_text_not_present("Example Header")
-
- def test_is_text_not_present_and_should_wait_time(self):
- "should verify if text is not present and wait for five seconds"
- self.browser.links.find_by_text("FOO").click()
- assert self.browser.is_text_not_present("another text", wait_time=20)
-
- def test_is_text_present_no_body(self):
- "should work properly (return false) even if there's no body"
- self.browser.visit(EXAMPLE_APP + "no-body")
- assert not self.browser.is_text_present("No such text")
-
- def test_is_text_not_present_no_body(self):
- "returns true if there's no body"
- self.browser.visit(EXAMPLE_APP + "no-body")
- assert self.browser.is_text_not_present("No such text")
diff --git a/tests/lxml_drivers.py b/tests/lxml_drivers.py
deleted file mode 100644
index c89fe7b78..000000000
--- a/tests/lxml_drivers.py
+++ /dev/null
@@ -1,128 +0,0 @@
-import os
-
-import pytest
-
-from .fake_webapp import EXAMPLE_APP
-
-
-class LxmlDriverTests:
- def test_cant_switch_to_frame(self):
- """lxml-based drivers should not be able to switch to frames"""
- with pytest.raises(NotImplementedError) as err:
- self.browser.get_iframe("frame_123")
- self.fail()
-
- assert f"{self.browser.driver_name.lower()} doesn't support frames." == err.value.args[0]
-
- def test_attach_file(self):
- """should provide a way to change file field value"""
- file_path = os.path.join(
- os.path.abspath(os.path.dirname(__file__)),
- "mockfile.txt",
- )
- self.browser.attach_file("file", file_path)
- self.browser.find_by_name("upload").click()
-
- html = self.browser.html
- assert "text/plain" in html
- with open(file_path) as f:
- assert f.read() in html
-
- def test_forward_to_none_page(self):
- """lxml-based drivers should not fail when trying to forward to none"""
- browser = self.get_new_browser()
- browser.visit(EXAMPLE_APP)
- browser.forward()
- assert EXAMPLE_APP == browser.url
- browser.quit()
-
- def test_can_clear_password_field_content(self):
- """lxml-based drivers should not be able to clear"""
- with pytest.raises(NotImplementedError):
- self.browser.find_by_name("password").first.clear()
-
- def test_can_clear_tel_field_content(self):
- """lxml-based drivers should not be able to clear"""
- with pytest.raises(NotImplementedError):
- self.browser.find_by_name("telephone").first.clear()
-
- def test_can_clear_text_field_content(self):
- """lxml-based drivers should not be able to clear"""
- with pytest.raises(NotImplementedError):
- self.browser.find_by_name("query").first.clear()
-
- def test_can_clear_textarea_content(self):
- """lxml-based drivers should not be able to clear"""
- with pytest.raises(NotImplementedError):
- self.browser.find_by_name("description").first.clear()
-
- def test_can_clear_search_content(self):
- """lxml-based drivers should not be able to clear"""
- with pytest.raises(NotImplementedError):
- self.browser.find_by_name("search_keyword").first.clear()
-
- def test_can_clear_url_content(self):
- """lxml-based drivers should not be able to clear"""
- with pytest.raises(NotImplementedError):
- self.browser.find_by_name("url_input").first.clear()
-
- def test_simple_type(self):
- """
- lxml-based drivers won't support type method
- because it doesn't interact with JavaScript
- """
- with pytest.raises(NotImplementedError):
- self.browser.find_by_name("query").type("with type method")
-
- def test_simple_type_on_element(self):
- """
- lxml-based drivers won't support type method
- because it doesn't interact with JavaScript
- """
- with pytest.raises(NotImplementedError):
- self.browser.find_by_name("query").type("with type method")
-
- def test_slowly_typing(self):
- """
- lxml-based drivers won't support type method
- because it doesn't interact with JavaScript
- """
- with pytest.raises(NotImplementedError):
- self.browser.find_by_name("query").type("with type method", slowly=True)
-
- def test_slowly_typing_on_element(self):
- """
- lxml-based drivers won't support type method
- on element because it doesn't interac with JavaScript
- """
- with pytest.raises(NotImplementedError):
- query = self.browser.find_by_name("query")
- query.type("with type method", slowly=True)
-
- def test_cant_mouseover(self):
- """lxml-based drivers should not be able to put the mouse over the element"""
- with pytest.raises(NotImplementedError):
- self.browser.find_by_css("#visible").mouse_over()
-
- def test_cant_mouseout(self):
- """lxml-based drivers should not be able to mouse out of an element"""
- with pytest.raises(NotImplementedError):
- self.browser.find_by_css("#visible").mouse_out()
-
- def test_finding_all_links_by_non_ascii_text(self):
- """lxml-based drivers should find links by non ascii text"""
- non_ascii_encodings = {
- "pangram_pl": "Jeżu klątw, spłódź Finom część gry hańb!",
- "pangram_ja": "天 地 星 空",
- "pangram_ru": "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!", # NOQA RUF001
- "pangram_eo": "Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj.",
- }
- for key, text in non_ascii_encodings.items():
- link = self.browser.links.find_by_text(text)
- assert key == link["id"]
-
- def test_links_with_nested_tags_xpath(self):
- links = self.browser.find_by_xpath('//a/span[text()="first bar"]/..')
- assert len(links) == 1, 'Found more than one link with a span with text "BAR ONE". %s' % [
- item.outer_html for item in links
- ]
diff --git a/tests/status_code.py b/tests/status_code.py
deleted file mode 100644
index 814835253..000000000
--- a/tests/status_code.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# Copyright 2012 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 .fake_webapp import EXAMPLE_APP
-
-
-class StatusCodeTest:
- def test_should_visit_index_of_example_app_and_get_200_status_code(self):
- self.browser.visit(EXAMPLE_APP)
- assert 200 == self.browser.status_code
- assert "200 - OK" == str(self.browser.status_code)
-
- def test_should_visit_error_of_example_app_and_not_get_200_status_code(self):
- self.browser.visit(EXAMPLE_APP + "error.html")
- assert 200 != self.browser.status_code
- assert "404 - Not Found" == str(self.browser.status_code)
diff --git a/tests/test_all_drivers/test_attributes.py b/tests/test_all_drivers/test_attributes.py
new file mode 100644
index 000000000..0f55c40a4
--- /dev/null
+++ b/tests/test_all_drivers/test_attributes.py
@@ -0,0 +1,58 @@
+# Copyright 2012 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.
+
+
+def test_with_statement(browser):
+ """When I use a browser as a context manager
+ Then the context manager's target is the browser object
+ """
+ with browser as b:
+ assert b is not None
+
+
+def test_should_have_html(browser, app_url):
+ browser.visit(app_url)
+ html = browser.html
+ assert "Example Title" in html
+ assert '' in html
+
+
+def test_should_have_url(browser, app_url):
+ "should have access to the url"
+ browser.visit(app_url)
+ assert app_url == browser.url
+
+
+def test_accessing_attributes_of_links(browser, app_url):
+ "should allow link's attributes retrieval"
+ browser.visit(app_url)
+ foo = browser.links.find_by_text("FOO")
+ assert "http://localhost:5000/foo" == foo["href"]
+
+
+def test_accessing_attributes_of_inputs(browser, app_url):
+ "should allow input's attributes retrieval"
+ browser.visit(app_url)
+ button = browser.find_by_css('input[name="send"]')
+ assert "send" == button["name"]
+
+
+def test_accessing_attributes_of_simple_elements(browser, app_url):
+ "should allow simple element's attributes retrieval"
+ browser.visit(app_url)
+ header = browser.find_by_css("h1")
+ assert "firstheader" == header["id"]
+
+
+def test_links_should_have_value_attribute(browser, app_url):
+ browser.visit(app_url)
+ foo = browser.links.find_by_href("http://localhost:5000/foo")
+ assert "FOO" == foo.value
+
+
+def test_should_receive_browser_on_parent(browser, app_url):
+ 'element should contains the browser on "parent" attribute'
+ browser.visit(app_url)
+ element = browser.find_by_id("firstheader")
+ assert browser == element.parent
diff --git a/tests/test_all_drivers/test_click_elements.py b/tests/test_all_drivers/test_click_elements.py
new file mode 100644
index 000000000..8399fe848
--- /dev/null
+++ b/tests/test_all_drivers/test_click_elements.py
@@ -0,0 +1,33 @@
+# Copyright 2012 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.
+import os
+
+import pytest
+
+
+skip_if_safari = pytest.mark.skipif(
+ os.getenv("SAFARI"),
+ reason="Test not compatible with safari",
+)
+
+
+@skip_if_safari
+def test_click_links(browser, app_url):
+ browser.visit(app_url)
+ browser.links.find_by_text("FOO").click()
+ assert "BAR!" in browser.html
+
+
+@skip_if_safari
+def test_click_element_by_css_selector(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_css('a[href="http://localhost:5000/foo"]').click()
+ assert "BAR!" in browser.html
+
+
+@skip_if_safari
+def test_click_input_by_css_selector(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_css('input[name="send"]').click()
+ assert "My name is: Master Splinter" in browser.html
diff --git a/tests/test_all_drivers/test_cookies.py b/tests/test_all_drivers/test_cookies.py
new file mode 100644
index 000000000..5dd47ee17
--- /dev/null
+++ b/tests/test_all_drivers/test_cookies.py
@@ -0,0 +1,92 @@
+# Copyright 2012 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.
+def test_create_and_access_a_cookie(browser, app_url):
+ """Should be able to create and access a cookie"""
+ browser.visit(app_url)
+
+ browser.cookies.add({"sha": "zam"})
+
+ assert "zam" == browser.cookies["sha"]
+
+
+def test_create_many_cookies_at_once_as_dict(browser, app_url):
+ """Should be able to create many cookies at once as dict"""
+ browser.visit(app_url)
+
+ cookies = {"sha": "zam", "foo": "bar"}
+ browser.cookies.add(cookies)
+
+ assert "zam" == browser.cookies["sha"]
+ assert "bar" == browser.cookies["foo"]
+
+
+def test_create_some_cookies_and_delete_them_all(browser, app_url):
+ """Should be able to delete all cookies"""
+ browser.visit(app_url)
+
+ browser.cookies.add({"whatever": "and ever"})
+ browser.cookies.add({"anothercookie": "im bored"})
+ browser.cookies.delete_all()
+
+ assert {} == browser.cookies
+
+
+def test_create_and_delete_a_cookie(browser, app_url):
+ """Should be able to create and destroy a cookie"""
+ browser.visit(app_url)
+
+ browser.cookies.delete_all()
+ browser.cookies.add({"cookie": "with milk"})
+ browser.cookies.delete("cookie")
+
+ assert {} == browser.cookies
+
+
+def test_create_and_delete_many_cookies(browser, app_url):
+ """Should be able to create and destroy many cookies"""
+ browser.visit(app_url)
+
+ browser.cookies.delete_all()
+ browser.cookies.add({"acookie": "cooked"})
+ browser.cookies.add({"anothercookie": "uncooked"})
+ browser.cookies.add({"notacookie": "halfcooked"})
+ browser.cookies.delete("acookie", "notacookie")
+
+ assert "uncooked" == browser.cookies["anothercookie"]
+
+
+def test_try_to_destroy_an_absent_cookie_and_nothing_happens(browser, app_url):
+ browser.visit(app_url)
+
+ browser.cookies.delete_all()
+ browser.cookies.add({"foo": "bar"})
+ browser.cookies.delete("mwahahahaha")
+
+ assert {"foo": "bar"} == browser.cookies
+
+
+def test_create_and_get_all_cookies(browser, app_url):
+ """Should be able to create some cookies and retrieve them all"""
+ browser.visit(app_url)
+
+ browser.cookies.delete_all()
+ browser.cookies.add({"taco": "shrimp"})
+ browser.cookies.add({"lavar": "burton"})
+
+ assert 2 == len(browser.cookies.all())
+
+ browser.cookies.delete_all()
+
+ assert {} == browser.cookies.all()
+
+
+def test_create_and_use_contains(browser, app_url):
+ """Should be able to create many cookies at once as dict"""
+ browser.visit(app_url)
+
+ cookies = {"sha": "zam"}
+ browser.cookies.add(cookies)
+
+ assert "sha" in browser.cookies
+ assert "foo" not in browser.cookies
diff --git a/tests/test_all_drivers/test_element.py b/tests/test_all_drivers/test_element.py
new file mode 100644
index 000000000..a666d9f83
--- /dev/null
+++ b/tests/test_all_drivers/test_element.py
@@ -0,0 +1,39 @@
+# Copyright 2012 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.
+def test_element_has_class_when_element_has_the_class_as_first_class(browser, app_url):
+ browser.visit(app_url)
+ assert browser.find_by_css(".has-class-first").has_class("has-class-first")
+
+
+def test_element_has_class_when_element_has_the_class_as_middle_class(browser, app_url):
+ browser.visit(app_url)
+ assert browser.find_by_css(".has-class-middle").has_class("has-class-middle")
+
+
+def test_element_has_class_when_element_has_the_class_as_end_class(browser, app_url):
+ browser.visit(app_url)
+ assert browser.find_by_css(".has-class-end").has_class("has-class-end")
+
+
+def test_element_has_class_when_element_doesnt_have_the_class(browser, app_url):
+ browser.visit(app_url)
+ assert not browser.find_by_css(".has-class-first").has_class("has-class")
+
+
+def test_element_outer_html(browser, app_url):
+ browser.visit(app_url)
+ assert browser.find_by_id("html-property").outer_html == (
+ ''
+ 'inner
inner text
html test
'
+ )
+
+
+def test_element_html_with_breakline(browser, app_url):
+ browser.visit(app_url)
+ assert browser.find_by_id("html-property-with-breakline").html == "\\n some text here\\n"
+
+
+def test_element_html(browser, app_url):
+ browser.visit(app_url)
+ assert browser.find_by_id("html-property").html == 'inner inner text
html test'
diff --git a/tests/test_all_drivers/test_find_elements.py b/tests/test_all_drivers/test_find_elements.py
new file mode 100644
index 000000000..e67d06eff
--- /dev/null
+++ b/tests/test_all_drivers/test_find_elements.py
@@ -0,0 +1,333 @@
+# Copyright 2012 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 splinter.driver import ElementAPI
+from splinter.element_list import ElementList
+
+
+def test_finding_by_css(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_css("h1").value
+ assert "Example Header" == value
+
+
+def test_finding_by_xpath(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_xpath("//h1").value
+ assert "Example Header" == value
+
+
+def test_finding_by_tag(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_tag("h1").value
+ assert "Example Header" == value
+
+
+def test_finding_by_value(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_value("M").value
+ element = browser.find_by_id("gender-m")
+ assert element.value == value
+
+
+def test_finding_by_value_in_btn_elements(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_value("some value").value
+ btn = browser.find_by_id("button-value")
+ assert btn.value == value
+
+
+def test_finding_by_text(browser, app_url):
+ browser.visit(app_url)
+ element = browser.find_by_text("Complex")
+ assert element.value == "Complex"
+
+
+def test_finding_by_text_with_quotation_marks(browser, app_url):
+ browser.visit(app_url)
+ element = browser.find_by_text('Quotation " marks')
+ assert element.value == 'Quotation " marks'
+
+
+def test_finding_by_id(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_id("firstheader").value
+ assert "Example Header" == value
+
+
+def test_finding_by_name(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_name("query").value
+ assert "default value" == value
+
+
+def test_finding_all_elements_by_css(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_css("h1")[0].value
+ assert "Example Header" == value
+
+
+def test_finding_all_elements_by_xpath(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_xpath("//h1")[0].value
+ assert "Example Header" == value
+
+
+def test_finding_all_elements_by_tag(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_tag("h1")[0].value
+ assert "Example Header" == value
+
+
+def test_finding_all_elements_by_id(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_id("firstheader").value
+ assert "Example Header" == value
+
+
+def test_finding_all_elements_by_name(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_name("query").value
+ assert "default value" == value
+
+
+def test_finding_all_links_by_text(browser, app_url):
+ browser.visit(app_url)
+ link = browser.links.find_by_text("Link for Example.com")[0]
+ assert "http://example.com/" == link["href"]
+
+
+def test_finding_all_links_by_href(browser, app_url):
+ browser.visit(app_url)
+ link = browser.links.find_by_href("http://example.com/")[0]
+ assert "http://example.com/" == link["href"]
+
+
+def test_finding_all_links_by_partial_href(browser, app_url):
+ browser.visit(app_url)
+ link = browser.links.find_by_partial_href("example.c")[0]
+ assert "http://example.com/" == link["href"]
+
+
+def test_finding_all_links_by_partial_text(browser, app_url):
+ browser.visit(app_url)
+ link = browser.links.find_by_partial_text("FOO")[0]
+ assert "http://localhost:5000/foo" == link["href"]
+
+
+def test_find_links_by_partial_text_nested_elements(browser, app_url):
+ """
+ When text is split in multiple child elements of a parent link element
+ Then the parent link element is found
+ """
+ browser.visit(app_url)
+
+ expected = "http://localhost:5000/nested"
+
+ link = browser.links.find_by_partial_text("Nested text")[0]
+ assert expected == link["href"]
+
+ link = browser.links.find_by_partial_text("in a link")[0]
+ assert expected == link["href"]
+
+ link = browser.links.find_by_partial_text("Nested text in")[0]
+ assert expected == link["href"]
+
+ link = browser.links.find_by_partial_text("text in a link")[0]
+ assert expected == link["href"]
+
+ link = browser.links.find_by_partial_text("Nested text in a link")[0]
+ assert expected == link["href"]
+
+
+def test_finding_last_element_by_css(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_css("h1").last.value
+ assert "Example Last Header" == value
+
+
+def test_finding_last_element_by_xpath(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_xpath("//h1").last.value
+ assert "Example Last Header" == value
+
+
+def test_finding_last_element_by_tag(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_tag("h1").last.value
+ assert "Example Last Header" == value
+
+
+def test_finding_last_element_by_id(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_id("firstheader").last.value
+ assert "Example Header" == value
+
+
+def test_last_element_is_same_than_first_element_in_find_by_id(browser, app_url):
+ browser.visit(app_url)
+ # a html page have contain one element by id
+ first = browser.find_by_id("firstheader").value
+ last = browser.find_by_id("firstheader").last.value
+ assert first == last
+
+
+def test_finding_last_element_by_name(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_name("input1").last.value
+ assert "default last value" == value
+
+
+def test_finding_last_link_by_text(browser, app_url):
+ browser.visit(app_url)
+ link = browser.links.find_by_text("Link for Example.com").last
+ assert "http://example.com/last" == link["href"]
+
+
+def test_finding_last_link_by_href(browser, app_url):
+ browser.visit(app_url)
+ link = browser.links.find_by_href("http://example.com/").last
+ assert "Link for last Example.com" == link.text
+
+
+def test_finding_link_by_partial_href(browser, app_url):
+ browser.visit(app_url)
+ link = browser.links.find_by_partial_href("example.c").last
+ assert "Link for last Example.com" == link.text
+
+
+def test_finding_last_link_by_partial_text(browser, app_url):
+ browser.visit(app_url)
+ link = browser.links.find_by_partial_text("FOO").last
+ assert "A wordier (and last) link to FOO" == link.text
+
+
+def test_finding_element_by_css_using_slice(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_css("h1")[-1].value
+ assert "Example Last Header" == value
+
+
+def test_finding_element_by_xpath_using_slice(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_xpath("//h1")[-1].value
+ assert "Example Last Header" == value
+
+
+def test_finding_element_by_tag_using_slice(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_tag("h1")[-1].value
+ assert "Example Last Header" == value
+
+
+def test_finding_element_by_id_using_slice(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_id("firstheader")[-1].value
+ assert "Example Header" == value
+
+
+def test_all_elements_is_same_than_first_element_in_find_by_id(browser, app_url):
+ browser.visit(app_url)
+ # a html page have contain one element by id
+ first = browser.find_by_id("firstheader").value
+ some = browser.find_by_id("firstheader")[-1].value
+ assert first == some
+
+
+def test_finding_element_by_name_using_slice(browser, app_url):
+ browser.visit(app_url)
+ value = browser.find_by_name("input1")[-1].value
+ assert "default last value" == value
+
+
+def test_finding_link_by_text_using_slice(browser, app_url):
+ browser.visit(app_url)
+ link = browser.links.find_by_text("Link for Example.com")[-1]
+ assert "http://example.com/last" == link["href"]
+
+
+def test_finding_link_by_href_using_slice(browser, app_url):
+ "should find link by href using slice"
+ browser.visit(app_url)
+ link = browser.links.find_by_href("http://example.com/")[-1]
+ assert "Link for last Example.com" == link.text
+
+
+def test_finding_links_by_text(browser, app_url):
+ "should find links by text"
+ browser.visit(app_url)
+ link = browser.links.find_by_text("Link for Example.com")
+ assert "http://example.com/" == link["href"]
+
+
+def test_finding_links_by_href(browser, app_url):
+ "should find links by href"
+ browser.visit(app_url)
+ link = browser.links.find_by_href("http://example.com/")
+ assert "http://example.com/" == link["href"]
+
+
+def test_find_by_css_in_element_context(browser, app_url):
+ "should find elements by css in element context and should return splinter driver element"
+ browser.visit(app_url)
+ elements = browser.find_by_css("#inside")
+ decendent = elements[0].find_by_css("h2")
+ assert decendent.text.strip() == "inside"
+ assert isinstance(decendent, ElementList)
+ assert isinstance(decendent[0], ElementAPI)
+
+
+def test_find_by_xpath_in_element_context(browser, app_url):
+ "should find elements by xpath in element context"
+ browser.visit(app_url)
+ elements = browser.find_by_css("#inside")
+ decendent = elements[0].find_by_xpath("//h2")
+ assert decendent.text.strip() == "inside"
+ assert isinstance(decendent, ElementList)
+ assert isinstance(decendent.first, ElementAPI)
+
+
+def test_find_by_name_in_element_context(browser, app_url):
+ browser.visit(app_url)
+ elements = browser.find_by_css("#inside")
+ decendent = elements[0].find_by_name("crazy-upload")
+ assert len(decendent) == 1
+ assert isinstance(decendent, ElementList)
+ assert isinstance(decendent.first, ElementAPI)
+
+
+def test_find_by_tag_in_element_context(browser, app_url):
+ browser.visit(app_url)
+ elements = browser.find_by_css("#inside")
+ decendent = elements[0].find_by_tag("input")
+ assert len(decendent) == 1
+ assert isinstance(decendent, ElementList)
+ assert isinstance(decendent.first, ElementAPI)
+
+
+def test_find_by_id_in_element_context(browser, app_url):
+ browser.visit(app_url)
+ elements = browser.find_by_css("#inside")
+ decendent = elements[0].find_by_id("visible")
+ assert len(decendent) == 1
+ assert isinstance(decendent, ElementList)
+ assert isinstance(decendent.first, ElementAPI)
+
+
+def test_find_by_value_in_element_context(browser, app_url):
+ browser.visit(app_url)
+ elements = browser.find_by_css("#inside")
+ decendent = elements[0].find_by_value("crazy diamond")
+ assert len(decendent) == 1
+ assert isinstance(decendent, ElementList)
+ assert isinstance(decendent.first, ElementAPI)
+
+
+def test_finding_by_text_in_element_context(browser, app_url):
+ browser.visit(app_url)
+ inside = browser.find_by_id("inside")
+ element = inside.find_by_text("Complex")
+
+ assert len(element) == 1
+ assert element["class"] == "inside"
+ assert element.value == "Complex"
diff --git a/tests/test_all_drivers/test_form_elements.py b/tests/test_all_drivers/test_form_elements.py
new file mode 100644
index 000000000..3c0981270
--- /dev/null
+++ b/tests/test_all_drivers/test_form_elements.py
@@ -0,0 +1,321 @@
+# Copyright 2012 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.
+import os
+import re
+import time
+
+import pytest
+
+from splinter.exceptions import ElementDoesNotExist
+
+
+skip_if_zope = pytest.mark.skipif(
+ os.getenv("ZOPE"),
+ reason="Test not compatible with zope.testbrowser",
+)
+
+xfail_if_safari = pytest.mark.xfail(
+ os.getenv("SAFARI"),
+ reason="Safari issues need to be investigated.",
+)
+
+
+def test_fill(browser, app_url):
+ browser.visit(app_url)
+ my_input = "LT-CS-01/2018"
+ elem = browser.find_by_name("query")
+ elem.fill(my_input)
+ assert my_input == elem.value
+
+
+def test_fill_element(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_name("q").fill("new query")
+ time.sleep(1)
+ value = browser.find_by_name("q").value
+ assert "new query" == value
+
+
+@skip_if_zope
+@xfail_if_safari
+def test_clicking_submit_input_doesnt_post_input_value_if_name_not_present(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_css("input.submit-input-no-name").click()
+ elem = browser.find_by_xpath("/descendant-or-self::*")
+ assert elem.text.strip() == ""
+
+
+@skip_if_zope
+@xfail_if_safari
+def test_clicking_submit_input_posts_empty_value_if_value_not_present(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_css('input[name="submit-input-no-value"]').click()
+ body_text = browser.find_by_xpath("/descendant-or-self::*").text.strip()
+ assert re.match(r"^submit-input-no-value:(?:| Submit| Submit Query)$", body_text), repr(body_text)
+
+
+@skip_if_zope
+@xfail_if_safari
+def test_clicking_submit_input_doesnt_post_input_value_if_empty(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_css("input.submit-input-empty").click()
+ elem = browser.find_by_xpath("/descendant-or-self::*")
+ assert elem.text.strip() == ""
+
+
+@xfail_if_safari
+def test_clicking_submit_input_posts_input_value_if_value_present(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_css('input[name="submit-input"]').click()
+ elem = browser.find_by_xpath("/descendant-or-self::*")
+ assert elem.text == "submit-input: submit-input-value"
+
+
+@skip_if_zope
+@xfail_if_safari
+def test_clicking_submit_button_doesnt_post_button_value_if_name_not_present(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_css("button.submit-button-no-name").click()
+ elem = browser.find_by_xpath("/descendant-or-self::*")
+ assert elem.text == ""
+
+
+@skip_if_zope
+@xfail_if_safari
+def test_clicking_submit_button_posts_empty_value_if_value_not_present(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_css('button[name="submit-button-no-value"]').click()
+ assert browser.find_by_xpath("/descendant-or-self::*").text.strip() == "submit-button-no-value:"
+
+
+@skip_if_zope
+@xfail_if_safari
+def test_clicking_submit_button_doesnt_post_button_value_if_empty(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_css("button.submit-button-empty").click()
+ assert browser.find_by_xpath("/descendant-or-self::*").text.strip() == ""
+
+
+@skip_if_zope
+@xfail_if_safari
+def test_clicking_submit_button_posts_button_value_if_value_present(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_css('button[name="submit-button"]').click()
+
+ assert browser.find_by_xpath("/descendant-or-self::*").text == "submit-button: submit-button-value"
+
+
+@xfail_if_safari
+def test_submiting_a_form_and_verifying_page_content(browser, app_url):
+ browser.visit(app_url)
+ browser.find_by_name("query").fill("my name")
+ browser.find_by_name("send").click()
+ assert "My name is: Master Splinter" in browser.html
+
+
+def test_can_choose_a_radio_button(browser, app_url):
+ "should provide a way to choose a radio button"
+ browser.visit(app_url)
+ assert not browser.find_by_id("gender-m").checked
+ browser.choose("gender", "M")
+ assert browser.find_by_id("gender-m").checked
+
+
+def test_can_find_textarea_by_tag(browser, app_url):
+ "should provide a way to find a textarea by tag_name"
+ browser.visit(app_url)
+ tag = browser.find_by_tag("textarea").first
+ assert "" == tag.value
+
+
+def test_can_find_input_without_type(browser, app_url):
+ "should recognize an input element that doesn't have a `type` attribute"
+ browser.visit(app_url)
+ tag = browser.find_by_css('[name="typeless"]').first
+ assert "default value" == tag.value
+
+
+def test_can_find_button(browser, app_url):
+ "should recognize a button"
+ browser.visit(app_url)
+ tag = browser.find_by_css(".just-a-button").first
+ assert hasattr(tag, "click")
+
+
+def test_can_find_option_by_value(browser, app_url):
+ "should provide a way to find select option by value"
+ browser.visit(app_url)
+ assert "Rio de Janeiro" == browser.find_option_by_value("rj").text
+
+
+def test_can_get_value_attribute_for_a_option(browser, app_url):
+ "should option have a value attribute"
+ browser.visit(app_url)
+ assert "rj" == browser.find_option_by_value("rj")["value"]
+
+
+def test_can_find_option_by_text(browser, app_url):
+ "should provide a way to find select option by text"
+ browser.visit(app_url)
+ assert "rj" == browser.find_option_by_text("Rio de Janeiro").value
+
+
+def test_can_select_a_option(browser, app_url):
+ "should provide a way to select a option"
+ browser.visit(app_url)
+ assert not browser.find_option_by_value("rj").selected
+ browser.select("uf", "rj")
+ assert browser.find_option_by_value("rj").selected
+
+
+def test_can_select_an_option_in_an_optgroup(browser, app_url):
+ "should provide a way to select an option that is in an optgroup"
+ browser.visit(app_url)
+ assert browser.find_by_name("food").value == "apples"
+ browser.select("food", "grapes")
+ assert browser.find_by_name("food").value == "grapes"
+
+
+def test_can_select_a_option_via_element(browser, app_url):
+ "should provide a way to select a option via element"
+ browser.visit(app_url)
+ assert not browser.find_option_by_value("rj").selected
+ browser.find_by_name("uf").select("rj")
+ assert browser.find_option_by_value("rj").selected
+
+
+def test_can_check_a_checkbox(browser, app_url):
+ """should provide a way to check a radio checkbox"""
+ browser.visit(app_url)
+ elem = browser.find_by_name("some-check")
+ assert not elem.checked
+ elem.check()
+ assert elem.checked
+
+
+def test_check_keeps_checked_if_called_multiple_times(browser, app_url):
+ """should keep a checkbox checked if check() is called multiple times"""
+ browser.visit(app_url)
+ elem = browser.find_by_name("some-check")
+ assert not elem.checked
+ elem.check()
+ elem.check()
+ assert elem.checked
+
+
+def test_can_uncheck_a_checkbox(browser, app_url):
+ """should provide a way to uncheck a radio checkbox"""
+ browser.visit(app_url)
+ elem = browser.find_by_name("checked-checkbox")
+ assert elem.checked
+ elem.uncheck()
+ assert not elem.checked
+
+
+def test_uncheck_should_keep_unchecked_if_called_multiple_times(browser, app_url):
+ """should keep a checkbox unchecked if uncheck() is called multiple times"""
+ browser.visit(app_url)
+ elem = browser.find_by_name("checked-checkbox")
+ assert elem.checked
+ elem.uncheck()
+ elem.uncheck()
+ assert not elem.checked
+
+
+def test_can_fill_text_field_in_form(browser, app_url):
+ "should provide a away to change field value"
+ browser.visit(app_url)
+ browser.fill_form({"query": "new query"})
+ value = browser.find_by_name("query").value
+ assert "new query" == value
+
+
+def test_can_fill_password_field_in_form(browser, app_url):
+ "should provide a way to change password value"
+ browser.visit(app_url)
+ new_password = "new password"
+ browser.fill_form({"password": new_password})
+ value = browser.find_by_name("password").value
+ assert new_password == value
+
+
+@xfail_if_safari
+def test_can_fill_more_than_one_field_in_form(browser, app_url):
+ "should provide a away to change field value"
+ browser.visit(app_url)
+ browser.find_by_name("query").fill("my name")
+ assert not browser.find_by_id("gender-m").checked
+ assert not browser.find_option_by_value("rj").selected
+ assert not browser.find_by_name("some-check").checked
+ assert browser.find_by_name("checked-checkbox").checked
+ browser.fill_form(
+ {
+ "query": "another new query",
+ "description": "Just another description value in the textarea",
+ "gender": "M",
+ "uf": "rj",
+ "some-check": True,
+ "checked-checkbox": False,
+ },
+ )
+ query_value = browser.find_by_name("query").value
+ assert "another new query" == query_value
+ desc_value = browser.find_by_name("description").value
+ assert "Just another description value in the textarea" == desc_value
+ assert browser.find_by_id("gender-m").checked
+ assert browser.find_option_by_value("rj").selected
+ assert browser.find_by_name("some-check").checked
+ assert not browser.find_by_name("checked-checkbox").checked
+
+
+def test_can_fill_tel_text_field(browser, app_url):
+ "should provide a way to change a tel field value"
+ browser.visit(app_url)
+ new_telephone = "555-0042"
+ browser.fill_form({"telephone": new_telephone})
+ value = browser.find_by_name("telephone").value
+ assert new_telephone == value
+
+
+def test_can_fill_unknown_text_field(browser, app_url):
+ "should provide a way to change a unknown text field type that isn't specifically defined"
+ browser.visit(app_url)
+ new_search_keyword = "foobar"
+ browser.fill_form({"search_keyword": new_search_keyword})
+ value = browser.find_by_name("search_keyword").value
+ assert new_search_keyword == value
+
+
+def test_can_fill_form_by_id(browser, app_url):
+ "should be able to fill a form by its id"
+ browser.visit(app_url)
+ browser.fill_form(
+ {"firstname": "John", "lastname": "Doe"},
+ form_id="login",
+ )
+ value = browser.find_by_name("firstname").value
+ assert "John" == value
+
+
+@skip_if_zope
+def test_fill_form_missing_values(browser, app_url):
+ """Missing values should raise an error."""
+ browser.visit(app_url)
+ with pytest.raises(ElementDoesNotExist) as e:
+ browser.fill_form(
+ {"query": "new query", "missing_form": "doesn't exist"},
+ )
+
+ assert "missing_form" in str(e.value)
+
+
+def test_fill_form_missing_values_ignore_missing(browser, app_url):
+ """Missing values are ignores when ignore_missing is True."""
+ browser.visit(app_url)
+ browser.fill_form(
+ {"query": "new query", "missing_form": "doesn't exist"},
+ ignore_missing=True,
+ )
+ value = browser.find_by_name("query").value
+ assert "new query" == value
diff --git a/tests/test_all_drivers/test_is_text_present.py b/tests/test_all_drivers/test_is_text_present.py
new file mode 100644
index 000000000..35a519a6a
--- /dev/null
+++ b/tests/test_all_drivers/test_is_text_present.py
@@ -0,0 +1,51 @@
+# Copyright 2012 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.
+def test_is_text_present(browser, app_url):
+ "should verify if text is present"
+ browser.visit(app_url)
+ assert browser.is_text_present("Example Header")
+
+
+def test_is_text_present_and_should_return_false(browser, app_url):
+ "should verify if text is present and return false"
+ browser.visit(app_url)
+ assert not browser.is_text_present("Text that not exist")
+
+
+def test_is_text_present_and_should_wait_time(browser, app_url):
+ "should verify if text is present and wait for five seconds"
+ browser.visit(app_url)
+ browser.links.find_by_text("FOO").click()
+ assert browser.is_text_present("BAR!", wait_time=20)
+
+
+def test_is_text_not_present(browser, app_url):
+ "should verify if text is not present"
+ browser.visit(app_url)
+ assert browser.is_text_not_present("Text that not exist")
+
+
+def test_is_text_not_present_and_should_return_false(browser, app_url):
+ "should verify if text is not present and return false"
+ browser.visit(app_url)
+ assert not browser.is_text_not_present("Example Header")
+
+
+def test_is_text_not_present_and_should_wait_time(browser, app_url):
+ "should verify if text is not present and wait for five seconds"
+ browser.visit(app_url)
+ browser.links.find_by_text("FOO").click()
+ assert browser.is_text_not_present("another text", wait_time=20)
+
+
+def test_is_text_present_no_body(browser, app_url):
+ "should work properly (return false) even if there's no body"
+ browser.visit(app_url + "no-body")
+ assert not browser.is_text_present("No such text")
+
+
+def test_is_text_not_present_no_body(browser, app_url):
+ "returns true if there's no body"
+ browser.visit(app_url + "no-body")
+ assert browser.is_text_not_present("No such text")
diff --git a/tests/test_all_drivers/test_navigation.py b/tests/test_all_drivers/test_navigation.py
new file mode 100644
index 000000000..39762bc2e
--- /dev/null
+++ b/tests/test_all_drivers/test_navigation.py
@@ -0,0 +1,42 @@
+def test_can_open_page(browser, app_url):
+ """should be able to visit, get title and quit"""
+ browser.visit(app_url)
+ assert "Example Title" == browser.title
+
+
+def test_should_reload_a_page(browser, app_url):
+ browser.visit(app_url)
+ browser.reload()
+ assert "Example Title" == browser.title
+
+
+def test_can_back_on_history(browser, app_url):
+ """should be able to back on history"""
+ browser.visit(app_url)
+ browser.visit(f"{app_url}iframe")
+ browser.back()
+ assert app_url == browser.url
+
+
+def test_can_forward_on_history(request, browser, app_url):
+ """User can forward history"""
+ request.addfinalizer(browser.quit)
+
+ next_url = f"{app_url}iframe"
+
+ browser.visit(app_url)
+ browser.visit(next_url)
+ browser.back()
+
+ browser.forward()
+ assert next_url == browser.url
+
+
+def test_redirection(browser, app_url):
+ """
+ when visiting /redirected, browser should be redirected to /redirected-location?come=get&some=true
+ browser.url should be updated
+ """
+ browser.visit(f"{app_url}redirected")
+ assert "I just been redirected to this location." in browser.html
+ assert "redirect-location?come=get&some=true" in browser.url
diff --git a/tests/test_all_lxml_drivers/test_form_elements_lxml.py b/tests/test_all_lxml_drivers/test_form_elements_lxml.py
new file mode 100644
index 000000000..f4b04000f
--- /dev/null
+++ b/tests/test_all_lxml_drivers/test_form_elements_lxml.py
@@ -0,0 +1,43 @@
+import pytest
+
+
+def test_can_clear_text_field_content(browser, app_url):
+ """lxml-based drivers should not be able to clear"""
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_name("query").first.clear()
+
+
+def test_can_clear_password_field_content(browser, app_url):
+ """lxml-based drivers should not be able to clear"""
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_name("password").first.clear()
+
+
+def test_can_clear_tel_field_content(browser, app_url):
+ """lxml-based drivers should not be able to clear"""
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_name("telephone").first.clear()
+
+
+def test_can_clear_textarea_content(browser, app_url):
+ """lxml-based drivers should not be able to clear"""
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_name("description").first.clear()
+
+
+def test_can_clear_search_content(browser, app_url):
+ """lxml-based drivers should not be able to clear"""
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_name("search_keyword").first.clear()
+
+
+def test_can_clear_url_content(browser, app_url):
+ """lxml-based drivers should not be able to clear"""
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_name("url_input").first.clear()
diff --git a/tests/test_all_lxml_drivers/test_is_element_present_nojs.py b/tests/test_all_lxml_drivers/test_is_element_present_nojs.py
new file mode 100644
index 000000000..4bcfff95a
--- /dev/null
+++ b/tests/test_all_lxml_drivers/test_is_element_present_nojs.py
@@ -0,0 +1,233 @@
+# 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.
+def test_is_element_present_by_css(browser, app_url):
+ "should is element present by css verify if element is present"
+ browser.visit(app_url)
+
+ assert browser.is_element_present_by_css("h1")
+
+
+def test_is_element_present_by_css_returns_false_if_element_is_not_present(
+ browser,
+ app_url,
+):
+ "should is element present by css returns False if element is not present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_present_by_css(".async-elementzz")
+
+
+def test_is_element_not_present_by_css(browser, app_url):
+ "should is element not present by css verify if element is not present"
+ browser.visit(app_url)
+
+ assert browser.is_element_not_present_by_css(".async-element")
+
+
+def test_is_element_not_present_by_css_returns_false_if_element_is_present(
+ browser,
+ app_url,
+):
+ "should is element not present by css returns False if element is present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_not_present_by_css("h1")
+
+
+def test_is_element_present_by_xpath(browser, app_url):
+ "should is element present by xpath verify if element is present"
+ browser.visit(app_url)
+
+ assert browser.is_element_present_by_xpath("//h1")
+
+
+def test_is_element_present_by_xpath_returns_false_if_element_is_not_present(
+ browser,
+ app_url,
+):
+ "should is element present by xpath returns false if element is not present"
+ browser.visit(app_url)
+
+ assert browser.is_element_not_present_by_xpath("//h4")
+
+
+def test_is_element_not_present_by_xpath_returns_false_if_element_is_present(
+ browser,
+ app_url,
+):
+ "should is element not present by xpath returns false if element is present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_not_present_by_xpath("//h1")
+
+
+def test_is_element_present_by_tag(browser, app_url):
+ "should is element present by tag verify if element is present"
+ browser.visit(app_url)
+
+ assert browser.is_element_present_by_tag("h1")
+
+
+def test_is_element_present_by_tag_returns_false_if_element_is_not_present(
+ browser,
+ app_url,
+):
+ "should is element present by tag returns false if element is not present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_present_by_tag("h4")
+
+
+def test_is_element_not_present_by_tag(browser, app_url):
+ "should is element not present by tag verify if element is not present"
+ browser.visit(app_url)
+
+ assert browser.is_element_not_present_by_tag("h4")
+
+
+def test_is_element_not_present_by_tag_returns_false_if_element_is_present(
+ browser,
+ app_url,
+):
+ "should is element not present by tag returns false if element is present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_not_present_by_tag("h1")
+
+
+def test_is_element_present_by_text(browser, app_url):
+ "should is element present by text verify if element is present"
+ browser.visit(app_url)
+
+ assert browser.is_element_present_by_text("Complex")
+
+
+def test_is_element_present_by_text_returns_false_if_element_is_not_present(
+ browser,
+ app_url,
+):
+ "should is element present by text verify if element is present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_present_by_text("Not present")
+
+
+def test_is_element_not_present_by_text(browser, app_url):
+ "should is element not present by text verify if element is not present"
+ browser.visit(app_url)
+
+ assert browser.is_element_not_present_by_text("Not present")
+
+
+def test_is_element_not_present_by_text_returns_false_if_element_is_present(
+ browser,
+ app_url,
+):
+ "should is element not present by text returns False if element is present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_not_present_by_text("Complex")
+
+
+def test_is_element_present_by_value(browser, app_url):
+ "should is element present by value verify if element is present"
+ browser.visit(app_url)
+
+ assert browser.is_element_present_by_value("M")
+
+
+def test_is_element_present_by_value_returns_false_if_element_is_not_present(
+ browser,
+ app_url,
+):
+ "should is element present by value returns False if element is not present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_present_by_value("async-header-value")
+
+
+def test_is_element_not_present_by_value(browser, app_url):
+ "should is element not present by value verify if element is not present"
+ browser.visit(app_url)
+
+ assert browser.is_element_not_present_by_value("async-header-value")
+
+
+def test_is_element_not_present_by_value_returns_false_if_element_is_present(
+ browser,
+ app_url,
+):
+ "should is element not present by value returns False if element is present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_not_present_by_value("default value")
+
+
+def test_is_element_present_by_id(browser, app_url):
+ "should is element present by id verify if element is present"
+ browser.visit(app_url)
+
+ assert browser.is_element_present_by_id("firstheader")
+
+
+def test_is_element_present_by_id_returns_false_if_element_is_not_present(
+ browser,
+ app_url,
+):
+ "should is element present by id returns False if element is not present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_present_by_id("async-header")
+
+
+def test_is_element_not_present_by_id(browser, app_url):
+ "should is element not present by id verify if element is not present"
+ browser.visit(app_url)
+
+ assert browser.is_element_not_present_by_id("async-header")
+
+
+def test_is_element_not_present_by_id_returns_false_if_element_is_present(
+ browser,
+ app_url,
+):
+ "should is element not present by id returns False if element is present"
+
+ browser.visit(app_url)
+
+ assert not browser.is_element_not_present_by_id("firstheader")
+
+
+def test_is_element_present_by_name(browser, app_url):
+ "should is element present by name verify if element is present"
+ browser.visit(app_url)
+
+ assert browser.is_element_present_by_name("query")
+
+
+def test_is_element_present_by_name_returns_false_if_element_is_not_present(
+ browser,
+ app_url,
+):
+ "should is element present by name returns false if element is not present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_present_by_name("async-input")
+
+
+def test_is_element_not_present_by_name(browser, app_url):
+ "should is element not present by name verify if element is not present"
+ browser.visit(app_url)
+
+ assert browser.is_element_not_present_by_name("async-input")
+
+
+def test_is_element_not_present_by_name_returns_false_if_element_is_present(
+ browser,
+ app_url,
+):
+ "should is element not present by name returns false if element is present"
+ browser.visit(app_url)
+
+ assert not browser.is_element_not_present_by_name("query")
diff --git a/tests/test_all_lxml_drivers/test_lxml_drivers.py b/tests/test_all_lxml_drivers/test_lxml_drivers.py
new file mode 100644
index 000000000..e27fcf167
--- /dev/null
+++ b/tests/test_all_lxml_drivers/test_lxml_drivers.py
@@ -0,0 +1,78 @@
+import os
+import pathlib
+
+import pytest
+
+
+def test_cant_switch_to_frame(browser, app_url):
+ """lxml-based drivers should not be able to switch to frames"""
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError) as err:
+ browser.get_iframe("frame_123")
+ browser.fail()
+
+ assert f"{browser.driver_name.lower()} doesn't support frames." == err.value.args[0]
+
+
+def test_attach_file(browser, app_url):
+ """should provide a way to change file field value"""
+ browser.visit(app_url)
+
+ file_path = pathlib.Path(
+ os.getcwd(), # NOQA PTH109
+ "tests",
+ "mockfile.txt",
+ )
+
+ browser.attach_file("file", str(file_path))
+ browser.find_by_name("upload").click()
+
+ html = browser.html
+ assert "text/plain" in html
+ with open(file_path) as f:
+ assert f.read() in html
+
+
+def test_forward_to_none_page(request, browser, app_url):
+ """lxml-based drivers should not fail when trying to forward to none"""
+ request.addfinalizer(browser.quit)
+
+ browser.visit(app_url)
+ browser.forward()
+ assert app_url == browser.url
+
+
+def test_cant_mouseover(browser, app_url):
+ """lxml-based drivers should not be able to put the mouse over the element"""
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_css("#visible").mouse_over()
+
+
+def test_cant_mouseout(browser, app_url):
+ """lxml-based drivers should not be able to mouse out of an element"""
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_css("#visible").mouse_out()
+
+
+def test_finding_all_links_by_non_ascii_text(browser, app_url):
+ """lxml-based drivers should find links by non ascii text"""
+ non_ascii_encodings = {
+ "pangram_pl": "Jeżu klątw, spłódź Finom część gry hańb!",
+ "pangram_ja": "天 地 星 空",
+ "pangram_ru": "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!", # NOQA RUF001
+ "pangram_eo": "Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj.",
+ }
+ browser.visit(app_url)
+ for key, text in non_ascii_encodings.items():
+ link = browser.links.find_by_text(text)
+ assert key == link["id"]
+
+
+def test_links_with_nested_tags_xpath(browser, app_url):
+ browser.visit(app_url)
+ links = browser.find_by_xpath('//a/span[text()="first bar"]/..')
+ assert len(links) == 1, 'Found more than one link with a span with text "BAR ONE". %s' % [
+ item.outer_html for item in links
+ ]
diff --git a/tests/test_all_lxml_drivers/test_slowly_type_lxml.py b/tests/test_all_lxml_drivers/test_slowly_type_lxml.py
new file mode 100644
index 000000000..ee8dbbf20
--- /dev/null
+++ b/tests/test_all_lxml_drivers/test_slowly_type_lxml.py
@@ -0,0 +1,42 @@
+import pytest
+
+
+def test_simple_type(browser, app_url):
+ """
+ lxml-based drivers won't support type method
+ because it doesn't interact with JavaScript
+ """
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_name("query").type("with type method")
+
+
+def test_simple_type_on_element(browser, app_url):
+ """
+ lxml-based drivers won't support type method
+ because it doesn't interact with JavaScript
+ """
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_name("query").type("with type method")
+
+
+def test_slowly_typing(browser, app_url):
+ """
+ lxml-based drivers won't support type method
+ because it doesn't interact with JavaScript
+ """
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ browser.find_by_name("query").type("with type method", slowly=True)
+
+
+def test_slowly_typing_on_element(browser, app_url):
+ """
+ lxml-based drivers won't support type method
+ on element because it doesn't interac with JavaScript
+ """
+ browser.visit(app_url)
+ with pytest.raises(NotImplementedError):
+ query = browser.find_by_name("query")
+ query.type("with type method", slowly=True)
diff --git a/tests/test_all_lxml_drivers/test_status_code.py b/tests/test_all_lxml_drivers/test_status_code.py
new file mode 100644
index 000000000..6a6910114
--- /dev/null
+++ b/tests/test_all_lxml_drivers/test_status_code.py
@@ -0,0 +1,18 @@
+# Copyright 2012 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.
+import pytest
+
+
+@pytest.mark.xfail(reason="str() of status_code returns unexpected string.")
+def test_should_visit_index_of_example_app_and_get_200_status_code(browser, app_url):
+ browser.visit(app_url)
+ assert 200 == browser.status_code
+ assert "200 - OK" == str(browser.status_code)
+
+
+@pytest.mark.xfail(reason="str() of status_code returns unexpected string.")
+def test_should_visit_error_of_example_app_and_not_get_200_status_code(browser, app_url):
+ browser.visit(app_url + "error.html")
+ assert 200 != browser.status_code
+ assert "404 - Not Found" == str(browser.status_code)
diff --git a/tests/test_djangoclient.py b/tests/test_djangoclient.py
deleted file mode 100644
index 843e68984..000000000
--- a/tests/test_djangoclient.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# 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.
-import os
-import sys
-import time
-
-import django
-import pytest
-
-from .base import BaseBrowserTests
-from .base import get_browser
-from .fake_webapp import EXAMPLE_APP
-from .lxml_drivers import LxmlDriverTests
-
-
-sys.path.append("tests/fake_django")
-os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
-
-
-django.setup()
-
-
-class TestDjangoClientDriver(LxmlDriverTests, BaseBrowserTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- request.cls.browser = get_browser("django")
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self):
- self.browser.visit(EXAMPLE_APP)
-
- def test_cookies_extra_parameters(self):
- """Cookie can be created with extra parameters."""
- timestamp = int(time.time() + 120)
- self.browser.cookies.add({"sha": "zam"}, expires=timestamp)
- cookie = self.browser._browser.cookies["sha"]
- assert timestamp == cookie["expires"]
-
-
-class TestDjangoClientDriverWithCustomHeaders:
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- custom_headers = {
- "X-Splinter-Customheaders-1": "Hello",
- "X-Splinter-Customheaders-2": "Bye",
- }
- request.cls.browser = get_browser("django", custom_headers=custom_headers)
- request.addfinalizer(request.cls.browser.quit)
-
- def test_create_a_browser_with_custom_headers(self):
- self.browser.visit(EXAMPLE_APP + "headers")
- assert self.browser.is_text_present("X-Splinter-Customheaders-1: Hello")
-
- assert self.browser.is_text_present("X-Splinter-Customheaders-2: Bye")
diff --git a/tests/test_flaskclient.py b/tests/test_flaskclient.py
deleted file mode 100644
index c5ece799c..000000000
--- a/tests/test_flaskclient.py
+++ /dev/null
@@ -1,62 +0,0 @@
-# Copyright 2014 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.
-import time
-
-import pytest
-
-from .base import BaseBrowserTests
-from .base import get_browser
-from .fake_webapp import app
-from .fake_webapp import EXAMPLE_APP
-from .lxml_drivers import LxmlDriverTests
-
-
-class TestFlaskClientDriver(LxmlDriverTests, BaseBrowserTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- request.cls.browser = get_browser("flask", app=app, wait_time=0.1)
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self, request):
- self.browser.visit(EXAMPLE_APP)
-
- def test_serialize_select_mutiple(self):
- """should serialize a select with multiple values into a list"""
- self.browser.select("pets", ["cat", "dog"])
- form = self.browser.find_by_name("send")._get_parent_form()
- data = self.browser.serialize(form)
- assert data["pets"] == ["cat", "dog"]
-
- def test_redirection_on_post(self):
- """
- when submitting a form that POSTs to /redirected,
- browser should be redirected to GET /redirected-location?come=get&some=true
- """
- self.browser.find_by_name("redirect").click()
- assert "I just been redirected to this location" in self.browser.html
- assert "redirect-location?come=get&some=true" in self.browser.url
-
- def test_cookies_extra_parameters(self):
- """Cookie can be created with extra parameters."""
- timestamp = int(time.time() + 120)
- self.browser.cookies.add({"sha": "zam"}, expires=timestamp)
- cookie = {c.key: c for c in self.browser._browser._cookies.values()}["sha"]
- assert timestamp == int(cookie.expires.timestamp())
-
-
-class TestFlaskClientDriverWithCustomHeaders:
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- custom_headers = {
- "X-Splinter-Customheaders-1": "Hello",
- "X-Splinter-Customheaders-2": "Bye",
- }
- request.cls.browser = get_browser("flask", app=app, wait_time=0.1, custom_headers=custom_headers)
- request.addfinalizer(request.cls.browser.quit)
-
- def test_create_a_flask_client_with_custom_headers(self):
- self.browser.visit(EXAMPLE_APP + "headers")
- assert self.browser.is_text_present("X-Splinter-Customheaders-1: Hello")
- assert self.browser.is_text_present("X-Splinter-Customheaders-2: Bye")
diff --git a/tests/test_is_element_present_nojs.py b/tests/test_is_element_present_nojs.py
deleted file mode 100644
index 824954281..000000000
--- a/tests/test_is_element_present_nojs.py
+++ /dev/null
@@ -1,298 +0,0 @@
-# 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.
-import pytest
-
-from .fake_webapp import EXAMPLE_APP
-
-
-supported_browsers = [
- "django",
- "flask",
- "zope.testbrowser",
-]
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_css(get_new_browser, browser_name):
- "should is element present by css verify if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_present_by_css("h1")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_css_returns_false_if_element_is_not_present(
- get_new_browser,
- browser_name,
-):
- "should is element present by css returns False if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_present_by_css(".async-elementzz")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_css(get_new_browser, browser_name):
- "should is element not present by css verify if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_not_present_by_css(".async-element")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_css_returns_false_if_element_is_present(
- get_new_browser,
- browser_name,
-):
- "should is element not present by css returns False if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_not_present_by_css("h1")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_xpath(get_new_browser, browser_name):
- "should is element present by xpath verify if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_present_by_xpath("//h1")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_xpath_returns_false_if_element_is_not_present(
- get_new_browser,
- browser_name,
-):
- "should is element present by xpath returns false if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_not_present_by_xpath("//h4")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_xpath_returns_false_if_element_is_present(
- get_new_browser,
- browser_name,
-):
- "should is element not present by xpath returns false if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_not_present_by_xpath("//h1")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_tag(get_new_browser, browser_name):
- "should is element present by tag verify if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_present_by_tag("h1")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_tag_returns_false_if_element_is_not_present(
- get_new_browser,
- browser_name,
-):
- "should is element present by tag returns false if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_present_by_tag("h4")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_tag(get_new_browser, browser_name):
- "should is element not present by tag verify if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_not_present_by_tag("h4")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_tag_returns_false_if_element_is_present(
- get_new_browser,
- browser_name,
-):
- "should is element not present by tag returns false if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_not_present_by_tag("h1")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_text(get_new_browser, browser_name):
- "should is element present by text verify if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_present_by_text("Complex")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_text_returns_false_if_element_is_not_present(
- get_new_browser,
- browser_name,
-):
- "should is element present by text verify if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_present_by_text("Not present")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_text(get_new_browser, browser_name):
- "should is element not present by text verify if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_not_present_by_text("Not present")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_text_returns_false_if_element_is_present(
- get_new_browser,
- browser_name,
-):
- "should is element not present by text returns False if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_not_present_by_text("Complex")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_value(get_new_browser, browser_name):
- "should is element present by value verify if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_present_by_value("M")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_value_returns_false_if_element_is_not_present(
- get_new_browser,
- browser_name,
-):
- "should is element present by value returns False if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_present_by_value("async-header-value")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_value(get_new_browser, browser_name):
- "should is element not present by value verify if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_not_present_by_value("async-header-value")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_value_returns_false_if_element_is_present(
- get_new_browser,
- browser_name,
-):
- "should is element not present by value returns False if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_not_present_by_value("default value")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_id(get_new_browser, browser_name):
- "should is element present by id verify if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_present_by_id("firstheader")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_id_returns_false_if_element_is_not_present(
- get_new_browser,
- browser_name,
-):
- "should is element present by id returns False if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_present_by_id("async-header")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_id(get_new_browser, browser_name):
- "should is element not present by id verify if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_not_present_by_id("async-header")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_id_returns_false_if_element_is_present(
- get_new_browser,
- browser_name,
-):
- "should is element not present by id returns False if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_not_present_by_id("firstheader")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_name(get_new_browser, browser_name):
- "should is element present by name verify if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_present_by_name("query")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_present_by_name_returns_false_if_element_is_not_present(
- get_new_browser,
- browser_name,
-):
- "should is element present by name returns false if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_present_by_name("async-input")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_name(get_new_browser, browser_name):
- "should is element not present by name verify if element is not present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert browser.is_element_not_present_by_name("async-input")
-
-
-@pytest.mark.parametrize("browser_name", supported_browsers)
-def test_is_element_not_present_by_name_returns_false_if_element_is_present(
- get_new_browser,
- browser_name,
-):
- "should is element not present by name returns false if element is present"
- browser = get_new_browser(browser_name)
- browser.visit(EXAMPLE_APP)
-
- assert not browser.is_element_not_present_by_name("query")
diff --git a/tests/test_webdriver_chrome.py b/tests/test_webdriver_chrome.py
deleted file mode 100644
index 6cefc6387..000000000
--- a/tests/test_webdriver_chrome.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright 2013 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.
-import pytest
-
-from .base import get_browser
-from .base import WebDriverTests
-from .fake_webapp import EXAMPLE_APP
-
-from splinter.config import Config
-
-
-class TestChromeBrowser(WebDriverTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- config = Config(fullscreen=False, headless=True)
- request.cls.browser = get_browser("chrome", config=config)
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self, request):
- self.browser.driver.set_window_size(1024, 768)
- self.browser.visit(EXAMPLE_APP)
-
-
-class TestChromeBrowserFullscreen(WebDriverTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- config = Config(fullscreen=True, headless=True)
- request.cls.browser = get_browser("chrome", config=config)
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self):
- self.browser.visit(EXAMPLE_APP)
diff --git a/tests/test_webdriver_edge_chromium.py b/tests/test_webdriver_edge_chromium.py
deleted file mode 100644
index 66ce3d184..000000000
--- a/tests/test_webdriver_edge_chromium.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright 2021 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.
-import pytest
-
-from .base import get_browser
-from .base import WebDriverTests
-from .fake_webapp import EXAMPLE_APP
-
-from splinter.config import Config
-
-
-class TestEdgeChromiumBrowser(WebDriverTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- config = Config(fullscreen=False, headless=True)
- request.cls.browser = get_browser("edge", config=config)
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self, request):
- self.browser.driver.set_window_size(1024, 768)
- self.browser.visit(EXAMPLE_APP)
-
-
-class TestEdgeChromiumBrowserFullscreen(WebDriverTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- config = Config(fullscreen=True, headless=True)
- request.cls.browser = get_browser("edge", config=config)
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self):
- self.browser.visit(EXAMPLE_APP)
diff --git a/tests/test_webdriver_firefox.py b/tests/test_webdriver_firefox.py
deleted file mode 100644
index 20f476a9d..000000000
--- a/tests/test_webdriver_firefox.py
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright 2013 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.
-import pytest
-
-from tests.base import get_browser
-from tests.base import WebDriverTests
-from tests.fake_webapp import EXAMPLE_APP
-
-from splinter.config import Config
-
-
-class TestFirefoxBrowser(WebDriverTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- config = Config(fullscreen=False, headless=True)
- request.cls.browser = get_browser("firefox", config=config)
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self, request):
- self.browser.visit(EXAMPLE_APP)
-
-
-class TestFirefoxBrowserFullScreen(WebDriverTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- config = Config(fullscreen=True, headless=True)
- request.cls.browser = get_browser("firefox", config=config)
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self, request):
- self.browser.visit(EXAMPLE_APP)
diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py
deleted file mode 100644
index 4987349aa..000000000
--- a/tests/test_webdriver_remote.py
+++ /dev/null
@@ -1,222 +0,0 @@
-# Copyright 2013 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 unittest.mock import patch
-from urllib.request import urlopen
-
-import pytest
-
-from .base import WebDriverTests
-from .fake_webapp import EXAMPLE_APP
-from splinter import Browser
-
-
-def selenium_server_is_running():
- try:
- from splinter.driver.webdriver.remote import WebDriver
-
- page_contents = urlopen(WebDriver.DEFAULT_URL).read()
- except OSError:
- return False
- return "WebDriver Hub" in page_contents
-
-
-class TestRemoteBrowserFirefox(WebDriverTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- request.cls.browser = Browser("remote", browser="firefox")
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self, request):
- self.browser.visit(EXAMPLE_APP)
-
- def test_support_with_statement(self):
- "Remote should support with statement"
- with Browser("remote", browser="firefox"):
- pass
-
- @pytest.mark.skip(reason="Remote should not support custom user agent")
- def test_should_be_able_to_change_user_agent(self):
- pass
-
-
-class TestRemoteBrowserChrome(WebDriverTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- request.cls.browser = Browser("remote", browser="chrome")
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self, request):
- self.browser.visit(EXAMPLE_APP)
-
- def test_support_with_statement(self):
- "Remote should support with statement"
- with Browser("remote", browser="chrome"):
- pass
-
- @pytest.mark.skip(reason="Remote should not support custom user agent")
- def test_should_be_able_to_change_user_agent(self):
- pass
-
-
-@pytest.mark.macos
-class TestRemoteBrowserSafari(WebDriverTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- # test with statement. It can't be used as simple test
- # because safari doesn't support multisessions
- with Browser("remote", browser="safari"):
- pass
-
- request.cls.browser = Browser("remote", browser="safari")
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self, request):
- self.browser.visit(EXAMPLE_APP)
-
- def test_support_with_statement(self):
- """
- Remote should support with statement
- See setup browser
- """
-
- @pytest.mark.skip(reason="Remote should not support custom user agent")
- def test_should_be_able_to_change_user_agent(self):
- pass
-
- # ------- BEGIN OF MULTISESSION TESTS -------
- # Safari doesn't support multisessions.
- # So next tests mock quit of browser.
- def get_new_browser(self):
- return self.browser
-
- def test_can_forward_on_history(self):
- with patch("splinter.driver.webdriver.remote.WebDriver.quit"):
- super().test_can_forward_on_history()
-
- def test_create_and_access_a_cookie(self):
- with patch("splinter.driver.webdriver.remote.WebDriver.quit"):
- super().test_create_and_access_a_cookie()
-
- def test_create_many_cookies_at_once_as_dict(self):
- with patch("splinter.driver.webdriver.remote.WebDriver.quit"):
- super().test_create_many_cookies_at_once_as_dict()
-
- def test_create_some_cookies_and_delete_them_all(self):
- with patch("splinter.driver.webdriver.remote.WebDriver.quit"):
- super().test_create_some_cookies_and_delete_them_all()
-
- def test_create_and_delete_a_cookie(self):
- with patch("splinter.driver.webdriver.remote.WebDriver.quit"):
- super().test_create_and_delete_a_cookie()
-
- def test_create_and_delete_many_cookies(self):
- with patch("splinter.driver.webdriver.remote.WebDriver.quit"):
- super().test_create_and_delete_many_cookies()
-
- def test_try_to_destroy_an_absent_cookie_and_nothing_happens(self):
- with patch("splinter.driver.webdriver.remote.WebDriver.quit"):
- super().test_try_to_destroy_an_absent_cookie_and_nothing_happens()
-
- def test_create_and_get_all_cookies(self):
- with patch("splinter.driver.webdriver.remote.WebDriver.quit"):
- super().test_create_and_get_all_cookies()
-
- def test_create_and_use_contains(self):
- with patch("splinter.driver.webdriver.remote.WebDriver.quit"):
- super().test_create_and_use_contains()
-
- # ------- END OF MULTISESSION TESTS -------
-
- def test_can_fill_more_than_one_field_in_form(self):
- "should provide a away to change field value"
- self.browser.find_by_name("query").fill("my name")
- assert not self.browser.find_by_id("gender-m").checked
- assert not self.browser.find_option_by_value("rj").selected
- assert not self.browser.find_by_name("some-check").checked
- assert self.browser.find_by_name("checked-checkbox").checked
- # Select of dropdown doesn't work for Safari 17 (remote). Safari as OS user works well
- # for some reason select doesn't work for Safari
- self.browser.fill_form(
- {
- "query": "another new query",
- "description": "Just another description value in the textarea",
- "gender": "M",
- # "uf": "rj",
- "some-check": True,
- "checked-checkbox": False,
- },
- )
- query_value = self.browser.find_by_name("query").value
- assert "another new query" == query_value
- desc_value = self.browser.find_by_name("description").value
- assert "Just another description value in the textarea" == desc_value
- assert self.browser.find_by_id("gender-m").checked
- # assert self.browser.find_option_by_value("rj").selected
- assert self.browser.find_by_name("some-check").checked
- assert not self.browser.find_by_name("checked-checkbox").checked
-
- # ------- BEGIN OF CLICK PROBLEM TESTS -------
- # https://stackoverflow.com/questions/77388720/automation-testing-with-selenium-click-doesnt-works-on-new-safari-17-ios-sonoma
- @pytest.mark.xfail
- def test_click_element_by_css_selector(self):
- super().test_click_element_by_css_selector()
-
- @pytest.mark.xfail
- def test_click_input_by_css_selector(self):
- super().test_click_input_by_css_selector()
-
- @pytest.mark.xfail
- def test_clicking_submit_button_doesnt_post_button_value_if_empty(self):
- super().test_clicking_submit_button_doesnt_post_button_value_if_empty()
-
- @pytest.mark.xfail
- def test_clicking_submit_button_doesnt_post_button_value_if_name_not_present(self):
- super().test_clicking_submit_button_doesnt_post_button_value_if_name_not_present()
-
- @pytest.mark.xfail
- def test_clicking_submit_button_posts_button_value_if_value_present(self):
- super().test_clicking_submit_button_posts_button_value_if_value_present()
-
- @pytest.mark.xfail
- def test_clicking_submit_button_posts_empty_value_if_value_not_present(self):
- super().test_clicking_submit_button_posts_empty_value_if_value_not_present()
-
- @pytest.mark.xfail
- def test_clicking_submit_input_doesnt_post_input_value_if_empty(self):
- super().test_clicking_submit_input_doesnt_post_input_value_if_empty()
-
- @pytest.mark.xfail
- def test_clicking_submit_input_doesnt_post_input_value_if_name_not_present(self):
- super().test_clicking_submit_input_doesnt_post_input_value_if_name_not_present()
-
- @pytest.mark.xfail
- def test_clicking_submit_input_posts_empty_value_if_value_not_present(self):
- super().test_clicking_submit_input_posts_empty_value_if_value_not_present()
-
- @pytest.mark.xfail
- def test_clicking_submit_input_posts_input_value_if_value_present(self):
- super().test_clicking_submit_input_posts_input_value_if_value_present()
-
- @pytest.mark.xfail
- def test_submiting_a_form_and_verifying_page_content(self):
- super().test_submiting_a_form_and_verifying_page_content()
-
- @pytest.mark.xfail
- def test_click_links(self):
- super().test_click_links()
-
- # ------- END OF CLICK PROBLEM TESTS -------
- # ------- START OF TYPE PROBLEM TESTS -------
- @pytest.mark.xfail
- def test_simple_type(self):
- super().test_simple_type()
-
- @pytest.mark.xfail
- def test_simple_type_on_element(self):
- super().test_simple_type_on_element()
-
- # ------- END OF TYPE PROBLEM TESTS -------
diff --git a/tests/test_zopetestbrowser.py b/tests/test_zopetestbrowser.py
deleted file mode 100644
index c28759bed..000000000
--- a/tests/test_zopetestbrowser.py
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright 2013 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.
-import pytest
-
-from .base import BaseBrowserTests
-from .base import get_browser
-from .fake_webapp import EXAMPLE_APP
-from .lxml_drivers import LxmlDriverTests
-
-
-class TestZopeTestBrowserDriver(LxmlDriverTests, BaseBrowserTests):
- @pytest.fixture(autouse=True, scope="class")
- def setup_browser(self, request):
- request.cls.browser = get_browser("zope.testbrowser", wait_time=0.1)
- request.addfinalizer(request.cls.browser.quit)
-
- @pytest.fixture(autouse=True)
- def visit_example_app(self, request):
- self.browser.visit(EXAMPLE_APP)
-
- def test_fill_form_missing_values(self):
- """Missing values should raise an error."""
- with pytest.raises(LookupError):
- self.browser.fill_form(
- {"query": "new query", "missing_form": "doesn't exist"},
- )
-
- def test_cookies_extra_parameters(self):
- """Cookie can be created with extra parameters."""
- comment = "Ipsum lorem"
- self.browser.cookies.add({"sha": "zam"}, comment=comment)
- cookie = self.browser._browser.cookies.getinfo("sha")
- assert "Ipsum%20lorem" == cookie["comment"]
diff --git a/tests/tests_django/conftest.py b/tests/tests_django/conftest.py
new file mode 100644
index 000000000..05c79b270
--- /dev/null
+++ b/tests/tests_django/conftest.py
@@ -0,0 +1,11 @@
+import os
+import sys
+
+import django
+
+
+sys.path.append("tests/fake_django")
+os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
+
+
+django.setup()
diff --git a/tests/tests_django/test_cookies_django.py b/tests/tests_django/test_cookies_django.py
new file mode 100644
index 000000000..1b3baf6d4
--- /dev/null
+++ b/tests/tests_django/test_cookies_django.py
@@ -0,0 +1,12 @@
+# 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.
+import time
+
+
+def test_cookies_extra_parameters(browser):
+ """Cookie can be created with extra parameters."""
+ timestamp = int(time.time() + 120)
+ browser.cookies.add({"sha": "zam"}, expires=timestamp)
+ cookie = browser._browser.cookies["sha"]
+ assert timestamp == cookie["expires"]
diff --git a/tests/tests_django/test_custom_headers.py b/tests/tests_django/test_custom_headers.py
new file mode 100644
index 000000000..91640c7cb
--- /dev/null
+++ b/tests/tests_django/test_custom_headers.py
@@ -0,0 +1,19 @@
+import pytest
+
+
+@pytest.fixture()
+def browser_kwargs():
+ return {
+ "custom_headers": {
+ "X-Splinter-Customheaders-1": "Hello",
+ "X-Splinter-Customheaders-2": "Bye",
+ },
+ }
+
+
+def test_create_a_django_client_with_custom_headers(request, browser, app_url):
+ request.addfinalizer(browser.quit)
+
+ browser.visit(app_url + "headers")
+ assert browser.is_text_present("X-Splinter-Customheaders-1: Hello")
+ assert browser.is_text_present("X-Splinter-Customheaders-2: Bye")
diff --git a/tests/tests_firefox_webdriver/test_firefox_capabilities.py b/tests/tests_firefox_webdriver/test_firefox_capabilities.py
index 591bf20b5..15f1142fd 100644
--- a/tests/tests_firefox_webdriver/test_firefox_capabilities.py
+++ b/tests/tests_firefox_webdriver/test_firefox_capabilities.py
@@ -7,8 +7,6 @@ def browser_kwargs():
def test_capabilities_set(request, browser):
- request.addfinalizer(browser.quit)
-
capabilities = browser.driver.capabilities
assert "pageLoadStrategy" in capabilities
assert "eager" == capabilities.get("pageLoadStrategy")
diff --git a/tests/tests_firefox_webdriver/test_firefox_extension.py b/tests/tests_firefox_webdriver/test_firefox_extension.py
index 3243e35d9..567ddbc37 100644
--- a/tests/tests_firefox_webdriver/test_firefox_extension.py
+++ b/tests/tests_firefox_webdriver/test_firefox_extension.py
@@ -3,8 +3,6 @@
import pytest
-from tests.fake_webapp import EXAMPLE_APP
-
from splinter.config import Config
@@ -20,14 +18,12 @@ def browser_config():
return Config(extensions=[str(extension_path)], headless=True)
-def test_firefox_create_instance_with_extension(request, browser):
+def test_firefox_create_instance_with_extension(request, browser, app_url):
"""Test: Load an extension via selenium.
The dummy extension should add a red border to any web page.
"""
- request.addfinalizer(browser.quit)
-
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
elem = browser.find_by_css("body")
elem.is_visible(wait_time=20)
diff --git a/tests/tests_firefox_webdriver/test_firefox_preferences.py b/tests/tests_firefox_webdriver/test_firefox_preferences.py
index 3375a2579..3c2b82e81 100644
--- a/tests/tests_firefox_webdriver/test_firefox_preferences.py
+++ b/tests/tests_firefox_webdriver/test_firefox_preferences.py
@@ -13,8 +13,6 @@ def browser_kwargs():
def test_preference_set(request, browser):
- request.addfinalizer(browser.quit)
-
# Rip the preferences out of firefox's config page
browser.visit("about:config")
browser.find_by_id("warningButton").click()
diff --git a/tests/tests_flask/test_cookies_flask.py b/tests/tests_flask/test_cookies_flask.py
new file mode 100644
index 000000000..305c1e936
--- /dev/null
+++ b/tests/tests_flask/test_cookies_flask.py
@@ -0,0 +1,9 @@
+import time
+
+
+def test_cookies_extra_parameters(browser):
+ """Cookie can be created with extra parameters."""
+ timestamp = int(time.time() + 120)
+ browser.cookies.add({"sha": "zam"}, expires=timestamp)
+ cookie = {c.key: c for c in browser._browser._cookies.values()}["sha"]
+ assert timestamp == int(cookie.expires.timestamp())
diff --git a/tests/tests_flask/test_flaskclient.py b/tests/tests_flask/test_flaskclient.py
new file mode 100644
index 000000000..b25c1dc4e
--- /dev/null
+++ b/tests/tests_flask/test_flaskclient.py
@@ -0,0 +1,31 @@
+# Copyright 2014 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.
+import pytest
+
+from tests.fake_webapp import app
+
+
+@pytest.fixture()
+def browser_kwargs():
+ return {"app": app, "wait_time": 0.1}
+
+
+def test_serialize_select_mutiple(browser, app_url):
+ """should serialize a select with multiple values into a list"""
+ browser.visit(app_url)
+ browser.select("pets", ["cat", "dog"])
+ form = browser.find_by_name("send")._get_parent_form()
+ data = browser.serialize(form)
+ assert data["pets"] == ["cat", "dog"]
+
+
+def test_redirection_on_post(browser, app_url):
+ """
+ when submitting a form that POSTs to /redirected,
+ browser should be redirected to GET /redirected-location?come=get&some=true
+ """
+ browser.visit(app_url)
+ browser.find_by_name("redirect").click()
+ assert "I just been redirected to this location" in browser.html
+ assert "redirect-location?come=get&some=true" in browser.url
diff --git a/tests/tests_flask/tests_custom_headers_flask.py b/tests/tests_flask/tests_custom_headers_flask.py
new file mode 100644
index 000000000..010f31bf9
--- /dev/null
+++ b/tests/tests_flask/tests_custom_headers_flask.py
@@ -0,0 +1,23 @@
+import pytest
+
+from tests.fake_webapp import app
+
+
+@pytest.fixture()
+def browser_kwargs():
+ return {
+ "app": app,
+ "wait_time": 0.1,
+ "custom_headers": {
+ "X-Splinter-Customheaders-1": "Hello",
+ "X-Splinter-Customheaders-2": "Bye",
+ },
+ }
+
+
+def test_create_a_flask_client_with_custom_headers(request, browser, app_url):
+ request.addfinalizer(browser.quit)
+
+ browser.visit(app_url + "headers")
+ assert browser.is_text_present("X-Splinter-Customheaders-1: Hello")
+ assert browser.is_text_present("X-Splinter-Customheaders-2: Bye")
diff --git a/tests/tests_splinter/test_browser.py b/tests/tests_splinter/test_browser.py
index 0da66e514..c03655368 100644
--- a/tests/tests_splinter/test_browser.py
+++ b/tests/tests_splinter/test_browser.py
@@ -103,8 +103,8 @@ def test_browser_log_missing_drivers(caplog):
reload(browser)
unpatch_driver(browser, old_import)
- assert 7 == len(caplog.records)
- for i in range(0, 6):
+ assert 12 == len(caplog.records)
+ for i in range(0, 11):
record = caplog.records[i]
assert record.levelname == "DEBUG"
assert "Import Warning" in record.message
diff --git a/tests/tests_webdriver/test_alerts.py b/tests/tests_webdriver/test_alerts.py
new file mode 100644
index 000000000..9c8f18a9c
--- /dev/null
+++ b/tests/tests_webdriver/test_alerts.py
@@ -0,0 +1,98 @@
+import time
+
+
+def test_access_alerts_and_accept_them(browser, app_url):
+ browser.visit(app_url + "alert")
+ browser.find_by_tag("h1").click()
+ alert = browser.get_alert()
+ assert "This is an alert example." == alert.text
+ alert.accept()
+
+
+def test_access_prompts_and_be_able_to_fill_then(browser, app_url):
+ browser.visit(app_url + "alert")
+ browser.find_by_tag("h2").click()
+
+ alert = browser.get_alert()
+ assert "What is your name?" == alert.text
+ alert.fill_with("Splinter")
+ alert.accept()
+
+ # Wait for alert
+ time.sleep(2.5)
+
+ response = browser.get_alert()
+ assert "Splinter" == response.text
+ response.accept()
+
+
+def test_access_confirm_and_accept_and_dismiss_them(browser, app_url):
+ browser.visit(app_url + "alert")
+
+ browser.find_by_tag("h3").click()
+ alert = browser.get_alert()
+
+ assert "Should I continue?" == alert.text
+ alert.accept()
+
+ # Wait for alert
+ time.sleep(2.5)
+
+ alert = browser.get_alert()
+ assert "You say I should" == alert.text
+ alert.accept()
+
+ browser.find_by_tag("h3").click()
+ alert = browser.get_alert()
+ assert "Should I continue?" == alert.text
+ alert.dismiss()
+
+ # Wait for alert
+ time.sleep(2.5)
+
+ alert = browser.get_alert()
+ assert "You say I should not" == alert.text
+ alert.accept()
+
+
+def test_access_confirm_and_accept_and_dismiss_them_using_with(browser, app_url):
+ browser.visit(app_url + "alert")
+
+ browser.find_by_tag("h3").click()
+ with browser.get_alert() as alert:
+ assert "Should I continue?" == alert.text
+ alert.accept()
+
+ # Wait for alert
+ time.sleep(2.5)
+
+ with browser.get_alert() as alert:
+ assert "You say I should" == alert.text
+ alert.accept()
+
+ browser.find_by_tag("h3").click()
+ with browser.get_alert() as alert:
+ assert "Should I continue?" == alert.text
+ alert.dismiss()
+
+ # Wait for alert
+ time.sleep(2.5)
+
+ with browser.get_alert() as alert:
+ assert "You say I should not" == alert.text
+ alert.accept()
+
+
+def test_access_alerts_using_with(browser, app_url):
+ "should access alerts using 'with' statement"
+ browser.visit(app_url + "alert")
+ browser.find_by_tag("h1").click()
+ with browser.get_alert() as alert:
+ assert "This is an alert example." == alert.text
+ alert.accept()
+
+
+def test_get_alert_return_none_if_no_alerts(browser, app_url):
+ "should return None if no alerts available"
+ alert = browser.get_alert()
+ assert alert is None
diff --git a/tests/tests_webdriver/test_async_finder.py b/tests/tests_webdriver/test_async_finder.py
index 79f3dc4a1..c982435b2 100644
--- a/tests/tests_webdriver/test_async_finder.py
+++ b/tests/tests_webdriver/test_async_finder.py
@@ -1,11 +1,8 @@
# Copyright 2012 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 tests.fake_webapp import EXAMPLE_APP
-
-
-def test_find_by_css_should_found_an_async_element(browser):
- browser.visit(EXAMPLE_APP)
+def test_find_by_css_should_found_an_async_element(browser, app_url):
+ browser.visit(app_url)
browser.find_by_css(".add-async-element").click()
elements = browser.find_by_css(".async-element", wait_time=30)
@@ -13,8 +10,8 @@ def test_find_by_css_should_found_an_async_element(browser):
assert 1 == len(elements)
-def test_find_by_xpath_should_found_an_async_element(browser):
- browser.visit(EXAMPLE_APP)
+def test_find_by_xpath_should_found_an_async_element(browser, app_url):
+ browser.visit(app_url)
browser.find_by_css(".add-async-element").click()
elements = browser.find_by_xpath("//h4", wait_time=30)
@@ -22,8 +19,8 @@ def test_find_by_xpath_should_found_an_async_element(browser):
assert 1 == len(elements)
-def test_find_by_tag_should_found_an_async_element(browser):
- browser.visit(EXAMPLE_APP)
+def test_find_by_tag_should_found_an_async_element(browser, app_url):
+ browser.visit(app_url)
browser.find_by_css(".add-async-element").click()
elements = browser.find_by_tag("h4", wait_time=30)
@@ -31,8 +28,8 @@ def test_find_by_tag_should_found_an_async_element(browser):
assert 1 == len(elements)
-def test_find_by_id_should_found_an_async_element(browser):
- browser.visit(EXAMPLE_APP)
+def test_find_by_id_should_found_an_async_element(browser, app_url):
+ browser.visit(app_url)
browser.find_by_css(".add-async-element").click()
elements = browser.find_by_id("async-header", wait_time=30)
@@ -40,8 +37,8 @@ def test_find_by_id_should_found_an_async_element(browser):
assert 1 == len(elements)
-def test_find_by_name_should_found_an_async_element(browser):
- browser.visit(EXAMPLE_APP)
+def test_find_by_name_should_found_an_async_element(browser, app_url):
+ browser.visit(app_url)
browser.find_by_css(".add-async-element").click()
elements = browser.find_by_name("async-input", wait_time=10)
@@ -49,8 +46,8 @@ def test_find_by_name_should_found_an_async_element(browser):
assert 1 == len(elements)
-def test_find_by_value_should_found_an_async_element(browser):
- browser.visit(EXAMPLE_APP)
+def test_find_by_value_should_found_an_async_element(browser, app_url):
+ browser.visit(app_url)
browser.find_by_css(".add-async-element").click()
elements = browser.find_by_value("async-header-value", wait_time=30)
diff --git a/tests/tests_webdriver/test_cookies_wd.py b/tests/tests_webdriver/test_cookies_wd.py
new file mode 100644
index 000000000..0959624a5
--- /dev/null
+++ b/tests/tests_webdriver/test_cookies_wd.py
@@ -0,0 +1,10 @@
+import time
+
+
+def test_cookies_extra_parameters(browser, app_url):
+ """Cookie can be created with extra parameters."""
+ browser.visit(app_url)
+ timestamp = int(time.time() + 120)
+ browser.cookies.add({"sha": "zam"}, expiry=timestamp)
+ cookie = browser.driver.get_cookie("sha")
+ assert timestamp == cookie["expiry"]
diff --git a/tests/tests_webdriver/test_element_does_not_exist.py b/tests/tests_webdriver/test_element_does_not_exist.py
new file mode 100644
index 000000000..be76ea913
--- /dev/null
+++ b/tests/tests_webdriver/test_element_does_not_exist.py
@@ -0,0 +1,63 @@
+# Copyright 2012 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.
+import pytest
+
+from splinter.exceptions import ElementDoesNotExist
+
+
+def test_element_query_should_raises_when_element_first_doest_exists(browser, app_url):
+ browser.visit(app_url)
+ with pytest.raises(ElementDoesNotExist):
+ browser.find_by_css(".element-that-dont-exists").first
+
+
+def test_element_list_raises_when_element_last_does_not_exists(browser, app_url):
+ browser.visit(app_url)
+ with pytest.raises(ElementDoesNotExist):
+ browser.find_by_css(".element-that-dont-exists").last
+
+
+def test_element_list_raises_when_element_does_not_exists(browser, app_url):
+ browser.visit(app_url)
+ with pytest.raises(ElementDoesNotExist):
+ browser.find_by_css(".element-that-dont-exists")[2]
+
+
+def test_element_list_raises_with_unicode_query(browser, app_url):
+ browser.visit(app_url)
+ with pytest.raises(ElementDoesNotExist):
+ browser.find_by_css(".element[title=título]").last
+
+
+def test_element_list_contains_right_information_and_raises_right_exception(browser, app_url):
+ "element list contains right information about query and raises nice exception message"
+ browser.visit(app_url)
+ with pytest.raises(ElementDoesNotExist) as err:
+ element_list = browser.find_by_css(".element-that-dont-exists")
+ assert "css" == element_list.find_by
+ assert ".element-that-dont-exists" == element_list.query
+ element_list.first
+
+ expected_message = 'No elements were found with css ".element-that-dont-exists"'
+
+ assert expected_message == err.value.args[0]
+
+
+def test_element_list_raises_when_element_first_doesnt_exists_in_element_context(
+ browser,
+ app_url,
+):
+ "element list raises exception with right information in element context"
+ browser.visit(app_url)
+ with pytest.raises(ElementDoesNotExist) as err:
+ element_list = browser.find_by_css("#inside").find_by_css(
+ ".inner-element-that-dont-exists",
+ )
+ assert "css" == element_list.find_by
+ assert ".inner-element-that-dont-exists" == element_list.query
+ element_list.first
+
+ expected_message = 'No elements were found with css ".inner-element-that-dont-exists"'
+
+ assert expected_message == err.value.args[0]
diff --git a/tests/tests_webdriver/test_element_is_visible.py b/tests/tests_webdriver/test_element_is_visible.py
index c8cc1e225..31aa90854 100644
--- a/tests/tests_webdriver/test_element_is_visible.py
+++ b/tests/tests_webdriver/test_element_is_visible.py
@@ -3,61 +3,59 @@
# license that can be found in the LICENSE file.
import time
-from tests.fake_webapp import EXAMPLE_APP
-
-def test_element_is_visible(browser):
+def test_element_is_visible(browser, app_url):
"""WebDriverElement.is_visible() should verify if element is visible."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
browser.find_by_css(".show-invisible-element").click()
assert browser.find_by_css("#invisible").is_visible()
-def test_element_is_visible_custom_wait_time(browser):
+def test_element_is_visible_custom_wait_time(browser, app_url):
"""WebDriverElement.is_visible()'s wait_time argument should be respected."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
browser.find_by_css(".show-invisible-element").click()
assert browser.find_by_css("#invisible").is_visible(wait_time=12)
-def test_element_is_visible_return_false(browser):
+def test_element_is_visible_return_false(browser, app_url):
"""WebDriverElement.is_visible() should return False if element is not visible."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
assert not browser.find_by_css("#invisible").is_visible()
-def test_element_is_not_visible(browser):
+def test_element_is_not_visible(browser, app_url):
"""WebDriverElement.is_not_visible() should verify if element is not visible."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
assert browser.find_by_css("#invisible").is_not_visible()
-def test_element_is_not_visible_return_false(browser):
+def test_element_is_not_visible_return_false(browser, app_url):
"""WebDriverElement.is_not_visible() should return False if element is visible."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
browser.find_by_css(".show-invisible-element").click()
assert not browser.find_by_css("#invisible").is_not_visible()
-def test_element_is_not_visible_custom_wait_time(browser):
+def test_element_is_not_visible_custom_wait_time(browser, app_url):
"""WebDriverElement.is_not_visible()'s wait_time argument should be respected."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
assert browser.find_by_css("#invisible").is_not_visible(wait_time=12)
-def test_element_is_visible_element_removed(browser):
+def test_element_is_visible_element_removed(browser, app_url):
"""
Given an element has been found
When it is removed from the page
Then the is_visible() method for this element will return False
"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
elem = browser.find_by_css("#removed_after_5_seconds")
@@ -67,13 +65,13 @@ def test_element_is_visible_element_removed(browser):
assert not elem.is_visible()
-def test_element_is_not_visible_element_removed(browser):
+def test_element_is_not_visible_element_removed(browser, app_url):
"""
Given an element has been found
When it is removed from the page
Then the is_not_visible() method for this element will return True
"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
elem = browser.find_by_css("#removed_after_5_seconds")
diff --git a/tests/tests_webdriver/test_element_wd.py b/tests/tests_webdriver/test_element_wd.py
new file mode 100644
index 000000000..7d1f63226
--- /dev/null
+++ b/tests/tests_webdriver/test_element_wd.py
@@ -0,0 +1,54 @@
+from selenium.common.exceptions import WebDriverException
+
+import pytest
+
+
+def test_can_see_the_text_for_an_element(browser, app_url):
+ "should provide text for an element"
+ browser.visit(app_url)
+ assert browser.find_by_id("simple_text").text == "my test text"
+
+
+def test_the_text_for_an_element_strips_html_tags(browser, app_url):
+ "should show that the text attribute strips html"
+ browser.visit(app_url)
+ assert browser.find_by_id("text_with_html").text == "another bit of text"
+
+
+def test_can_verify_if_a_element_is_visible(browser, app_url):
+ "should provide verify if element is visible"
+ browser.visit(app_url)
+ assert browser.find_by_id("visible").visible
+
+
+def test_can_verify_if_a_element_is_invisible(browser, app_url):
+ "should provide verify if element is invisible"
+ browser.visit(app_url)
+ assert not browser.find_by_id("invisible").visible
+
+
+def test_can_select_a_option_via_element_text(browser, app_url):
+ "should provide a way to select a option via element"
+ browser.visit(app_url)
+ assert not browser.find_option_by_value("rj").selected
+ browser.find_by_name("uf").select_by_text("Rio de Janeiro")
+ assert browser.find_option_by_value("rj").selected
+
+
+def test_click_intercepted(browser, app_url):
+ """Intercepted clicks should retry."""
+ browser.visit(app_url + "click_intercepted")
+ browser.wait_time = 10
+ # Clicking this element adds a new element to the page.
+ browser.find_by_id("overlapped").click()
+ value = browser.find_by_id("added_container").value
+ assert "Added" == value
+ browser.wait_time = 2
+
+
+def test_click_intercepted_fails(browser, app_url):
+ """Intercepted clicks that never unblock should raise an error."""
+ browser.visit(app_url + "click_intercepted")
+
+ with pytest.raises(WebDriverException):
+ browser.find_by_id("overlapped2").click()
diff --git a/tests/tests_webdriver/test_form_elements_wd.py b/tests/tests_webdriver/test_form_elements_wd.py
new file mode 100644
index 000000000..95a326093
--- /dev/null
+++ b/tests/tests_webdriver/test_form_elements_wd.py
@@ -0,0 +1,61 @@
+def test_can_clear_text_field_content(browser, app_url):
+ browser.visit(app_url)
+ my_input = "random query"
+ elem = browser.find_by_name("query")
+ elem.fill(my_input)
+ assert my_input == elem.value
+
+ elem.clear()
+ assert not elem.value
+
+
+def test_can_clear_password_field_content(browser, app_url):
+ browser.visit(app_url)
+ my_input = "1nF4m310"
+ elem = browser.find_by_name("password")
+ elem.fill(my_input)
+ assert my_input == elem.value
+
+ elem.clear()
+ assert not elem.value
+
+
+def test_can_clear_tel_field_content(browser, app_url):
+ browser.visit(app_url)
+ my_input = "5553743980"
+ elem = browser.find_by_name("telephone")
+ elem.fill(my_input)
+ assert my_input == elem.value
+
+ elem.clear()
+ assert not elem.value
+
+
+def test_can_clear_textarea_content(browser, app_url):
+ browser.visit(app_url)
+ elem = browser.find_by_name("description")
+ elem.fill("A box of widgets")
+ assert "A box of widgets" == elem.value
+
+ elem.clear()
+ assert "" == elem.value
+
+
+def test_can_clear_search_content(browser, app_url):
+ browser.visit(app_url)
+ elem = browser.find_by_name("search_keyword")
+ elem.fill("widgets")
+ assert "widgets" == elem.value
+
+ elem.clear()
+ assert "" == elem.value
+
+
+def test_can_clear_url_content(browser, app_url):
+ browser.visit(app_url)
+ elem = browser.find_by_name("url_input")
+ elem.fill("http://widgets.com")
+ assert "http://widgets.com" == elem.value
+
+ elem.clear()
+ assert "" == elem.value
diff --git a/tests/tests_webdriver/test_html_snapshot.py b/tests/tests_webdriver/test_html_snapshot.py
index f05a7cdce..76daad0ca 100644
--- a/tests/tests_webdriver/test_html_snapshot.py
+++ b/tests/tests_webdriver/test_html_snapshot.py
@@ -1,39 +1,37 @@
import os
import tempfile
-from tests.fake_webapp import EXAMPLE_APP
-
-def test_take_snapshot_no_unique_file(browser):
+def test_take_snapshot_no_unique_file(browser, app_url):
"""When the unique_file parameter is false,
Then the filename should match the name parameter exactly.
"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
browser.html_snapshot(name="test_html_snap", unique_file=False)
expected_filepath = os.path.abspath("test_html_snap.html")
assert os.path.isfile(expected_filepath)
-def test_html_snapshot(browser):
+def test_html_snapshot(browser, app_url):
"""Should take an html snapshot of the current page."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
filename = browser.html_snapshot()
assert tempfile.gettempdir() in filename
-def test_html_snapshot_with_prefix(browser):
+def test_html_snapshot_with_prefix(browser, app_url):
"""Should add the prefix to the snapshot filename"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
filename = browser.html_snapshot(name="foobar")
assert "foobar" in filename
-def test_html_snapshot_with_suffix(browser):
+def test_html_snapshot_with_suffix(browser, app_url):
"""Should add the suffix to the snapshot filename"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
filename = browser.html_snapshot(suffix="xml")
assert "xml" == filename[-3:]
diff --git a/tests/tests_webdriver/test_iframes.py b/tests/tests_webdriver/test_iframes.py
index 0cc02080f..ea837ab09 100644
--- a/tests/tests_webdriver/test_iframes.py
+++ b/tests/tests_webdriver/test_iframes.py
@@ -1,12 +1,9 @@
# Copyright 2012 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 tests.fake_webapp import EXAMPLE_APP
-
-
-def test_can_work_on_iframes_by_name(browser):
+def test_can_work_on_iframes_by_name(browser, app_url):
"""can work on iframes and switch back to the page"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
with browser.get_iframe("iframemodal-name") as frame:
value = frame.find_by_tag("h1").value
@@ -16,9 +13,9 @@ def test_can_work_on_iframes_by_name(browser):
assert "Example Header" == value
-def test_can_work_on_iframes_by_id(browser):
+def test_can_work_on_iframes_by_id(browser, app_url):
"""can work on iframes and switch back to the page"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
with browser.get_iframe("iframemodal") as frame:
value = frame.find_by_tag("h1").value
@@ -28,9 +25,9 @@ def test_can_work_on_iframes_by_id(browser):
assert "Example Header" == value
-def test_can_work_on_iframes_by_webelement(browser):
+def test_can_work_on_iframes_by_webelement(browser, app_url):
"""can work on iframes and switch back to the page"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
elem = browser.find_by_id("iframemodal").first
@@ -42,9 +39,9 @@ def test_can_work_on_iframes_by_webelement(browser):
assert "Example Header" == value
-def test_can_work_on_iframes_by_index(browser):
+def test_can_work_on_iframes_by_index(browser, app_url):
"""can work on iframes and switch back to the page"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
with browser.get_iframe(0) as frame:
value = frame.find_by_tag("h1").value
diff --git a/tests/tests_webdriver/test_is_element_present.py b/tests/tests_webdriver/test_is_element_present.py
new file mode 100644
index 000000000..1a3cbb6dc
--- /dev/null
+++ b/tests/tests_webdriver/test_is_element_present.py
@@ -0,0 +1,259 @@
+# 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.
+def test_is_element_present_by_css(browser, app_url):
+ "should is element present by css verify if element is present"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_css(".async-element")
+
+
+def test_is_element_present_by_css_using_a_custom_wait_time(browser, app_url):
+ "should is element present by css verify if element is present using a custom wait time"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_css(".async-element2", wait_time=12)
+
+
+def test_is_element_present_by_css_returns_false_if_element_is_not_present(browser, app_url):
+ "should is element present by css returns False if element is not present"
+ browser.visit(app_url)
+ assert not browser.is_element_present_by_css(".async-elementzz")
+
+
+def test_is_element_not_present_by_css(browser, app_url):
+ "should is element not present by css verify if element is not present"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_css(".async-element")
+
+
+def test_is_element_not_present_by_css_returns_false_if_element_is_present(browser, app_url):
+ "should is element not present by css returns False if element is present"
+ browser.visit(app_url)
+ assert not browser.is_element_not_present_by_css("h1")
+
+
+def test_is_element_not_present_by_css_using_a_custom_wait_time(browser, app_url):
+ "should is element not present by css verify if element is not present using a custom wait time"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_css(".async-element", wait_time=12)
+
+
+def test_is_element_present_by_xpath(browser, app_url):
+ "should is element present by xpath verify if element is present"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_xpath("//h4")
+
+
+def test_is_element_present_by_xpath_using_a_custom_wait_time(browser, app_url):
+ "should is element present by xpath verify if element is present using a custom wait time"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_xpath("//h5", wait_time=12)
+
+
+def test_is_element_present_by_xpath_returns_false_if_element_is_not_present(browser, app_url):
+ "should is element present by xpath returns false if element is not present"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_xpath("//h4")
+
+
+def test_is_element_not_present_by_xpath_returns_false_if_element_is_present(browser, app_url):
+ """should is_element_not_present_by_xpath returns False if element is present"""
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert len(browser.find_by_xpath("//h4")) > 0
+ assert not browser.is_element_not_present_by_xpath("//h4")
+
+
+def test_is_element_not_present_by_xpath_using_a_custom_wait_time(browser, app_url):
+ "should is element not present by xpath verify if element is not present using a custom wait time"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_xpath("//h4", wait_time=12)
+
+
+def test_is_element_present_by_tag(browser, app_url):
+ "should is element present by tag verify if element is present"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_tag("h4")
+
+
+def test_is_element_present_by_tag_using_a_custom_wait_time(browser, app_url):
+ "should is element present by tag verify if element is present using a custom wait time"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_tag("h4", wait_time=12)
+
+
+def test_is_element_present_by_tag_returns_false_if_element_is_not_present(browser, app_url):
+ "should is element present by tag returns false if element is not present"
+ browser.visit(app_url)
+ assert not browser.is_element_present_by_tag("h4")
+
+
+def test_is_element_not_present_by_tag(browser, app_url):
+ "should is element not present by tag verify if element is not present"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_tag("h4")
+
+
+def test_is_element_not_present_by_tag_using_a_custom_wait_time(browser, app_url):
+ "should is element not present by tag verify if element is not present using a custom wait time"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_tag("h4", wait_time=12)
+
+
+def test_is_element_not_present_by_tag_returns_false_if_element_is_present(browser, app_url):
+ """should is_element_not_present_by_tag returns False if element is present"""
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ browser.find_by_tag("h4")
+ assert not browser.is_element_not_present_by_tag("h4")
+
+
+def test_is_element_present_by_text(browser, app_url):
+ "should is element present by text verify if element is present"
+ browser.visit(app_url)
+ assert browser.is_element_present_by_text("Complex")
+
+
+def test_is_element_present_by_text_returns_false_if_element_is_not_present(browser, app_url):
+ "should is element present by text verify if element is present"
+ browser.visit(app_url)
+ assert not browser.is_element_present_by_text("Not present")
+
+
+def test_is_element_not_present_by_text(browser, app_url):
+ "should is element not present by text verify if element is not present"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_text("Not present")
+
+
+def test_is_element_not_present_by_text_returns_false_if_element_is_present(browser, app_url):
+ "should is element not present by text returns False if element is present"
+ browser.visit(app_url)
+ assert not browser.is_element_not_present_by_text("Complex")
+
+
+def test_is_element_present_by_value(browser, app_url):
+ "should is element present by value verify if element is present"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_value("async-header-value")
+
+
+def test_is_element_present_by_value_using_a_custom_wait_time(browser, app_url):
+ "should is element present by value verify if element is present using a custom wait time"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_value("async-header-value", wait_time=12)
+
+
+def test_is_element_present_by_value_returns_false_if_element_is_not_present(browser, app_url):
+ "should is element present by value returns False if element is not present"
+ browser.visit(app_url)
+ assert not browser.is_element_present_by_value("async-header-value")
+
+
+def test_is_element_not_present_by_value(browser, app_url):
+ "should is element not present by value verify if element is not present"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_value("async-header-value")
+
+
+def test_is_element_not_present_by_value_using_a_custom_wait_time(browser, app_url):
+ "should is element not present by value verify if element is not present using a custom wait time"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_value(
+ "async-header-value",
+ wait_time=12,
+ )
+
+
+def test_is_element_not_present_by_value_returns_false_if_element_is_present(browser, app_url):
+ "should is element not present by value returns False if element is present"
+ browser.visit(app_url)
+ assert not browser.is_element_not_present_by_value("default value")
+
+
+def test_is_element_present_by_id(browser, app_url):
+ "should is element present by id verify if element is present"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ result = browser.is_element_present_by_id("async-header", wait_time=20)
+ assert result
+
+
+def test_is_element_present_by_id_using_a_custom_wait_time(browser, app_url):
+ "should is element present by id verify if element is present using a custom wait time"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_id("async-header", wait_time=12)
+
+
+def test_is_element_present_by_id_returns_false_if_element_is_not_present(browser, app_url):
+ "should is element present by id returns False if element is not present"
+ browser.visit(app_url)
+ assert not browser.is_element_present_by_id("async-header")
+
+
+def test_is_element_not_present_by_id(browser, app_url):
+ "should is element not present by id verify if element is not present"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_id("async-header")
+
+
+def test_is_element_not_present_by_id_using_a_custom_wait_time(browser, app_url):
+ "should is element not present by id verify if element is not present using a custom wait time"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_id("async-header", wait_time=12)
+
+
+def test_is_element_not_present_by_id_returns_false_if_element_is_present(browser, app_url):
+ """should is_element_not_present_by_id returns False if element is present"""
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ browser.find_by_id("async-header")
+ assert not browser.is_element_not_present_by_id("async-header")
+
+
+def test_is_element_present_by_name(browser, app_url):
+ "should is element present by name verify if element is present"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_name("async-input")
+
+
+def test_is_element_present_by_name_using_a_custom_wait_time(browser, app_url):
+ "should is element present by name verify if element is present using a custom wait time"
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ assert browser.is_element_present_by_name("async-input", wait_time=12)
+
+
+def test_is_element_present_by_name_returns_false_if_element_is_not_present(browser, app_url):
+ "should is element present by name returns false if element is not present"
+ browser.visit(app_url)
+ assert not browser.is_element_present_by_name("async-input")
+
+
+def test_is_element_not_present_by_name(browser, app_url):
+ "should is element not present by name verify if element is not present"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_name("async-input")
+
+
+def test_is_element_not_present_by_name_using_a_custom_wait_time(browser, app_url):
+ "should is element not present by name verify if element is not present using a custom wait time"
+ browser.visit(app_url)
+ assert browser.is_element_not_present_by_name("async-input", wait_time=12)
+
+
+def test_is_element_not_present_by_name_returns_false_if_element_is_present(browser, app_url):
+ """should is_element_not_present_by_name returns False if element is present"""
+ browser.visit(app_url)
+ browser.find_by_css(".add-async-element").click()
+ browser.find_by_name("async-input")
+ assert not browser.is_element_not_present_by_name("async-input")
diff --git a/tests/tests_webdriver/test_javascript.py b/tests/tests_webdriver/test_javascript.py
new file mode 100644
index 000000000..9d086bfc3
--- /dev/null
+++ b/tests/tests_webdriver/test_javascript.py
@@ -0,0 +1,14 @@
+def test_can_execute_javascript(browser, app_url):
+ "should be able to execute javascript"
+ browser.visit(app_url)
+ browser.execute_script("$('body').empty()")
+ assert "" == browser.find_by_tag("body").value
+
+
+def test_can_evaluate_script(browser):
+ "should evaluate script"
+ assert 8 == browser.evaluate_script("4+4")
+
+
+def test_execute_script_returns_result_if_present(browser):
+ assert browser.execute_script("return 42") == 42
diff --git a/tests/tests_webdriver/test_mouse_interaction.py b/tests/tests_webdriver/test_mouse_interaction.py
index fa029f8b4..bccddf587 100644
--- a/tests/tests_webdriver/test_mouse_interaction.py
+++ b/tests/tests_webdriver/test_mouse_interaction.py
@@ -5,13 +5,11 @@
import pytest
-from tests.fake_webapp import EXAMPLE_APP
-
@pytest.mark.flaky
-def test_mouse_over(browser):
+def test_mouse_over(browser, app_url):
"Should be able to perform a mouse over on an element"
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
element = browser.find_by_css(".add-element-mouseover")
element.mouse_over()
@@ -26,9 +24,9 @@ def test_mouse_over(browser):
@pytest.mark.flaky
-def test_mouse_out(browser):
+def test_mouse_out(browser, app_url):
"Should be able to perform a mouse out on an element"
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
element = browser.find_by_css(".add-element-mouseover")
element.mouse_over()
@@ -38,11 +36,11 @@ def test_mouse_out(browser):
@pytest.mark.flaky
-def test_mouse_out_top_left(browser):
+def test_mouse_out_top_left(browser, app_url):
"""Should be able to perform a mouse out on an element,
even if the element is at the top left corner of the screen.
"""
- browser.visit(EXAMPLE_APP + "/mouse")
+ browser.visit(app_url + "/mouse")
element = browser.find_by_css(".add-element-mouseover")
element.mouse_over()
@@ -52,13 +50,13 @@ def test_mouse_out_top_left(browser):
@pytest.mark.flaky
-def test_double_click(browser):
+def test_double_click(browser, app_url):
"""Test: WebDriverElement.double_click()
When an element has an action activated by a double click
Then using the double_click() method will trigger it
"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
button = browser.find_by_css(".db-button", wait_time=10)
button.double_click()
@@ -73,9 +71,9 @@ def test_double_click(browser):
@pytest.mark.flaky
-def test_right_click(browser):
+def test_right_click(browser, app_url):
"should be able to perform a right click on an element"
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
element = browser.find_by_css(".right-clicable")
element.right_click()
@@ -88,11 +86,11 @@ def test_right_click(browser):
@pytest.mark.flaky
-def test_drag_and_drop(browser):
+def test_drag_and_drop(browser, app_url):
"""
should be able to perform a drag an element and drop in another element
"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
droppable = browser.find_by_css(".droppable")
draggable = browser.find_by_css(".draggable")
diff --git a/tests/tests_webdriver/test_popups.py b/tests/tests_webdriver/test_popups.py
index 99fbcdd59..149d31426 100644
--- a/tests/tests_webdriver/test_popups.py
+++ b/tests/tests_webdriver/test_popups.py
@@ -3,11 +3,9 @@
# license that can be found in the LICENSE file.
import time
-from tests.fake_webapp import EXAMPLE_APP
-
-def test_lists_all_windows_as_window_instances(browser):
- browser.visit(EXAMPLE_APP)
+def test_lists_all_windows_as_window_instances(browser, app_url):
+ browser.visit(app_url)
browser.find_by_id("open-popup").click()
@@ -25,14 +23,14 @@ def test_lists_all_windows_as_window_instances(browser):
assert window.name == handle
-def test_current_is_a_window_instance_pointing_to_current_window(browser):
- browser.visit(EXAMPLE_APP)
+def test_current_is_a_window_instance_pointing_to_current_window(browser, app_url):
+ browser.visit(app_url)
assert browser.windows.current.name == browser.driver.current_window_handle
-def test_set_current_to_window_instance_sets_current_window(browser):
- browser.visit(EXAMPLE_APP)
+def test_set_current_to_window_instance_sets_current_window(browser, app_url):
+ browser.visit(app_url)
browser.find_by_id("open-popup").click()
last_current_window = browser.windows.current
@@ -40,16 +38,16 @@ def test_set_current_to_window_instance_sets_current_window(browser):
assert browser.windows.current != last_current_window
-def test_next_prev_return_next_prev_windows(browser):
- browser.visit(EXAMPLE_APP)
+def test_next_prev_return_next_prev_windows(browser, app_url):
+ browser.visit(app_url)
browser.find_by_id("open-popup").click()
assert browser.windows.current.next == browser.windows.current.prev
assert browser.windows.current != browser.windows.current.next
-def test_is_current_returns_true_if_current_window_else_false(browser):
- browser.visit(EXAMPLE_APP)
+def test_is_current_returns_true_if_current_window_else_false(browser, app_url):
+ browser.visit(app_url)
browser.find_by_id("open-popup").click()
assert browser.windows.current.is_current
@@ -59,8 +57,8 @@ def test_is_current_returns_true_if_current_window_else_false(browser):
browser.windows.current.close_others()
-def test_set_is_current_to_true_sets_window_to_current(browser):
- browser.visit(EXAMPLE_APP)
+def test_set_is_current_to_true_sets_window_to_current(browser, app_url):
+ browser.visit(app_url)
browser.find_by_id("open-popup").click()
next_window = browser.windows.current.next
@@ -70,23 +68,23 @@ def test_set_is_current_to_true_sets_window_to_current(browser):
assert next_window.is_current
-def test_get_window_by_index(browser):
- browser.visit(EXAMPLE_APP)
+def test_get_window_by_index(browser, app_url):
+ browser.visit(app_url)
browser.find_by_id("open-popup").click()
assert browser.windows[0].name == browser.driver.window_handles[0]
-def test_get_window_by_name(browser):
- browser.visit(EXAMPLE_APP)
+def test_get_window_by_name(browser, app_url):
+ browser.visit(app_url)
browser.find_by_id("open-popup").click()
window_handle = browser.driver.window_handles[0]
assert browser.windows[window_handle].name == window_handle
-def test_close_closes_window(browser):
- browser.visit(EXAMPLE_APP)
+def test_close_closes_window(browser, app_url):
+ browser.visit(app_url)
browser.find_by_id("open-popup").click()
current = browser.windows.current
@@ -95,8 +93,8 @@ def test_close_closes_window(browser):
assert browser.windows.current == current
-def test_close_current_window_expect_previous_window_becomes_current(browser):
- browser.visit(EXAMPLE_APP)
+def test_close_current_window_expect_previous_window_becomes_current(browser, app_url):
+ browser.visit(app_url)
browser.find_by_id("open-popup").click()
prev = browser.windows.current
@@ -107,8 +105,8 @@ def test_close_current_window_expect_previous_window_becomes_current(browser):
assert browser.windows.current == prev
-def test_close_others_expect_close_all_other_open_windows(browser):
- browser.visit(EXAMPLE_APP)
+def test_close_others_expect_close_all_other_open_windows(browser, app_url):
+ browser.visit(app_url)
current = browser.windows.current
browser.find_by_id("open-popup").click()
diff --git a/tests/tests_webdriver/test_screenshot.py b/tests/tests_webdriver/test_screenshot.py
index 1d9437c4f..5262c00ce 100644
--- a/tests/tests_webdriver/test_screenshot.py
+++ b/tests/tests_webdriver/test_screenshot.py
@@ -7,89 +7,87 @@
import pytest
from selenium.common.exceptions import WebDriverException
-from tests.fake_webapp import EXAMPLE_APP
-
-def test_take_screenshot_no_unique_file(browser):
+def test_take_screenshot_no_unique_file(browser, app_url):
"""When the unique_file parameter is false,
Then the screenshot filename should match the name parameter exactly.
"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
browser.screenshot(name="test_screenshot", unique_file=False)
expected_filepath = os.path.abspath("test_screenshot.png")
assert os.path.isfile(expected_filepath)
-def test_take_screenshot(browser):
+def test_take_screenshot(browser, app_url):
"""Should take a screenshot of the current page"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
filename = browser.screenshot()
assert tempfile.gettempdir() in filename
-def test_take_screenshot_full_screen(browser):
+def test_take_screenshot_full_screen(browser, app_url):
"""Should take a full screen screenshot of the current page"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
filename = browser.screenshot(full=True)
assert tempfile.gettempdir() in filename
-def test_take_screenshot_with_prefix(browser):
+def test_take_screenshot_with_prefix(browser, app_url):
"""Should add the prefix to the screenshot file name"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
filename = browser.screenshot(name="foobar")
assert "foobar" in filename
-def test_take_screenshot_with_suffix(browser):
+def test_take_screenshot_with_suffix(browser, app_url):
"""Should add the suffix to the screenshot file name"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
filename = browser.screenshot(suffix=".png")
assert ".png" in filename[-4:]
-def test_take_element_screenshot(browser):
- browser.visit(EXAMPLE_APP)
+def test_take_element_screenshot(browser, app_url):
+ browser.visit(app_url)
elem = browser.find_by_tag("body")
filename = elem.screenshot()
assert tempfile.gettempdir() in filename
-def test_take_element_screenshot_with_prefix(browser):
+def test_take_element_screenshot_with_prefix(browser, app_url):
"""Should add the prefix to the screenshot file name"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
elem = browser.find_by_tag("body")
filename = elem.screenshot(name="foobar")
assert "foobar" in filename
-def test_take_element_screenshot_full_screen(browser):
+def test_take_element_screenshot_full_screen(browser, app_url):
"""Should resize the window before taking screenshot of the element"""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
elem = browser.find_by_tag("body")
filename = elem.screenshot(name="foobar", full=True)
assert tempfile.gettempdir() in filename
-def test_take_nested_element_screenshot(browser):
- browser.visit(EXAMPLE_APP)
+def test_take_nested_element_screenshot(browser, app_url):
+ browser.visit(app_url)
elem = browser.find_by_tag("body").find_by_css("h1")
filename = elem.screenshot()
assert tempfile.gettempdir() in filename
-def test_element_screenshot_zero_size(browser):
+def test_element_screenshot_zero_size(browser, app_url):
"""Elements with 0 width and 0 height should crash."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
elem = browser.find_by_id("zerodiv")
diff --git a/tests/tests_webdriver/test_shadow_root.py b/tests/tests_webdriver/test_shadow_root.py
index 1e6372cf1..181f2c38f 100644
--- a/tests/tests_webdriver/test_shadow_root.py
+++ b/tests/tests_webdriver/test_shadow_root.py
@@ -1,19 +1,18 @@
-from tests.fake_webapp import EXAMPLE_APP
from splinter.driver.webdriver import ShadowRootElement
-def test_shadow_root(browser):
+def test_shadow_root(browser, app_url):
"""The shadow_root property will return a ShadowRootElement."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
element = browser.find_by_id("has_shadow_root")
shadow_root = element.shadow_root
assert isinstance(shadow_root, ShadowRootElement)
-def test_shadow_root_element_find_by_css(browser):
+def test_shadow_root_element_find_by_css(browser, app_url):
"""ShadowRootElement implements ElementAPI.find_by_css."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
element = browser.find_by_id("has_shadow_root")
shadow_root = element.shadow_root
@@ -22,9 +21,9 @@ def test_shadow_root_element_find_by_css(browser):
assert "Inside a shadow root" == inner_element.value
-def test_shadow_root_element_find_by_name(browser):
+def test_shadow_root_element_find_by_name(browser, app_url):
"""ShadowRootElement implements ElementAPI.find_by_value."""
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
element = browser.find_by_id("has_shadow_root")
shadow_root = element.shadow_root
diff --git a/tests/tests_webdriver/test_slowly_type.py b/tests/tests_webdriver/test_slowly_type.py
new file mode 100644
index 000000000..35aadd369
--- /dev/null
+++ b/tests/tests_webdriver/test_slowly_type.py
@@ -0,0 +1,68 @@
+# Copyright 2012 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.
+import os
+
+import pytest
+
+
+xfail_if_safari = pytest.mark.xfail(
+ os.getenv("SAFARI"),
+ reason="Typing issues with safari need to be investigated.",
+)
+
+
+@xfail_if_safari
+def test_simple_type(browser, app_url):
+ """should provide a away to change field value using type method"""
+ browser.visit(app_url)
+ elem = browser.find_by_name("query")
+ elem.type(" with type method")
+ assert "default value with type method" == elem.value
+
+ browser.find_by_name("description").type("type into textarea")
+ value = browser.find_by_name("description").value
+ assert "type into textarea" == value
+
+
+@xfail_if_safari
+def test_simple_type_on_element(browser, app_url):
+ browser.visit(app_url)
+ elem = browser.find_by_name("query")
+ elem.type(" with type method")
+ assert "default value with type method" == elem.value
+
+ browser.find_by_name("description").type("type into textarea")
+ value = browser.find_by_name("description").value
+ assert "type into textarea" == value
+
+
+def test_slowly_typing(browser, app_url):
+ """should be able to slowly type some text in a field"""
+ for name in ["type-input", "type-textarea"]:
+ browser.visit(app_url + "type")
+ num = 0
+ num_max = 6
+ for key in browser.find_by_name(name).type("typing", slowly=True):
+ assert browser.is_text_present("#%d" % num)
+ num += 1
+ assert num == num_max
+
+ element = browser.find_by_name(name)
+ assert element.value == "typing"
+
+
+def test_slowly_typing_on_element(browser, app_url):
+ for name in ["type-input", "type-textarea"]:
+ browser.visit(app_url + "type")
+ num = 0
+ num_max = 6
+ text_input = browser.find_by_name(name)
+ typing = text_input.type("typing", slowly=True)
+ for key in typing:
+ assert browser.is_text_present("#%d" % num)
+ num += 1
+ assert num == num_max
+
+ element = browser.find_by_name(name)
+ assert element.value == "typing"
diff --git a/tests/tests_webdriver/test_user_agent.py b/tests/tests_webdriver/test_user_agent.py
new file mode 100644
index 000000000..a8283d243
--- /dev/null
+++ b/tests/tests_webdriver/test_user_agent.py
@@ -0,0 +1,23 @@
+import os
+
+import pytest
+
+from splinter.config import Config
+
+
+xfail_if_safari = pytest.mark.xfail(
+ os.getenv("SAFARI"),
+ reason="Safari issues need to be investigated.",
+)
+
+
+@pytest.fixture(scope="session")
+def browser_config():
+ return Config(user_agent="iphone", headless=True)
+
+
+@xfail_if_safari
+def test_should_be_able_to_change_user_agent(browser, app_url):
+ browser.visit(app_url + "useragent")
+
+ assert "iphone" in browser.html
diff --git a/tests/tests_webdriver/test_webdriver.py b/tests/tests_webdriver/test_webdriver.py
index 86b399d3d..c1738729d 100644
--- a/tests/tests_webdriver/test_webdriver.py
+++ b/tests/tests_webdriver/test_webdriver.py
@@ -2,38 +2,46 @@
import pathlib
import pytest
-from selenium.common.exceptions import WebDriverException
-from tests.fake_webapp import EXAMPLE_APP
+xfail_if_safari = pytest.mark.xfail(
+ os.getenv("SAFARI"),
+ reason="Safari issues need to be investigated.",
+)
-def test_webdriver_local_driver_not_present(browser_name):
- """When chromedriver/geckodriver are not present on the system."""
- from splinter import Browser
- from selenium.webdriver.chrome.service import Service as ChromeService
- from selenium.webdriver.firefox.service import Service as FirefoxService
+def test_default_wait_time(browser):
+ "should driver default wait time 2"
+ assert 2 == browser.wait_time
- if browser_name == "chrome":
- service = ChromeService(executable_path="failpath")
- else:
- service = FirefoxService(executable_path="failpath")
- with pytest.raises(WebDriverException):
- Browser(browser_name, service=service)
+def test_status_code(browser):
+ with pytest.raises(NotImplementedError):
+ browser.status_code
-def test_attach_file(request, browser):
- """Should provide a way to change file field value"""
- request.addfinalizer(browser.quit)
+def test_can_open_page_in_new_tab(browser, app_url):
+ """should be able to visit url in a new tab"""
+ browser.visit(app_url)
+ browser.windows.current.new_tab(app_url)
+ browser.windows[1].is_current = True
+ assert app_url == browser.url
+ assert 2 == len(browser.windows)
+ browser.windows[0].is_current = True
+ browser.windows[1].close()
+
+
+@xfail_if_safari
+def test_attach_file(request, browser, app_url):
+ """Should provide a way to change file field value"""
file_path = pathlib.Path(
os.getcwd(), # NOQA PTH109
"tests",
"mockfile.txt",
)
- browser.visit(EXAMPLE_APP)
+ browser.visit(app_url)
browser.attach_file("file", str(file_path))
browser.find_by_name("upload").click()
@@ -44,13 +52,13 @@ def test_attach_file(request, browser):
assert str(f.read()) in html
-def test_browser_config(request, browser_name):
+def test_browser_config(request, browser_name, browser_kwargs):
"""Splinter's drivers get the Config object when it's passed through the Browser function."""
from splinter import Config
from splinter import Browser
config = Config(user_agent="agent_smith", headless=True)
- browser = Browser(browser_name, config=config)
+ browser = Browser(browser_name, config=config, **browser_kwargs)
request.addfinalizer(browser.quit)
assert browser.config.user_agent == "agent_smith"
diff --git a/tests/tests_webdriver_local/test_local_driver_not_found.py b/tests/tests_webdriver_local/test_local_driver_not_found.py
new file mode 100644
index 000000000..a8ce6b421
--- /dev/null
+++ b/tests/tests_webdriver_local/test_local_driver_not_found.py
@@ -0,0 +1,24 @@
+import pytest
+
+from selenium.common.exceptions import WebDriverException
+
+
+def test_webdriver_local_driver_not_found(browser_name):
+ """When chromedriver/geckodriver/edgedriver are not present on the system."""
+ from splinter import Browser
+
+ if browser_name == "chrome":
+ from selenium.webdriver.chrome.service import Service as ChromeService
+
+ service = ChromeService(executable_path="failpath")
+ elif browser_name == "firefox":
+ from selenium.webdriver.firefox.service import Service as FirefoxService
+
+ service = FirefoxService(executable_path="failpath")
+ elif browser_name == "edge":
+ from selenium.webdriver.edge.service import Service as EdgeService
+
+ service = EdgeService(executable_path="failpath")
+
+ with pytest.raises(WebDriverException):
+ Browser(browser_name, service=service)
diff --git a/tests/tests_zope_testbrowser/conftest.py b/tests/tests_zope_testbrowser/conftest.py
new file mode 100644
index 000000000..0adf953b5
--- /dev/null
+++ b/tests/tests_zope_testbrowser/conftest.py
@@ -0,0 +1,6 @@
+import pytest
+
+
+@pytest.fixture()
+def browser_kwargs():
+ return {"wait_time": 0.1}
diff --git a/tests/tests_zope_testbrowser/test_cookies_zope.py b/tests/tests_zope_testbrowser/test_cookies_zope.py
new file mode 100644
index 000000000..91dc0402b
--- /dev/null
+++ b/tests/tests_zope_testbrowser/test_cookies_zope.py
@@ -0,0 +1,7 @@
+def test_cookies_extra_parameters(browser, app_url):
+ """Cookie can be created with extra parameters."""
+ browser.visit(app_url)
+ comment = "Ipsum lorem"
+ browser.cookies.add({"sha": "zam"}, comment=comment)
+ cookie = browser._browser.cookies.getinfo("sha")
+ assert "Ipsum%20lorem" == cookie["comment"]
diff --git a/tests/tests_zope_testbrowser/test_fill_form.py b/tests/tests_zope_testbrowser/test_fill_form.py
new file mode 100644
index 000000000..3f13c2309
--- /dev/null
+++ b/tests/tests_zope_testbrowser/test_fill_form.py
@@ -0,0 +1,13 @@
+# Copyright 2013 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.
+import pytest
+
+
+def test_fill_form_missing_values(browser, app_url):
+ """Missing values should raise an error."""
+ browser.visit(app_url)
+ with pytest.raises(LookupError):
+ browser.fill_form(
+ {"query": "new query", "missing_form": "doesn't exist"},
+ )
diff --git a/tests/type.py b/tests/type.py
deleted file mode 100644
index 686618607..000000000
--- a/tests/type.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# Copyright 2012 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 .fake_webapp import EXAMPLE_APP
-
-
-class SlowlyTypeTest:
- def test_simple_type(self):
- """should provide a away to change field value using type method"""
- self.browser.visit(EXAMPLE_APP)
- elem = self.browser.find_by_name("query")
- elem.type(" with type method")
- assert "default value with type method" == elem.value
-
- self.browser.find_by_name("description").type("type into textarea")
- value = self.browser.find_by_name("description").value
- assert "type into textarea" == value
-
- def test_simple_type_on_element(self):
- self.browser.visit(EXAMPLE_APP)
- elem = self.browser.find_by_name("query")
- elem.type(" with type method")
- assert "default value with type method" == elem.value
-
- self.browser.find_by_name("description").type("type into textarea")
- value = self.browser.find_by_name("description").value
- assert "type into textarea" == value
-
- def test_slowly_typing(self):
- """should be able to slowly type some text in a field"""
- for name in ["type-input", "type-textarea"]:
- self.browser.visit(EXAMPLE_APP + "type")
- num = 0
- num_max = 6
- for key in self.browser.find_by_name(name).type("typing", slowly=True):
- assert self.browser.is_text_present("#%d" % num)
- num += 1
- assert num == num_max
-
- element = self.browser.find_by_name(name)
- assert element.value == "typing"
-
- def test_slowly_typing_on_element(self):
- for name in ["type-input", "type-textarea"]:
- self.browser.visit(EXAMPLE_APP + "type")
- num = 0
- num_max = 6
- text_input = self.browser.find_by_name(name)
- typing = text_input.type("typing", slowly=True)
- for key in typing:
- assert self.browser.is_text_present("#%d" % num)
- num += 1
- assert num == num_max
-
- element = self.browser.find_by_name(name)
- assert element.value == "typing"
diff --git a/tox.ini b/tox.ini
index b3718e620..2961a2e0d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,51 +1,77 @@
[testenv:tests_splinter]
-extras = zope.testbrowser, django, flask
deps = -rrequirements/test.txt
commands =
- pytest --ignore-flaky -v {posargs} tests/tests_splinter
+ pytest --ignore-flaky {posargs} tests/tests_splinter
-[testenv:tests_lxml_drivers]
-extras = zope.testbrowser, django, flask
+[testenv:tests_django]
+extras = django
deps = -rrequirements/test.txt
commands =
- pytest --ignore-flaky -v {posargs} tests/test_flaskclient.py tests/test_zopetestbrowser.py tests/test_djangoclient.py tests/test_is_element_present_nojs.py
+ pytest --ignore-flaky {posargs} --browser=django tests/test_all_drivers tests/test_all_lxml_drivers tests/tests_django
+
+[testenv:tests_flask]
+extras = flask
+deps = -rrequirements/test.txt
+commands =
+ pytest --ignore-flaky {posargs} --browser=flask tests/test_all_drivers tests/test_all_lxml_drivers tests/tests_flask
+
+[testenv:tests_zopetestbrowser]
+extras = zope.testbrowser
+deps = -rrequirements/test.txt
+setenv =
+ ZOPE = True
+commands =
+ pip install -e .[zope.testbrowser]
+ pytest --ignore-flaky {posargs} --browser=zope.testbrowser tests/test_all_drivers tests/test_all_lxml_drivers tests/tests_zope_testbrowser
[testenv:tests_selenium_firefox]
extras = selenium
deps =
-rrequirements/test.txt
commands =
- pytest --ignore-flaky -m "not macos" -v {posargs} --browser=firefox tests/tests_firefox_webdriver tests/tests_webdriver tests/test_webdriver_firefox.py
+ pytest --ignore-flaky {posargs} --browser=firefox tests/test_all_drivers tests/tests_webdriver tests/tests_webdriver_local tests/tests_firefox_webdriver
+ pytest --ignore-flaky {posargs} --browser=firefox --webdriver-fullscreen True tests/test_all_drivers tests/tests_webdriver tests/tests_webdriver_local tests/tests_firefox_webdriver
[testenv:tests_selenium_chrome]
extras = selenium
deps =
-rrequirements/test.txt
commands =
- pytest --ignore-flaky -m "not macos" -v {posargs} --browser=chrome tests/tests_webdriver tests/test_webdriver_chrome.py
+ pytest --ignore-flaky {posargs} --browser=chrome tests/test_all_drivers tests/tests_webdriver tests/tests_webdriver_local
+ pytest --ignore-flaky {posargs} --browser=chrome --webdriver-fullscreen True tests/test_all_drivers tests/tests_webdriver tests/tests_webdriver_local
-[testenv:tests_selenium_remote]
+[testenv:tests_selenium_edge]
+extras = selenium
+deps =
+ -rrequirements\test_windows.txt
+passenv =
+ EDGEWEBDRIVER
+commands =
+ pytest --ignore-flaky {posargs} --browser=edge tests/test_all_drivers tests/tests_webdriver tests/tests_webdriver_local
+ pytest --ignore-flaky {posargs} --browser=edge --webdriver-fullscreen True tests/test_all_drivers tests/tests_webdriver tests/tests_webdriver_local
+
+[testenv:tests_selenium_remote_chrome]
extras = selenium
deps =
-rrequirements/test.txt
commands =
- pytest --ignore-flaky -m "not macos" -v {posargs} tests/test_webdriver_remote.py
+ pytest --ignore-flaky {posargs} --browser=remote --webdriver-remote-name=chrome tests/test_all_drivers tests/tests_webdriver
-[testenv:tests_selenium_edge]
+[testenv:tests_selenium_remote_firefox]
extras = selenium
deps =
- -rrequirements\test_windows.txt
-passenv =
- EDGEWEBDRIVER
+ -rrequirements/test.txt
commands =
- pytest --ignore-flaky -v {posargs} --browser=edge tests/tests_webdriver tests/test_webdriver_edge_chromium.py
+ pytest --ignore-flaky {posargs} --browser=remote --webdriver-remote-name=firefox tests/test_all_drivers tests/tests_webdriver
-[testenv:tests_selenium_safari]
+[testenv:tests_selenium_remote_safari]
extras = selenium
+setenv =
+ SAFARI = True
deps =
-rrequirements/test.txt
commands =
- pytest --ignore-flaky -m macos -v {posargs}
+ pytest --ignore-flaky {posargs} --browser=remote --webdriver-remote-name=safari tests/test_all_drivers tests/tests_webdriver
[testenv:build_docs]
allowlist_externals = make