Comments (5)
Let me think about it
from playwright-bdd.
Btw, in Playwright if you call test.use({ viewport: { width: 800, height: 600 }})
somewhere in the file -> all tests in that file will use that viewport. For example:
test("test 1", async ({ page }) => { ... });
test.use({ viewport: { width: 800, height: 600 }});
test("test 2", async ({ page }) => { ... });
Both test 1
and test 2
will have viewport 800x600.
To execute one test in different viewport we could use fixtures-overrides:
const test = base.extend({
viewport: async ({ viewport }, use, testInfo) => {
if (testInfo.title.includes('(800x600)')) {
viewport = { width: 800, height: 600 };
}
await use(viewport);
}
});
test("test 1", async ({ page }) => { ... });
test("test 2 (800x600)", async ({ page }) => { ... });
Here only test 2
will have viewport 800x600.
With playwright-bdd we can use exactly the same approach with fixtures overrides. For example in fixtures.ts
:
import { test as base } from 'playwright-bdd';
export const test = base.extend({
viewport: async ({ viewport }, use, testInfo) => {
if (testInfo.title.includes('(800x600)')) { // <- can also use testInfo.titlePath to apply 800x600 to whole feature
viewport = { width: 800, height: 600 };
}
await use(viewport)
}
});
And then in config:
const testDir = defineBddConfig({
importTestFrom: 'fixtures.ts',
// ...
});
@NikkTod could you check and let me know does it works for you?
Note:
Instead of checking testInfo.title
it would be more accurate to stick to test tags - this is how cucumber tagged hooks work. While #8 is not ready, I'm thinking about providing custom $tags
fixture with all tags defined in feature file for particular test. In that case we can set tags in feature file and then use it in fixtures:
Feature: Playwright site
@tablet
Scenario: Check title
Given I open url "https://playwright.dev"
When I click link "Get started"
Then I see in title "Playwright"
fixtures.ts
:
import { test as base } from 'playwright-bdd';
export const test = base.extend({
viewport: async ({ viewport, $tags }, use) => {
if ($tags.includes('@tablet')) {
viewport = { width: 800, height: 600 };
}
await use(viewport)
}
});
from playwright-bdd.
@vitalets actually you are right, I kind of misslead you.
Good example on the feature override, I actually created for me a new project within the playwright.config file, but I also checked your suggestion and it is working as expected, thank you I will close that ticket.
I very much like your suggestion for custum tags, looking forward to see it implemented, as I think it will help us a lot.
from playwright-bdd.
You are welcome :)
from playwright-bdd.
Added this question to FAQ.
from playwright-bdd.
Related Issues (20)
- Feature: CLI option to print version HOT 2
- Question:Using Tags to define test environments. HOT 1
- Feature: remove dependency on @cucumber/cucumber
- Bug:$step.title is giving eslint errors HOT 2
- Feature: Add special tag @slow HOT 1
- Bug: scenario using special tag @timeout display <anonymous> in playwright UI HOT 4
- Bug: Can't seem to be able to launch playwright with cucumber because of SyntaxError: Error reading storage state from tests-config/storageState.json: HOT 7
- Bug:@fail tag is not working correctly with Example Tables HOT 3
- Question:What is the Priority of Tags stated in the playwright BDD run command vs Playwright Config using grep HOT 1
- Bug: Reporter doesn't work for non BDD setup projects HOT 1
- Question:Tag specific examples of a Scenario Outline HOT 2
- Feature: Support Code Coverage Reports HOT 5
- Feature: Update to [email protected] HOT 1
- Bug: [nodemon] starting `'npx bddgen'` HOT 3
- Question: sample code how to use Hooks, Before, BeforeAll HOT 3
- Question: Would you mind adding more extensive examples to this repo? HOT 3
- Question: Best practice for handling multiple step definitions with the same text HOT 4
- Question: Example code for writing custom locators HOT 2
- Question: Integration with jenkins
- Question: Allure report shows unnecessary hooks and random order number in the report
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-bdd.