Comments (6)
Hi, here is minimal reproducible example:
conftest.py:
import os
import tempfile
from typing import Any, Callable, Dict, Generator, List
import pytest
from playwright.sync_api import (
Browser,
BrowserContext,
Page,
Playwright,
sync_playwright,
)
artifacts_folder = tempfile.TemporaryDirectory(prefix="playwright-pytest-")
print(f"{artifacts_folder.name=}")
@pytest.fixture()
def browser_context_args(
pytestconfig: Any,
playwright: Playwright,
) -> Dict:
context_args = {"record_video_dir": artifacts_folder}
return context_args
@pytest.fixture(scope="session")
def playwright() -> Generator[Playwright, None, None]:
pw = sync_playwright().start()
yield pw
pw.stop()
@pytest.fixture(scope="session")
def browser(launch_browser: Callable[[], Browser]) -> Generator[Browser, None, None]:
browser = launch_browser()
yield browser
browser.close()
@pytest.fixture
def context(
browser: Browser,
browser_context_args: Dict,
pytestconfig: Any,
) -> Generator[BrowserContext, None, None]:
pages: List[Page] = []
context = browser.new_context(**browser_context_args)
context.on("page", lambda p: pages.append(p))
yield context
context.close()
for page in pages:
video = page.video
video_path = str(video.path())
print(f"{video_path=}")
file_name = os.path.basename(video_path)
video.save_as(f"/tmp/{file_name}")
@pytest.fixture
def page(context: BrowserContext, base_url: str) -> Generator[Page, None, None]:
page = context.new_page()
yield page
test_bug.py:
from playwright.sync_api import Page
def test_bug(page: Page):
page.goto("https://playwright.dev/python/docs/intro/")
Running on Python 3.8.1, ubuntu/bionic64. If I change following line:
context_args = {"record_video_dir": artifacts_folder}
to:
context_args = {"record_video_dir": artifacts_folder.name}
It starts working.
from playwright-pytest.
Just for posterity, the bug that I was encountering few weeks ago when I initially opened this issue was different - TemporaryDirectory
was returning underscore instead of dash at one place in the string for some reason, compared to video.path()
. Looks like there are few buggy behaviours. Personally I refactored my fixtures away from TemporaryDirectory.
Oh and there's also a typo in temp directory name, playwight
.
from playwright-pytest.
Looks like a bug with tempfile
library where tempfile.Directory()
returns slightly incorrect path, resulting videos not to be moved from artifacts dir to output dir.
from playwright-pytest.
Transferred to the playwright-pytest repo. Looks like a bug with our pytest fixtures. PRs welcome if you know how to fix it, otherwise @mxschmitt can you take a look?
from playwright-pytest.
@paunovic sorry for the late reply. Do you have a full example somewhere (e.g. GitHub repo)? I tried to confirm it and reproduce it locally, but for me it seems working as intended.
from playwright-pytest.
Ohhh good catch! Thats the fix for it: #83. Will release it shortly.
from playwright-pytest.
Related Issues (20)
- 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
- Move creation of artifacts_folder into a fixture HOT 2
- [BUG]PermissionError: [WinError 5]
- [FEATURE] Implement steps for Trace Viewer HOT 1
- [Feature]: Expose output_dir as a fixture HOT 3
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.