Skip to content

Commit

Permalink
Add acceptmobile task.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed Jan 7, 2025
1 parent dd27d7f commit 7aa75c1
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ markers =
# that has access to the configured app and context,
# I'm just using some markers to reset/wipe the dev db.
dbreset: cli hack to wipe the dev db and set the LoadDemoData flag

mobile: acceptance tests using a mobile browser
82 changes: 69 additions & 13 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,13 @@ def print_subproc_output(pipe, label):
raise RuntimeError("tests failed")


@task(
pre=[_ensure_test_db],
help={
"port": "optional port to run on; creates server if needed.",
"show": "print data",
"noheadless": "run as non-headless (default is headless, i.e. not shown)",
"kflag": "optional -k flag argument",
"exitfirst": "exit on first failure",
"verbose": "make verbose",
},
)
def accept( # pylint: disable=too-many-arguments,too-many-positional-arguments
def _run_acceptance( # pylint: disable=too-many-arguments,too-many-positional-arguments
c,
port=5001,
show=False,
noheadless=False,
kflag=None,
mobile=False,
exitfirst=False,
verbose=False,
):
Expand Down Expand Up @@ -206,10 +196,75 @@ def accept( # pylint: disable=too-many-arguments,too-many-positional-arguments
run_test.append("--exitfirst")
if verbose:
run_test.append("-vv")
if mobile:
run_test.append("-m mobile")
run_test.append("--mobile")

_run_browser_tests(c, 5001, run_test)


acceptance_help = {
"port": "optional port to run on; creates server if needed.",
"show": "print data",
"noheadless": "run as non-headless (default is headless, i.e. not shown)",
"kflag": "optional -k flag argument",
"exitfirst": "exit on first failure",
"verbose": "make verbose",
}


@task(
pre=[_ensure_test_db],
help=acceptance_help,
)
def accept( # pylint: disable=too-many-arguments,too-many-positional-arguments
c,
port=5001,
show=False,
noheadless=False,
kflag=None,
exitfirst=False,
verbose=False,
):
"Run acceptance tests, full browser."
_run_acceptance( # pylint: disable=too-many-arguments,too-many-positional-arguments
c,
port=port,
show=show,
noheadless=noheadless,
kflag=kflag,
mobile=False,
exitfirst=exitfirst,
verbose=verbose,
)


@task(
pre=[_ensure_test_db],
help=acceptance_help,
)
def acceptmobile( # pylint: disable=too-many-arguments,too-many-positional-arguments
c,
port=5001,
show=False,
noheadless=False,
kflag=None,
exitfirst=False,
verbose=False,
):
"Run acceptance tests, mobile emulation, tests marked @mobile."
_run_acceptance( # pylint: disable=too-many-arguments,too-many-positional-arguments
c,
port=port,
show=show,
noheadless=noheadless,
kflag=kflag,
mobile=True,
exitfirst=exitfirst,
verbose=verbose,
)


@task(pre=[_ensure_test_db])
def playwright(c):
"""
Expand Down Expand Up @@ -246,7 +301,7 @@ def black(c):
c.run("python -m black .")


@task(pre=[test, accept, playwright])
@task(pre=[test, accept, acceptmobile, playwright])
def fulltest(c): # pylint: disable=unused-argument
"""
Run full tests check.
Expand All @@ -269,6 +324,7 @@ def full(c): # pylint: disable=unused-argument
ns.add_task(lint_changed)
ns.add_task(test)
ns.add_task(accept)
ns.add_task(acceptmobile)
ns.add_task(playwright)
ns.add_task(coverage)
ns.add_task(todos)
Expand Down
2 changes: 2 additions & 0 deletions tests/acceptance/book.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Feature: Books and stats are available
## And the reading pane shows:
## Hola/. /Tengo/ /un/ /perro/.

@mobile
Scenario: I can import text.
Given I visit "/"
Given a Spanish book "Hola" with content:
Expand All @@ -30,6 +31,7 @@ Feature: Books and stats are available
And the reading pane shows:
Hola/. /Tengo/ /un/ /gato/.

@mobile
Scenario: I can import a text file.
Given I visit "/"
Given a Spanish book "Hola" from file hola.txt
Expand Down
14 changes: 14 additions & 0 deletions tests/acceptance/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def pytest_addoption(parser):
"""
parser.addoption("--port", action="store", type=int, help="Specify the port number")
parser.addoption("--headless", action="store_true", help="Run the test as headless")
parser.addoption("--mobile", action="store_true", help="Run tests tagged @mobile")


@pytest.fixture(name="_environment_check", scope="session")
Expand Down Expand Up @@ -104,6 +105,19 @@ def session_chrome_browser(request, _environment_check):
# how-can-i-set-the-browser-window-size-when-using-google-chrome-headless
chrome_options.add_argument("window-size=1920,1080")

mobile = request.config.getoption("--mobile")
if mobile:
useragent = [
"Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D)",
"AppleWebKit/535.19 (KHTML, like Gecko)",
"Chrome/18.0.1025.166 Mobile Safari/535.19",
]
mobile_emulation = {
"deviceMetrics": {"width": 375, "height": 812, "pixelRatio": 3.0},
"userAgent": " ".join(useragent),
}
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)

# Initialize the browser with ChromeOptions
browser = Browser("chrome", options=chrome_options)

Expand Down
2 changes: 2 additions & 0 deletions tests/acceptance/reading.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Feature: User can actually read and stuff.
And demo languages


@mobile
Scenario: Book elements are rendered correctly
Given a Spanish book "Hola" with content:
Hola. Adios amigo.
Expand All @@ -15,6 +16,7 @@ Feature: User can actually read and stuff.
Hola/. /Adios/ /amigo/.


@mobile
Scenario: Updating term status updates the reading frame
Given a Spanish book "Hola" with content:
Hola. Adios amigo.
Expand Down

0 comments on commit 7aa75c1

Please sign in to comment.