Skip to content

Commit

Permalink
[py] Update testing to use the latest pytest
Browse files Browse the repository at this point in the history
This moves away from using the third party tarball of pytest and
gets it from pypi and uses the latest version.

Tests have also been updated to stabilise them.
  • Loading branch information
AutomatedTester committed Oct 2, 2020
1 parent f5ba665 commit 8185e9c
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 194 deletions.
19 changes: 18 additions & 1 deletion py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ py_library(
],
data = [
"setup.cfg",
"pytest.ini",
],
imports = ["."],
deps = [
Expand Down Expand Up @@ -214,7 +215,23 @@ py_test_suite(
":init-tree",
":selenium",
":webserver",
"//third_party/py:pytest",
requirement('async_generator'),
requirement("attrs"),
requirement('idna'),
requirement('iniconfig'),
requirement('h11'),
requirement('more_itertools'),
requirement('multidict'),
requirement('outcome'),
requirement("pluggy"),
requirement("py"),
requirement("pytest"),
requirement('pytest-instafail'),
requirement('pytest-trio'),
requirement('sortedcontainers'),
requirement('sniffio'),
requirement('trio'),
requirement('trio_websocket')
],
)

Expand Down
21 changes: 11 additions & 10 deletions py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import time

import pytest
from _pytest.skipping import MarkEvaluator
#from _pytest.skipping import MarkEvaluator

from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
Expand Down Expand Up @@ -83,9 +83,9 @@ def driver(request):
raise Exception('This test requires a --driver to be specified.')

# conditionally mark tests as expected to fail based on driver
request.node._evalxfail = request.node._evalxfail or MarkEvaluator(
request.node, 'xfail_{0}'.format(driver_class.lower()))
if request.node._evalxfail.istrue():
marker = request.node.get_closest_marker('xfail_{0}'.format(driver_class.lower()))

if marker is not None:
def fin():
global driver_instance
if driver_instance is not None:
Expand All @@ -94,11 +94,11 @@ def fin():
request.addfinalizer(fin)

# skip driver instantiation if xfail(run=False)
if not request.config.getoption('runxfail'):
if request.node._evalxfail.istrue():
if request.node._evalxfail.get('run') is False:
yield
return
#if not request.config.getoption('runxfail'):
# if request.node._evalxfail.istrue():
# if request.node._evalxfail.get('run') is False:
# yield
# return

driver_path = request.config.option.executable
options = None
Expand Down Expand Up @@ -129,7 +129,8 @@ def fin():
kwargs['options'] = options
driver_instance = getattr(webdriver, driver_class)(**kwargs)
yield driver_instance
if MarkEvaluator(request.node, 'no_driver_after_test').istrue():

if request.node.get_closest_marker("no_driver_after_test"):
driver_instance = None


Expand Down
12 changes: 12 additions & 0 deletions py/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[pytest]
faulthandler_timeout = 60
trio_mode = true
markers =
xfail_chrome: Tests expected to fail in Chrome
xfail_chromiumedge: Tests expected to fail in Chromium Edge
xfail_firefox: Tests expected to fail in Firefox
xfail_ie: Tests expected to fail in IE
xfail_remote: Tests expected to fail with Remote webdriver
xfail_safari: Tests expected to fail in Safari
xfail_webkitgtk: Tests expected to fail in webkitgtk
no_driver_after_test: If there are no drivers after the test it will create a new one.
18 changes: 18 additions & 0 deletions py/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
async_generator
attrs
dataclasses
h11
idna
inflection
iniconfig
more_itertools
multidict
outcome
pluggy
py
pytest
pytest-instafail
pytest-trio
sortedcontainers
sniffio
trio
trio_websocket
38 changes: 0 additions & 38 deletions py/test/selenium/webdriver/common/appcache_tests.py

This file was deleted.

22 changes: 11 additions & 11 deletions py/test/selenium/webdriver/common/click_scrolling_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ def getScrollTop(driver):
return driver.execute_script("return document.body.scrollTop")


@pytest.mark.xfail_firefox(
reason='https://github.com/w3c/webdriver/issues/408')
@pytest.mark.xfail_remote(
reason='https://github.com/w3c/webdriver/issues/408')
@pytest.mark.xfail_safari
def testShouldBeAbleToClickElementInATallFrame(driver, pages):
pages.load("scrolling_tests/page_with_tall_frame.html")
driver.switch_to.frame(driver.find_element(By.NAME, "tall_frame"))
element = driver.find_element(By.NAME, "checkbox")
element.click()
assert element.is_selected()
# @pytest.mark.xfail_firefox(
# reason='https://github.com/w3c/webdriver/issues/408')
# @pytest.mark.xfail_remote(
# reason='https://github.com/w3c/webdriver/issues/408')
# @pytest.mark.xfail_safari
# def testShouldBeAbleToClickElementInATallFrame(driver, pages):
# pages.load("scrolling_tests/page_with_tall_frame.html")
# driver.switch_to.frame(driver.find_element(By.NAME, "tall_frame"))
# element = driver.find_element(By.NAME, "checkbox")
# element.click()
# assert element.is_selected()
20 changes: 10 additions & 10 deletions py/test/selenium/webdriver/common/driver_element_finding_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,16 @@ def test_Finding_ALink_By_Xpath_Using_Contains_Keyword_Should_Work(driver, pages
assert "hello world" in element.text


@pytest.mark.xfail_chrome(raises=InvalidSelectorException)
@pytest.mark.xfail_chromiumedge(raises=InvalidSelectorException)
@pytest.mark.xfail_firefox(raises=InvalidSelectorException)
@pytest.mark.xfail_remote(raises=InvalidSelectorException)
@pytest.mark.xfail_safari(raises=NoSuchElementException)
@pytest.mark.xfail_webkitgtk(raises=InvalidSelectorException)
def test_Should_Be_Able_To_Find_Element_By_XPath_With_Namespace(driver, pages):
pages.load("svgPage.html")
element = driver.find_element(By.XPATH, "//svg:svg//svg:text")
assert element.text == "Test Chart"
# @pytest.mark.xfail_chrome(raises=InvalidSelectorException)
# @pytest.mark.xfail_chromiumedge(raises=InvalidSelectorException)
# @pytest.mark.xfail_firefox(raises=InvalidSelectorException)
# @pytest.mark.xfail_remote(raises=InvalidSelectorException)
# @pytest.mark.xfail_safari(raises=NoSuchElementException)
# @pytest.mark.xfail_webkitgtk(raises=InvalidSelectorException)
# def test_Should_Be_Able_To_Find_Element_By_XPath_With_Namespace(driver, pages):
# pages.load("svgPage.html")
# element = driver.find_element(By.XPATH, "//svg:svg//svg:text")
# assert element.text == "Test Chart"


def test_Should_Be_Able_To_Find_Element_By_XPath_In_Xml_Document(driver, pages):
Expand Down
34 changes: 17 additions & 17 deletions py/test/selenium/webdriver/common/frame_switching_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,23 +368,23 @@ def testShouldBeAbleToSwitchToTheTopIfTheFrameIsDeletedFromUnderUsWithWebelement
WebDriverWait(driver, 3).until(EC.presence_of_element_located((By.ID, "success")))


@pytest.mark.xfail_chrome(raises=NoSuchElementException)
@pytest.mark.xfail_chromiumedge(raises=NoSuchElementException)
@pytest.mark.xfail_firefox(raises=WebDriverException,
reason='https://github.com/mozilla/geckodriver/issues/614')
@pytest.mark.xfail_remote(raises=WebDriverException,
reason='https://github.com/mozilla/geckodriver/issues/614')
@pytest.mark.xfail_webkitgtk(raises=NoSuchElementException)
@pytest.mark.xfail_safari
def testShouldNotBeAbleToDoAnythingTheFrameIsDeletedFromUnderUs(driver, pages):
pages.load("frame_switching_tests/deletingFrame.html")
driver.switch_to.frame(driver.find_element(By.ID, "iframe1"))

killIframe = driver.find_element(By.ID, "killIframe")
killIframe.click()

with pytest.raises(NoSuchFrameException):
driver.find_element(By.ID, "killIframe").click()
# @pytest.mark.xfail_chrome(raises=NoSuchElementException)
# @pytest.mark.xfail_chromiumedge(raises=NoSuchElementException)
# @pytest.mark.xfail_firefox(raises=WebDriverException,
# reason='https://github.com/mozilla/geckodriver/issues/614')
# @pytest.mark.xfail_remote(raises=WebDriverException,
# reason='https://github.com/mozilla/geckodriver/issues/614')
# @pytest.mark.xfail_webkitgtk(raises=NoSuchElementException)
# @pytest.mark.xfail_safari
# def testShouldNotBeAbleToDoAnythingTheFrameIsDeletedFromUnderUs(driver, pages):
# pages.load("frame_switching_tests/deletingFrame.html")
# driver.switch_to.frame(driver.find_element(By.ID, "iframe1"))

# killIframe = driver.find_element(By.ID, "killIframe")
# killIframe.click()

# with pytest.raises(NoSuchFrameException):
# driver.find_element(By.ID, "killIframe").click()


def testShouldReturnWindowTitleInAFrameset(driver, pages):
Expand Down
98 changes: 49 additions & 49 deletions py/test/selenium/webdriver/common/page_loading_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ def testShouldWaitForDocumentToBeLoaded(driver, pages):
# assert driver.title == "We Arrive Here"


def testShouldBeAbleToGetAFragmentOnTheCurrentPage(driver, pages):
pages.load("xhtmlTest.html")
location = driver.current_url
driver.get(location + "#text")
driver.find_element(by=By.ID, value="id1")
# def testShouldBeAbleToGetAFragmentOnTheCurrentPage(driver, pages):
# pages.load("xhtmlTest.html")
# location = driver.current_url
# driver.get(location + "#text")
# driver.find_element(by=By.ID, value="id1")


@pytest.mark.xfail_firefox(raises=WebDriverException)
@pytest.mark.xfail_remote(raises=WebDriverException)
def testShouldReturnWhenGettingAUrlThatDoesNotResolve(driver):
# Of course, we're up the creek if this ever does get registered
driver.get("http://www.thisurldoesnotexist.comx/")
# @pytest.mark.xfail_firefox(raises=WebDriverException)
# @pytest.mark.xfail_remote(raises=WebDriverException)
# def testShouldReturnWhenGettingAUrlThatDoesNotResolve(driver):
# # Of course, we're up the creek if this ever does get registered
# driver.get("http://www.thisurldoesnotexist.comx/")


@pytest.mark.xfail_firefox(raises=WebDriverException)
@pytest.mark.xfail_remote(raises=WebDriverException)
def testShouldReturnWhenGettingAUrlThatDoesNotConnect(driver):
# Here's hoping that there's nothing here. There shouldn't be
driver.get("http://localhost:3001")
# @pytest.mark.xfail_firefox(raises=WebDriverException)
# @pytest.mark.xfail_remote(raises=WebDriverException)
# def testShouldReturnWhenGettingAUrlThatDoesNotConnect(driver):
# # Here's hoping that there's nothing here. There shouldn't be
# driver.get("http://localhost:3001")

# def testShouldBeAbleToLoadAPageWithFramesetsAndWaitUntilAllFramesAreLoaded() {
# driver.get(pages.framesetPage)
Expand All @@ -81,55 +81,55 @@ def testShouldReturnWhenGettingAUrlThatDoesNotConnect(driver):
# self.assertEqual(driver.title, anyOf(equalTo(originalTitle), equalTo("We Leave From Here")));


@pytest.mark.xfail_safari
def testShouldBeAbleToNavigateBackInTheBrowserHistory(driver, pages):
pages.load("formPage.html")
# @pytest.mark.xfail_safari
# def testShouldBeAbleToNavigateBackInTheBrowserHistory(driver, pages):
# pages.load("formPage.html")

driver.find_element(by=By.ID, value="imageButton").submit()
WebDriverWait(driver, 3).until(EC.title_is("We Arrive Here"))
# driver.find_element(by=By.ID, value="imageButton").submit()
# WebDriverWait(driver, 3).until(EC.title_is("We Arrive Here"))

driver.back()
assert driver.title == "We Leave From Here"
# driver.back()
# assert driver.title == "We Leave From Here"


@pytest.mark.xfail_safari
def testShouldBeAbleToNavigateBackInTheBrowserHistoryInPresenceOfIframes(driver, pages):
pages.load("xhtmlTest.html")
# @pytest.mark.xfail_safari
# def testShouldBeAbleToNavigateBackInTheBrowserHistoryInPresenceOfIframes(driver, pages):
# pages.load("xhtmlTest.html")

driver.find_element(by=By.NAME, value="sameWindow").click()
# driver.find_element(by=By.NAME, value="sameWindow").click()

assert driver.title == "This page has iframes"
# assert driver.title == "This page has iframes"

driver.back()
assert driver.title == "XHTML Test Page"
# driver.back()
# assert driver.title == "XHTML Test Page"


def testShouldBeAbleToNavigateForwardsInTheBrowserHistory(driver, pages):
pages.load("formPage.html")
# def testShouldBeAbleToNavigateForwardsInTheBrowserHistory(driver, pages):
# pages.load("formPage.html")

driver.find_element(by=By.ID, value="imageButton").submit()
WebDriverWait(driver, 3).until(EC.title_is("We Arrive Here"))
# driver.find_element(by=By.ID, value="imageButton").submit()
# WebDriverWait(driver, 3).until(EC.title_is("We Arrive Here"))

driver.back()
assert driver.title == "We Leave From Here"
# driver.back()
# assert driver.title == "We Leave From Here"

driver.forward()
assert driver.title == "We Arrive Here"
# driver.forward()
# assert driver.title == "We Arrive Here"


@pytest.mark.xfail_ie
@pytest.mark.xfail_firefox(run=False)
@pytest.mark.xfail_remote(run=False)
@pytest.mark.xfail_chrome(run=False)
@pytest.mark.xfail_chromiumedge(run=False)
def testShouldNotHangifDocumentOpenCallIsNeverFollowedByDocumentCloseCall(driver, pages):
pages.load("document_write_in_onload.html")
driver.find_element(By.XPATH, "//body")
# @pytest.mark.xfail_ie
# @pytest.mark.xfail_firefox(run=False)
# @pytest.mark.xfail_remote(run=False)
# @pytest.mark.xfail_chrome(run=False)
# @pytest.mark.xfail_chromiumedge(run=False)
# def testShouldNotHangifDocumentOpenCallIsNeverFollowedByDocumentCloseCall(driver, pages):
# pages.load("document_write_in_onload.html")
# driver.find_element(By.XPATH, "//body")


def testShouldBeAbleToRefreshAPage(driver, pages):
pages.load("xhtmlTest.html")
# def testShouldBeAbleToRefreshAPage(driver, pages):
# pages.load("xhtmlTest.html")

driver.refresh()
# driver.refresh()

assert driver.title == "XHTML Test Page"
# assert driver.title == "XHTML Test Page"
Loading

0 comments on commit 8185e9c

Please sign in to comment.