Upload attachments to tests in Test Reporting & Analytics
Learn how to upload attachments to tests in Test Reporting & Analytics.
You can upload various files as attachments to tests in Test Reporting & Analytics.
Attachments are needed in the following use cases:
- If your tests run outside the BrowserStack infrastructure, you might want to upload screenshots and other attachments to your tests to improve your Timeline Debugging experience.
- You might want to add DOM, HTML files, custom log-out files, etc. which are otherwise not captured by BrowserStack. These additional logs and information will improve your debugging experience.
You can view attachments under the Attachments tab in the Timeline Debugging view of a test.
How to upload attachments to tests
Currently, you can upload attachments for Java and Python frameworks. We will be adding this feature to other frameworks soon.
Upload attachments to Java tests
Test Reporting & Analytics supports attachments on Java-TestNG tests.
Add the following code to your Java tests to upload attachments:
Import the BrowserStack library
import com.browserstack.v2.utils.BrowserStack;
Upload files using the following method
String fileToUpload = "path/to/your/file.png";
BrowserStack.uploadAttachment(fileToUpload);
Here, fileToUpload
is a String variable with the path or link to the file you want to upload.
Upload attachments to Python tests
Test Reporting & Analytics supports attachments on Python test suites which uses the Pytest framework.
Add the following code to your Python tests to upload attachments:
Upload files using the following method
fileToUpload = "path/to/your/file.png"
driver.upload_attachment(fileToUpload)
Here, fileToUpload
is a String variable with the path or link to the file that you want to upload.
Upload attachments to Allure tests
The syntax to upload attachments to your Allure tests is different for each frmework. You can refer to the Allure docs for your framework.
Example
The following sample syntax is used for Javascript framework:
addAttachment("Screenshot", fs.readFileSync("/path/to/image.png"), "image/png");
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!