Giter Site home page Giter Site logo

Comments (6)

mxschmitt avatar mxschmitt commented on May 22, 2024 1

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.

sqandrew avatar sqandrew commented on May 22, 2024 1

amazing! thanks for the solution and forecast!

from playwright-pytest.

mxschmitt avatar mxschmitt commented on May 22, 2024

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.

sqandrew avatar sqandrew commented on May 22, 2024

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.

mxschmitt avatar mxschmitt commented on May 22, 2024

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.

sqandrew avatar sqandrew commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.