-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to attach a screenshot of failed tests? #50
Comments
Comment contains stack trace from pytest, it should be the same what you see in a terminal code. Do you have something different reported in Xray? It is not possible to attache a screenshot or any other test evidence. There is no such functionality implemented in the plugin. |
Thanks for your response! |
What do you mean by steps? Do you use gherkin, or just logs from a python logger? (I can try to add possibility to include screenshots as a test evidence) |
I mean logs from python logger. That would be really great to be able to attach a screenshot as test evidence, thanks! |
I created a branch Here is an example how to use it: # FILE: conftest.py
import pytest
from pytest_xray import evidence
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
evidences = getattr(report, "evidences", [])
if report.when == "call":
xfail = hasattr(report, "wasxfail")
if (report.skipped and xfail) or (report.failed and not xfail):
data = open('screenshot.jpg', 'rb').read()
evidences.append(
evidence.jpeg(data=data, filename="image21.jpg",)
)
report.evidences = evidences |
Sorry, maybe I am not catching up well. But, suppose the screenshot taken once the test failed is "xyz.png" where I should refer to it:
|
data = open('xyz.png', 'rb').read() -> zyz.png is our screenshot's filename XRAY API required evidence as dict: "evidences" : [
{
"data": "(... base 64 encoded ...)",
"filename": "screenshot1.jpg",
"contentType": "image/jpeg"
}
] BTW, you can attach logs from test in the same way: logs = report.caplog
evidences.append(evidence.text(data=logs, filename="test.log")) |
Hi, for the failed tests no screenshot is attached. `@pytest.hookimpl(hookwrapper=True)
|
We launch tests on Jenkins using docker containers. I think the problem is that there is something going wrong while reading the file from the saved location. |
Did you try to use full path to a screenshot file, e.g.: from pathlib import Path
screenshot_path = Path.cwd() / f"{TEST_METHOD_NAME}" + ".jpg" Also if DRIVER is Selenium webdriver than you should use PNG format |
Thanks. I will try that. Changing screenshot format from "jpg" to "png" also requires changes these parts of the code as well, right? def jpeg(data: AnyStr, filename: str) -> Dict[str, str]: |
Yes, I commited that change to the branch. |
Hi, I have two questions related to attaching logs & screenshots to test execution.
The text was updated successfully, but these errors were encountered: