To access values from the Playwright test configuration within a test function, you can use the testInfo
parameter. This parameter contains information about the current test, including the configuration values defined in playwright.config.ts
.
For example, if you have a metadata
property in your config file:
export default {
metadata: 'acceptance tests',
};
Access this value in your test using testInfo.config.metadata
. Similarly, if you have an outputDir
property:
export default {
outputDir: './test-results',
};
Access it using testInfo.outputDir
.
You can also access other values through the testInfo
object, such as the name of the current project with testInfo.project.name
, or information about the current browser context using testInfo.context
.
Keep in mind that some values may be undefined depending on your test configuration. For example, if you haven't specified a project name in your config file or on the command line when running tests, then testInfo.project.name
will return undefined.
In summary, accessing configuration values within a test function is simple and allows you to customize behavior based on different configurations.
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].