Open floraachy opened 4 months ago
In pytest, I have configured options for taking screenshots, recording videos, and tracing。 [pytest] addopts = --tracing=on --screenshot=on --video=on
also, I have configured options "--output" with my own directory. For example: --output=outputs/tracing
When I run test, if the test case name is too long, it will be unable to take screenshots and record videos.
testcase name: test_login_user_no_phone[chromium-网页登录,正确用户名和密码登录成功,弹窗后提示未绑定手机号码]
I checked pytest_playwright.py
, It will runcates the length of the screenshot file name. But it seems doesn't work.
def _build_artifact_test_folder( pytestconfig: Any, request: pytest.FixtureRequest, folder_or_file_name: str ) -> str: output_dir = pytestconfig.getoption("--output") return os.path.join( output_dir, truncate_file_name(slugify(request.node.nodeid)), truncate_file_name(folder_or_file_name), )
def truncate_file_name(file_name: str) -> str: if len(file_name) < 256: return file_name return f"{file_name[:100]}-{hashlib.sha256(file_name.encode()).hexdigest()[:7]}-{file_name[-100:]}"
it will be unable to take screenshots and record videos.
Can you share the error which you receive?
it will be unable to take screenshots and record videos.
Can you share the error which you receive?
only one case, it didn‘t generate pictures and video., this is the error:
When I changed the testcase name, long name to short name. It run success and genertate picures and videos successfully.
Could you help us creating a minimal reproduction for it? I tried to execute the following ,but for me it was working as expected:
import pytest
testdata = [
("网页登录,正确用户名和密码登录成功,弹窗后提示未绑定手机号码弹窗后提示未绑定手机号码弹窗后提示未绑定手机号码]机号码弹窗绑定手机号码弹窗后提示未绑定手机号码]机号码弹窗后提绑定手机号码弹窗后提示未绑定手机号码]机号码弹窗后提绑定手机号码弹窗后提示未绑定手机号码]机号码弹窗后提后提示未绑定手机号码弹窗后提示未绑定手机号码]机号码弹窗后提示未绑定手机号码弹窗后提示未绑定手机号码]机号码弹窗后提示未绑定手机号码弹窗后提示未绑定手机号码]机号码弹窗后提示未绑定手机号码弹窗后提示未绑定手机号码]"),
]
@pytest.mark.parametrize("name", testdata)
def test_timedistance_v0(name, page):
print(name)
I was running it with --video=on --screenshot=on --tracing=on
网页登录,正确用户名和密码登录成功,弹窗后提示未绑定手机号码
from playwright.sync_api import Page, expect
import pytest
@pytest.mark.parametrize('case',
[{"title": "网页登录,正确用户名和密码登录成功,弹窗后提示未绑定手机号码", "name": "GitLink"}],
ids=lambda x: x["title"])
def test_gitlink(page: Page, case):
page.goto("https://www.gitlink.org.cn/explore")
expect(page).to_have_url("https://www.gitlink.org.cn/explore")
assert "GitLink" == case["name"]
import pytest
if __name__ == '__main__':
pytest.main(["--browser=chromium", "--headed"])
[pytest]
addopts =
--tracing=on
--screenshot=on
--video=on
--output=results
When I run main.py
, ERROR happened:
For me the test passes unfortunately so your system might have different settings compared to my machine. Could you run the following and provide me the values?
python
>>> os.pathconf('/', 'PC_PATH_MAX')
...
>>> os.pathconf('/', 'PC_NAME_MAX')
...
os.pathconf('/', 'PC_NAME_MAX')
My system version: Windows 11 专业版 - 23H2 - 22631.3880 Python version=3.9.5
I see, while looking at the error message, I stumped across this post - we recommend to have this setting enabled, could you try enabling this? The issue is that the whole path length reaches this limit, so it would be hard from our side to take care of that, since the parent path could be already very long.
I see, while looking at the error message, I stumped across this post - we recommend to have this setting enabled, could you try enabling this? The issue is that the whole path length reaches this limit, so it would be hard from our side to take care of that, since the parent path could be already very long.
I changed Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled
from 0 to 1, no error happen and the folder generated successfully.
Could we limit the maximum length of directory names through code?
I thought this method: truncate_file_name
, was used to limit the length of directory .
I still can't understand why it didn't work.
I see, while looking at the error message, I stumped across this post - we recommend to have this setting enabled, could you try enabling this? The issue is that the whole path length reaches this limit, so it would be hard from our side to take care of that, since the parent path could be already very long.
I made a little change, and It solved my problem for now. (I don't want adjust my system:Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled
)。
I set tracing,screenshot and video opened.