From 2ee66e5ca24964d5e396080694ee0254e2dc43e7 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Wed, 2 Oct 2024 15:34:49 +0000 Subject: [PATCH 1/3] chore: proof of concept changes to install playwright --- .devcontainer/Dockerfile | 8 ++++++++ pyproject.toml | 2 ++ test_example.py | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 test_example.py diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 855659a66b..c976e25ca3 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -9,6 +9,14 @@ USER $USER # install devcontainer requirements RUN pip install -e .[dev,test] +# USER root +# RUN pip install playwright +# RUN pip install pytest-playwright playwright -U +# RUN playwright install-deps + +# USER $USER +# RUN playwright install + # docs requirements are in a separate file for the GitHub Action COPY docs/requirements.txt docs/requirements.txt RUN pip install -r docs/requirements.txt diff --git a/pyproject.toml b/pyproject.toml index ce729d2ef3..dcbb4b22a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,8 +33,10 @@ dev = [ test = [ "coverage", "pytest", + "playwright", "pytest-django", "pytest-mock", + "pytest-playwright", "pytest-socket", ] diff --git a/test_example.py b/test_example.py new file mode 100644 index 0000000000..b05b15dabb --- /dev/null +++ b/test_example.py @@ -0,0 +1,21 @@ +import re +from playwright.sync_api import Page, expect + + +def test_has_title(page: Page): + page.goto("https://dev-benefits.calitp.org/") + + # Expect a title "to contain" a substring. + expect(page).to_have_title(re.compile("Cal-ITP")) + + +def test_get_started_link(page: Page): + page.goto("https://dev-benefits.calitp.org/") + + # Click the Choose your provider link. + page.get_by_text("Choose your provider").click() + + page.get_by_text("California State Transit (dev)").click() + + # # Expects page to have a heading with the name of Installation. + # expect(page.get("heading", name="Installation")).to_be_visible() From 640083fe2e9a07a50d1ac87ff73b42525b03cc4a Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Tue, 8 Oct 2024 22:41:12 +0000 Subject: [PATCH 2/3] chore: tweaks for workshop session --- .devcontainer/Dockerfile | 11 +++++------ run_playwright.sh | 21 +++++++++++++++++++++ test_example.py | 8 ++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 run_playwright.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index c976e25ca3..c92116de11 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -9,13 +9,12 @@ USER $USER # install devcontainer requirements RUN pip install -e .[dev,test] -# USER root -# RUN pip install playwright -# RUN pip install pytest-playwright playwright -U -# RUN playwright install-deps +USER root +RUN pip install pytest-playwright playwright -U +RUN playwright install-deps -# USER $USER -# RUN playwright install +USER $USER +RUN playwright install # docs requirements are in a separate file for the GitHub Action COPY docs/requirements.txt docs/requirements.txt diff --git a/run_playwright.sh b/run_playwright.sh new file mode 100644 index 0000000000..89a57a8f0b --- /dev/null +++ b/run_playwright.sh @@ -0,0 +1,21 @@ +# Basic command (runs Chromium) + +pytest -k test_example --headed --slowmo 1000 + +# (From here, run second test only in the interest of time) + +# Use --browser to run with a different browser + +# pytest -k test_get_started_link --headed --browser firefox + +# Use --device to run with different viewports + +# pytest -k test_get_started_link --headed --device "iPhone 13" + +# Run in debug mode (https://playwright.dev/python/docs/running-tests#debugging-tests) + +# PWDEBUG=1 pytest -s -k test_get_started_link + +# More CLI options: +# https://playwright.dev/python/docs/test-runners +# https://playwright.dev/python/docs/running-tests#command-line diff --git a/test_example.py b/test_example.py index b05b15dabb..dbf2900c55 100644 --- a/test_example.py +++ b/test_example.py @@ -17,5 +17,13 @@ def test_get_started_link(page: Page): page.get_by_text("California State Transit (dev)").click() + page.get_by_label("Medicare Cardholder").click() + + page.get_by_text("Choose this benefit").click() + + page.get_by_text("Continue to Medicare.gov").click() + + page.wait_for_timeout(5000) + # # Expects page to have a heading with the name of Installation. # expect(page.get("heading", name="Installation")).to_be_visible() From 4912128e7fb4d6728991aeda1e54b7697897e66a Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Wed, 9 Oct 2024 15:06:37 +0000 Subject: [PATCH 3/3] chore: avoid error about cypress module not being found --- tests/cypress/cypress.config.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/cypress/cypress.config.js b/tests/cypress/cypress.config.js index 55296b755d..6a9a4a82ab 100644 --- a/tests/cypress/cypress.config.js +++ b/tests/cypress/cypress.config.js @@ -1,6 +1,4 @@ -const { defineConfig } = require("cypress"); - -module.exports = defineConfig({ +module.exports = { downloadsFolder: "downloads", fixturesFolder: "fixtures", screenshotsFolder: "screenshots", @@ -15,5 +13,6 @@ module.exports = defineConfig({ }, specPattern: "specs/**/*.cy.{js,jsx,ts,tsx}", supportFile: false, + baseUrl: "http://localhost:11369", }, -}); +};