Coder Social home page Coder Social logo

Comments (5)

vitalets avatar vitalets commented on May 19, 2024 1

Let me think about it

from playwright-bdd.

vitalets avatar vitalets commented on May 19, 2024

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.

NikkTod avatar NikkTod commented on May 19, 2024

@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.

vitalets avatar vitalets commented on May 19, 2024

You are welcome :)

from playwright-bdd.

vitalets avatar vitalets commented on May 19, 2024

Added this question to FAQ.

from playwright-bdd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.