Reputation: 101
I have tests which are running in Chromium, Firefox and Webkit (mobile) browsers.
But several of these tests should not be executed in the mobile browser.
How can I set skipping such tests if Playwright executes tests in Webkit?
I tried to use the pytest annotations from here https://playwright.dev/python/docs/test-runners#examples but it doesn't work, all tests are executed as earlier.
import pytest
@pytest.mark.only_browser("firefox")
# @pytest.mark.skip_browser("webkit")
def test_selected(order):
order.open()
order.set_channel('XXX')
The command for executing is pytest ./tests/Orders
(if it's important).
For executing in a few browsers I use the fixture in conftest.py
:
@fixture(scope="session",
params=['chromium', 'firefox', 'mobile'],
ids=['chromium', 'firefox', 'mobile'])
def pw(get_playwright, request):
headless = True if request.config.getini('headless').casefold() == 'true' else False
match request.param:
case 'chromium':
app = App(
get_playwright.chromium.launch(headless=headless),
{
'base_url': request.config.getini('base_url'),
'viewport': {"width": 1920, "height": 1080},
},
)
case 'firefox':
app = App(
get_playwright.firefox.launch(headless=headless),
{
'base_url': request.config.getini('base_url'),
'viewport': {"width": 1366, "height": 768}
},
)
case 'mobile':
app = App(
get_playwright.webkit.launch(headless=headless),
{
'base_url': request.config.getini('base_url'),
**get_playwright.devices['iPhone 14 Pro Max landscape']
},
)
case _: assert False, 'Wrong browser'
yield app
app.close()
Upvotes: 0
Views: 756
Reputation: 73
You can use Conditionally skip
, this can skip certain tests based on the condition, e.g.:
Single test:
test('skip this test', async ({ page, browserName }) => {
test.skip(browserName === 'firefox', 'Still working on it');
});
Conditionally skip a group of tests:
For example, you can run a group of tests just in Chromium by passing a callback.
test.describe('chromium only', () => {
test.skip(({ browserName }) => browserName !== 'chromium', 'Chromium only!');
test.beforeAll(async () => {
// This hook is only run in Chromium.
});
test('test 1', async ({ page }) => {
// This test is only run in Chromium.
});
test('test 2', async ({ page }) => {
// This test is only run in Chromium.
});
});
Upvotes: 0