File tree Expand file tree Collapse file tree 7 files changed +286
-29
lines changed Expand file tree Collapse file tree 7 files changed +286
-29
lines changed Original file line number Diff line number Diff line change @@ -162,3 +162,5 @@ cython_debug/
162162# Project
163163* .env
164164requirements.txt
165+ generated
166+ tests /test_codegen.py
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ info: ## show information
1616install-deps-dev : # # install dependencies for development
1717 uv sync --all-extras
1818 uv run pre-commit install
19+ uv run playwright install
1920
2021.PHONY : install-deps
2122install-deps : # # install dependencies for production
@@ -98,3 +99,28 @@ docs-serve: ## serve documentation
9899
99100.PHONY : ci-test-docs
100101ci-test-docs : docs # # run CI test for documentation
102+
103+ # ---
104+ # Project
105+ # ---
106+
107+ .PHONY : test-verbose
108+ test-verbose : # # run tests with verbose
109+ uv run pytest \
110+ --capture=no \
111+ --verbose \
112+ --headed \
113+ --tracing on \
114+ --video on \
115+ --screenshot on \
116+ --output generated
117+
118+ TRACE_ZIP ?= generated/tests-test-core-py-test-get-started-link-chromium/trace.zip
119+ .PHONY : show-trace
120+ show-trace : # # show trace
121+ uv run playwright show-trace $(TRACE_ZIP )
122+
123+ .PHONY : codegen
124+ codegen : # # generate test code
125+ uv run playwright codegen \
126+ --output tests/test_codegen.py
Original file line number Diff line number Diff line change 11# workshop-playwright-python
2+
3+ ## Installation
4+
5+ To set up the environment, details are provided in [ Playwright for Python > Installation] ( https://playwright.dev/python/docs/intro ) .
6+ In this workshop, we provide a script to install the necessary dependencies.
7+
8+ ``` bash
9+ git clone https://github.com/ks6088ts-labs/workshop-playwright-python.git
10+ cd workshop-playwright-python
11+
12+ # Install the dependencies
13+ make install-deps-dev
14+ ```
15+
16+ - [[ BUG] Host system is missing dependencies to run browsers (WSL2) #19100 ] ( https://github.com/microsoft/playwright/issues/19100 )
17+
18+ ## Guides
19+
20+ To run some demos, please follow the instructions below.
21+
22+ ``` bash
23+ # Run tests in verbose mode
24+ make test-verbose
25+
26+ # Show traces
27+ make show-trace
28+
29+ # Generate code
30+ make codegen
31+ ```
32+
33+ ## [ Microsoft Playwright Testing] ( https://learn.microsoft.com/ja-jp/azure/playwright-testing/ )
34+
35+ - [ Get Started Sample] ( https://github.com/microsoft/playwright-testing-service/tree/main/samples/get-started )
36+
37+ ## [ Playwright MCP server] ( https://github.com/microsoft/playwright-mcp )
Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ version = "0.0.1"
44description = " A GitHub template repository for Python"
55readme = " README.md"
66requires-python = " >=3.10"
7- dependencies = []
7+ dependencies = [
8+ " playwright>=1.52.0" ,
9+ " pytest-playwright>=0.7.0" ,
10+ ]
811
912[project .optional-dependencies ]
1013docs = [
Original file line number Diff line number Diff line change 11import logging
2+ import re
3+
4+ from playwright .sync_api import Page , expect
25
36from workshop_playwright_python .core import hello_world
47
@@ -13,3 +16,20 @@ def test_hello_world_non_verbose(caplog):
1316 with caplog .at_level (logging .DEBUG ):
1417 hello_world (verbose = False )
1518 assert "Hello, world!" not in caplog .text
19+
20+
21+ def test_has_title (page : Page ):
22+ page .goto ("https://playwright.dev/" )
23+
24+ # Expect a title "to contain" a substring.
25+ expect (page ).to_have_title (re .compile ("Playwright" ))
26+
27+
28+ def test_get_started_link (page : Page ):
29+ page .goto ("https://playwright.dev/" )
30+
31+ # Click the get started link.
32+ page .get_by_role ("link" , name = "Get started" ).click ()
33+
34+ # Expects page to have a heading with the name of Installation.
35+ expect (page .get_by_role ("heading" , name = "Installation" )).to_be_visible ()
Original file line number Diff line number Diff line change 1+ import json
2+
3+ from playwright .sync_api import Page
4+
5+
6+ def test_hatena_bookmark (page : Page ):
7+ page .goto ("https://b.hatena.ne.jp/hotentry/all" )
8+
9+ entries = []
10+ for entry in page .query_selector_all (".entrylist-contents-main" ):
11+ title_element = entry .query_selector (".entrylist-contents-title a" )
12+ bookmark_element = entry .query_selector (".entrylist-contents-users span" )
13+
14+ if title_element and bookmark_element :
15+ title = title_element .inner_text ()
16+ url = title_element .get_attribute ("href" )
17+ bookmarks = bookmark_element .inner_text ().replace ("users" , "" ).strip ()
18+
19+ entries .append ({"title" : title , "url" : url , "bookmarks" : int (bookmarks ) if bookmarks .isdigit () else 0 })
20+
21+ print (json .dumps (entries , indent = 2 , ensure_ascii = False ))
You can’t perform that action at this time.
0 commit comments