Comments (6)
Oh gotcha! Yeah this is since they use classes probably internally, thats why you need such a hacky solution:
diff --git a/conftest.py b/conftest.py
index d3f58e1..8deceda 100644
--- a/conftest.py
+++ b/conftest.py
@@ -9,8 +9,8 @@ from pathlib import Path
def pytest_runtest_makereport(item, call) -> None:
if call.when == "call":
- if call.excinfo is not None and "page" in item.funcargs:
- page = item.funcargs["page"]
+ if "page" in item.funcargs["request"]._fixture_defs:
+ page = item.funcargs["request"]._fixture_defs["page"].cached_result[0]
screenshot_dir = Path(".playwright-screenshots")
screenshot_dir.mkdir(exist_ok=True)
page.screenshot(path=str(screenshot_dir / f"{slugify(item.nodeid)}.png"))
\ No newline at end of file
Stay tuned for Playwright version 1.12 which gets released in a few days. It includes a tracing feature with which its not required anymore to have videos/screenshots on failure. With them after and before every step a snapshot is made which you can view locally. And everything is contained in a single zip file.
from playwright-pytest.
amazing! thanks for the solution and forecast!
from playwright-pytest.
I tried it with the latest version but was not able to reproduce it with your example. Could you install the latest version via pip install pytest-playwright==0.1.2
to make sure it got installed correctly and not the cached one was used?
from playwright-pytest.
were you able to make a screenshot with this test?
I uninstalled pytest-playwright, than made pip install pytest-playwright==0.1.2. without changes - and "page" in item.funcargs
is not true. (Python 3.9.0)
from playwright-pytest.
Yes it worked for me. I made the following changes:
diff --git a/features/test.feature b/features/test.feature
index cac51d2..77daad8 100644
--- a/features/test.feature
+++ b/features/test.feature
@@ -2,3 +2,4 @@ Feature: Demo feature
Scenario: Demo scenario
Given I open browser
+ Then I make a screenshot
\ No newline at end of file
diff --git a/step_definition/demo.py b/step_definition/demo.py
index 93eb8d4..16ff183 100644
--- a/step_definition/demo.py
+++ b/step_definition/demo.py
@@ -4,4 +4,7 @@ from pytest_bdd import scenarios, given, when, then
@given("I open browser")
def step_impl(page):
page.goto("https://example.com")
- assert False
+
+@then("I make a screenshot")
+def step_impl(page):
+ page.screenshot(path="foo.png")
from playwright-pytest.
Let me be more precise.
What works OK for me:
unconditional screenshot capture.
For example, using page.screenshot(path="foo.png") in a regular step, as it is in your changes above.
What doesn't work:
Screenshot on test failure
The condition never becomes true, because there is no 'page' in funcargs.
from playwright-pytest.
Related Issues (20)
- [BUG] Unable to set timezone_id or locale using pytest.mark fixture HOT 2
- Can't click or find elements on page without a slight pause/time.sleep() first HOT 5
- Rerunning skipped dependent test cases when a parent test fails HOT 1
- [BUG] Playwright fixture hangs on teardown with pytest-flask HOT 1
- Setting locale for a test affects the local for other tests HOT 1
- Coverage support HOT 1
- [BUG] Error when installing in Python 3.12 HOT 2
- Pytest.ini set --screenshot="only-on-failure" --video="retain-on-failure" Screenshots and recorded videos will also be generated after the use case is successfully executed.
- pytest-playwright--parameterization, cases order Not what I expected HOT 8
- playwright._impl._api_types.Error: net::ERR_CONNECTION_TIMED_OUT at https://www.google.com HOT 2
- [FEATURE] Support connecting to remote browsers HOT 1
- Request: `async` support HOT 4
- [FEATURE] Support pytest 8.x HOT 3
- [BUG]The execution sequence is incorrect when use parametrize HOT 1
- Request: extending `browser_type_launch_args` to work with `request`
- [FEATURE] Support for multiple browser contexts in a single test HOT 1
- [FR] Support for working with pytest-rerunfailures to only create --output on true failure
- Allow extending playwright capabilities HOT 2
- run with --video on --screenshot on how to set screenshot dir and how to get videoname and screenshot name? HOT 1
- pytest-playwirght uses --video="on" to record video,the recorded video only records the newly opened tab page HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright-pytest.