Skip to content

Commit 2fef454

Browse files
committed
wip
1 parent d7f918e commit 2fef454

File tree

9 files changed

+83
-3
lines changed

9 files changed

+83
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,5 @@ tests/test_codegen.py
167167
.streamlit/*
168168
!.streamlit/config.yaml
169169
!.streamlit/secrets.toml.example
170+
playwright/.auth/*
171+
!playwright/.auth/.gitkeep

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
GIT_REVISION ?= $(shell git rev-parse --short HEAD)
33
GIT_TAG ?= $(shell git describe --tags --abbrev=0 --always | sed -e s/v//g)
44

5+
# Project
6+
SKIP_TEST ?= true
7+
58
.PHONY: help
69
help:
710
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@@ -40,7 +43,7 @@ lint: ## lint
4043

4144
.PHONY: test
4245
test: ## run tests
43-
uv run pytest --capture=no -vv
46+
SKIP_TEST=$(SKIP_TEST) uv run pytest --capture=no -vv
4447

4548
.PHONY: ci-test
4649
ci-test: install-deps-dev format-check lint test ## run CI tests

compose.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
pgadmin:
3+
image: dpage/pgadmin4
4+
ports:
5+
- "8888:80"
6+
environment:
7+
PGADMIN_DEFAULT_EMAIL: [email protected]
8+
PGADMIN_DEFAULT_PASSWORD: very-strong-password
9+
PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION: "False"

docs/index.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,26 @@ make codegen
3636

3737
#### Credentials
3838

39-
Run the following command to set up the credentials for the application.
39+
1. Run the following command to set up the credentials for the application.
4040

4141
```shell
4242
# Run the application
4343
uv run streamlit run workshop_playwright_python/apps/streamlit_authentication.py
4444
```
4545

46-
Then, type your credentials described in [.streamlit/config.yaml](../.streamlit/config.yaml) and click the "Login" button. (e.g. `jsmith:abc`, `rbriggs:def`)
46+
2. Type your credentials described in [.streamlit/config.yaml](../.streamlit/config.yaml) and click the "Login" button. (e.g. `jsmith:abc`, `rbriggs:def`)
47+
48+
3. Run scripts to save the context.
49+
50+
```shell
51+
uv run scripts/save_context.py
52+
```
53+
54+
4. Run the following command to load the context.
55+
56+
```shell
57+
uv run scripts/load_context.py
58+
```
4759

4860
#### OpenID Connect
4961

playwright/.auth/.gitkeep

Whitespace-only changes.

scripts/load_context.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from playwright.sync_api import Playwright, sync_playwright
2+
3+
4+
def run(playwright: Playwright) -> None:
5+
browser = playwright.chromium.launch(headless=False)
6+
context = browser.new_context(
7+
storage_state="playwright/.auth/storage.json",
8+
)
9+
page = context.new_page()
10+
page.goto("http://localhost:8888/")
11+
12+
# sleep for a few seconds to allow the page to load
13+
import time
14+
15+
time.sleep(10)
16+
17+
# ---------------------
18+
# context.close()
19+
# browser.close()
20+
21+
22+
with sync_playwright() as playwright:
23+
run(playwright)

scripts/save_context.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import json
2+
3+
from playwright.sync_api import Playwright, StorageState, sync_playwright
4+
5+
6+
def run(playwright: Playwright) -> None:
7+
browser = playwright.chromium.launch(headless=False)
8+
context = browser.new_context()
9+
page = context.new_page()
10+
page.goto("http://localhost:8888/")
11+
page.get_by_role("textbox", name="Username").fill("jsmith")
12+
page.get_by_role("textbox", name="Password").fill("abc")
13+
page.get_by_test_id("stBaseButton-secondaryFormSubmit").click()
14+
15+
storage: StorageState = context.storage_state(path="playwright/.auth/storage.json")
16+
print(json.dumps(storage, indent=2))
17+
18+
# ---------------------
19+
context.close()
20+
browser.close()
21+
22+
23+
with sync_playwright() as playwright:
24+
run(playwright)

tests/flags.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from os import getenv
2+
3+
SKIP = getenv("SKIP_TEST", "true").lower() == "true"

tests/test_hatena_bookmark.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import json
22

3+
import pytest
4+
35
from playwright.sync_api import Page
6+
from tests import flags
47

58

9+
@pytest.mark.skipif(flags.SKIP, reason="This test is skipped because it requires a live server.")
610
def test_hatena_bookmark(page: Page):
711
page.goto("https://b.hatena.ne.jp/hotentry/all")
812

0 commit comments

Comments
 (0)