Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial playwright setup #1665

Merged
merged 79 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
3601e04
initial playwright setup
kcpevey Feb 28, 2023
635d99b
[pre-commit.ci] Apply automatic pre-commit fixes
pre-commit-ci[bot] Feb 28, 2023
304c288
update run notebook test, working well now
kcpevey Mar 9, 2023
d4f30f7
[pre-commit.ci] Apply automatic pre-commit fixes
pre-commit-ci[bot] Mar 9, 2023
bd4e939
add notebook for testing, clean up CI
kcpevey Mar 20, 2023
78e7fc4
Merge branch 'develop' into add_playwright
kcpevey Mar 20, 2023
481e788
use the right dotenv
kcpevey Mar 20, 2023
a57f3c4
run playwright tests under separate workflow
kcpevey Mar 20, 2023
6d20c98
change run location
kcpevey Mar 20, 2023
1f1e141
run headless
kcpevey Mar 20, 2023
be6c794
ensure headless
kcpevey Mar 20, 2023
aae1d16
pass cli argument to pytest as fixture
kcpevey Mar 20, 2023
4f8dc3d
typo...
kcpevey Mar 20, 2023
ed4e830
restrict tests on PRs to exclude playwright tests
kcpevey Mar 21, 2023
6e5ee6d
add a few file types to gitignore
kcpevey Mar 21, 2023
f6de84d
move playwright to k8s gh action
kcpevey Mar 21, 2023
a2faeee
gh action syntax strikes again!
kcpevey Mar 21, 2023
bac4a59
fix string env var replacement
kcpevey Mar 21, 2023
5b305cd
add username/password login option
kcpevey Mar 22, 2023
6ec87f0
minor fixes
kcpevey Mar 22, 2023
2ad22fe
add https to url
kcpevey Mar 27, 2023
2874c8b
remove conflicing sync test
kcpevey Mar 27, 2023
346eaae
add config to artifacts
kcpevey Mar 28, 2023
dc7b227
add config to artifact... second try
kcpevey Mar 28, 2023
8200a4f
add instance type to env vars to smooth working between local and ci
kcpevey Mar 28, 2023
5024154
fix stupid mistake
kcpevey Mar 28, 2023
2390753
add videos to tests
kcpevey Mar 29, 2023
c755179
try/except on the nav fixture- temp
kcpevey Mar 29, 2023
70f0f66
fix bad username/password
kcpevey Mar 29, 2023
c4105a9
git clone, add a simpler test to check login
kcpevey Mar 30, 2023
50926ab
apparently can't run multiple tests with different nav instances...
kcpevey Mar 30, 2023
5f80e59
clone repo in test, add more doc strings
kcpevey Mar 30, 2023
5f94818
fix extra slashes in constructed url
kcpevey Mar 30, 2023
a7ef508
add wait for notebook to actually run
kcpevey Mar 30, 2023
cd39da3
jupyter loading doesn't count as network traffic
kcpevey Mar 31, 2023
ec249d5
dont wait for server message, its too variable
kcpevey Mar 31, 2023
beebd9f
add sleep to terminal interactions
kcpevey Apr 11, 2023
a4b7cba
Merge branch 'develop' into add_playwright
kcpevey Apr 11, 2023
ccf0f61
[pre-commit.ci] Apply automatic pre-commit fixes
pre-commit-ci[bot] Apr 11, 2023
a431301
remove extra setting
kcpevey Apr 11, 2023
9b101bb
check conda env list
kcpevey Apr 12, 2023
e719bd0
switch to default env
kcpevey Apr 12, 2023
7c6b62a
rename file
kcpevey Apr 12, 2023
bee6053
switch order of cypress and playwright tests, separate navigator and …
kcpevey Apr 12, 2023
76d78d5
increase cypress wait for jlab to load
kcpevey Apr 12, 2023
2433510
fix import
kcpevey Apr 12, 2023
62ce07b
clone repo takes longer than 5 seconds
kcpevey Apr 13, 2023
7da6cc2
extend notebook runtime
kcpevey Apr 13, 2023
726a08d
increase cypress wait for jlab to load
kcpevey Apr 14, 2023
ca1570b
extend time to clone repo
kcpevey Apr 14, 2023
4886e3f
more waits in more places to account for jupyter flakinesss
kcpevey Apr 14, 2023
4da9d4a
Merge branch 'develop' into add_playwright
kcpevey Apr 18, 2023
8a905a2
doc strings cleanup
kcpevey Apr 20, 2023
f2a1396
disable azure tests for now
kcpevey Apr 20, 2023
c5c9624
restart dialog doesn't always popup
kcpevey Apr 21, 2023
7db3696
address review comments
kcpevey May 9, 2023
9965b29
Merge branch 'develop' into add_playwright
kcpevey May 9, 2023
96ba3b1
address review comments
kcpevey May 9, 2023
06bdba7
Apply suggestions from code review
kcpevey May 9, 2023
15a5044
rework server startup
kcpevey May 9, 2023
729092a
fix import
kcpevey May 9, 2023
9e62d31
jupyter is flaky, add retry to restart run all
kcpevey May 10, 2023
df1a2ca
fix trailing slash, remove instance type from .env
kcpevey May 10, 2023
93c703b
more reviewer comments
kcpevey May 11, 2023
5245dc4
Update tests_e2e/playwright/conftest.py
kcpevey May 11, 2023
902b466
fixture cleanup
kcpevey May 11, 2023
74e99c0
Merge branch 'develop' into add_playwright
kcpevey May 16, 2023
9d5ce0b
fix typo
aktech Jul 18, 2023
11d6cf3
Merge branch 'develop' into add_playwright
aktech Jul 18, 2023
7af2be8
write notebook on the nebari cluster instead of cloning
aktech Jul 18, 2023
2558c4a
remove cloning docs
aktech Jul 18, 2023
efaff5b
add docs to write_file, open terminal etc
aktech Jul 18, 2023
76ff6db
change notebook path relative to playwright
aktech Jul 18, 2023
a0954b5
[pre-commit.ci] Apply automatic pre-commit fixes
pre-commit-ci[bot] Jul 18, 2023
eb9a768
address comments
pmeier Jul 20, 2023
e803e2a
Merge branch 'develop' into add_playwright
pmeier Jul 20, 2023
e4d2a5f
add docs about creating a user
aktech Jul 20, 2023
ece5d19
add support for --headed and --slowmo
pmeier Jul 20, 2023
79aaba0
fix login env variables
aktech Jul 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions .github/workflows/kubernetes_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ on:
required: true
type: string

env:
NEBARI_BASE_URL: "github-actions.nebari.dev"

kcpevey marked this conversation as resolved.
Show resolved Hide resolved
jobs:
test-kubernetes:
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request'
Expand Down Expand Up @@ -70,6 +73,7 @@ jobs:
run: |
conda install -c anaconda pip
pip install .[dev]
playwright install --with-deps
kcpevey marked this conversation as resolved.
Show resolved Hide resolved
- name: Download and Install Kubectl
run: |
mkdir -p bin
Expand All @@ -92,12 +96,12 @@ jobs:
ip route
- name: Add DNS entry to hosts
run: |
sudo echo "172.18.1.100 github-actions.nebari.dev" | sudo tee -a /etc/hosts
sudo echo "172.18.1.100 $NEBARI_BASE_URL" | sudo tee -a /etc/hosts
- name: Initialize Nebari Cloud
run: |
mkdir -p local-deployment
cd local-deployment
nebari init local --project=thisisatest --domain github-actions.nebari.dev --auth-provider=password
nebari init local --project=thisisatest --domain $NEBARI_BASE_URL --auth-provider=password

kcpevey marked this conversation as resolved.
Show resolved Hide resolved
# Need smaller profiles on Local Kind
sed -i -E 's/(cpu_guarantee):\s+[0-9\.]+/\1: 0.25/g' "nebari-config.yaml"
Expand All @@ -112,12 +116,12 @@ jobs:
if: always()
run: |
kubectl get all,cm,secret,ing -A
- name: Check github-actions.nebari.dev resolves
- name: Check $NEBARI_BASE_URL resolves
run: |
nslookup github-actions.nebari.dev
nslookup $NEBARI_BASE_URL
- name: Curl jupyterhub login page
run: |
curl -k https://github-actions.nebari.dev/hub/home -i
curl -k https://$NEBARI_BASE_URL/hub/home -i

### CYPRESS TESTS
- name: Setup Node
Expand Down Expand Up @@ -146,10 +150,20 @@ jobs:
nebari keycloak adduser --user "${CYPRESS_EXAMPLE_USER_NAME}" "${CYPRESS_EXAMPLE_USER_PASSWORD}" --config "${NEBARI_CONFIG_PATH}"
nebari keycloak listusers --config "${NEBARI_CONFIG_PATH}"

- name: Playwright Tests
env:
USERNAME: ${{ secrets.EXAMPLE_USER_NAME }}
PASSWORD: ${{ secrets.EXAMPLE_USER_PASSWORD }}
NEBARI_FULL_URL: "https://${{ env.NEBARI_BASE_URL }}/"
working-directory: tests_e2e/playwright
run: |
envsubst < .env.tpl > .env
pytest --browser chromium

- name: Cypress run
uses: cypress-io/github-action@v4
env:
CYPRESS_BASE_URL: https://github-actions.nebari.dev/
CYPRESS_BASE_URL: "https://${{ env.NEBARI_BASE_URL }}/"
with:
working-directory: tests_e2e

Expand All @@ -161,6 +175,7 @@ jobs:
path: |
./tests_e2e/cypress/screenshots/
./tests_e2e/cypress/videos/
${{ env.NEBARI_CONFIG_PATH }}
kcpevey marked this conversation as resolved.
Show resolved Hide resolved

- name: Deployment Pytests
run: |
Expand All @@ -174,13 +189,15 @@ jobs:
run: |
export JUPYTERHUB_USERNAME=${CYPRESS_EXAMPLE_USER_NAME}
export JUPYTERHUB_PASSWORD=${CYPRESS_EXAMPLE_USER_PASSWORD}
jhubctl --verbose run --hub=https://github-actions.nebari.dev \
jhubctl --verbose run --hub=https://$NEBARI_BASE_URL \
--auth-type=keycloak \
--validate --no-verify-ssl \
--kernel python3 \
--stop-server \
--notebook tests_deployment/assets/notebook/simple.ipynb \



kcpevey marked this conversation as resolved.
Show resolved Hide resolved
### CLEANUP AFTER TESTS
- name: Cleanup nebari deployment
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- ".github/workflows/test.yaml"
- "tests/**"
- "tests_deployment/**"
- "tests_e2e/**"
- "tests_e2e/cypress/**"
- "scripts/**"
- "nebari/**"
- "setup.cfg"
Expand All @@ -20,7 +20,7 @@ on:
- ".github/workflows/test.yaml"
- "tests/**"
- "tests_deployment/**"
- "tests_e2e/**"
- "tests_e2e/cypress/**"
- "scripts/**"
- "nebari/**"
- "setup.cfg"
Expand Down Expand Up @@ -52,4 +52,4 @@ jobs:
- name: Test Nebari
run: |
pytest --version
pytest --ignore=tests_deployment
pytest --ignore=tests_deployment --ignore=tests_e2e/playwright
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# docs
.nox
_build
.env

# setuptools scm
nebari/_version.py
Expand Down Expand Up @@ -45,5 +46,7 @@ nebari-config.yaml

.vscode/
.pytest_cache
.ipynb_checkpoints
.DS_Store

/.ruff_cache
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ dev = [
"black==22.3.0",
"dask-gateway",
"diagrams",
"python-dotenv",
"escapism",
"flake8==3.8.4",
"importlib-metadata<5.0",
Expand All @@ -80,6 +81,7 @@ dev = [
"pre-commit",
"pytest",
"pytest-timeout",
"pytest-playwright",
]

[project.urls]
Expand Down
3 changes: 3 additions & 0 deletions tests_e2e/playwright/.env.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
USERNAME=""
PASSWORD=""
NEBARI_FULL_URL=""
67 changes: 67 additions & 0 deletions tests_e2e/playwright/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Nebari integration testing with Playwright


## How does it work?

Playwright manages interactions with any website. We are using it to interact
with a deployed Nebari instance and test the various integrations that are
included.

For our test suite, we utilize Playwright's synchronous API. The first task
is to launch the web browser you'd like to test in. Options in our test suite
are `chromium`, `webkit`, and `firefox`. Playwright uses browser contexts to
achieve test isolation. The context can either be created by default or
manually (for the purposes of generating multiple contexts per test in the case
of admin vs user testing). Next the page on the browser is created. For all
tests this starts as a blank page, then during the test, we navigate to a given
url.

## Setup

Install Nebari with the development requirements (which include Playwright)

`pip install -e ".[dev]"`

The install playwright

`playwright install`
kcpevey marked this conversation as resolved.
Show resolved Hide resolved


## Writing Playwright tests
kcpevey marked this conversation as resolved.
Show resolved Hide resolved

In general most of the testing happens through `assertions` and `locators`.
The Playwright API has several mechanism for getting a locator for an item on
the page.

```python
button = self.page.get_by_role("button", name="Sign in with Keycloak")
```

Once you have a handle locator, you can interact with it in different ways,
depending on the type of object. For example, clicking
a button:

```python
button.click()
```

Occasionally you'll need to wait for things to load on the screen. We can
achieve this through several mechanisms. We can either wait for the page to
finish loading:

```python
self.page.wait_for_load_state("networkidle")
```

or we can wait for something specific to happen with the locator itself:

```python
button.wait_for(timeout=3000, state="attached")
```



## Notes
Playwright dev tips:
* when its running, don't touch anything - this should go without saying,
but its easy to forget
Loading