Reputation: 61
Playwright Framework : Is there a way we can execute dependent tests in playwright? Like for example, we use 'depends on' method using TestNg annotations, or using Priority annotations in Selenium Webdriver. I have a test case which is dependent on the other test case. The latter one is actually for submitting an application first. So, only by using the submitted ID, I can run my other test cases. So, I can either create that test script as a method and call that method in my test scripts so I am not re-using the same test script again. But instead I wanted to run this test case before the other ones. So, is there a way in Playwright that we can execute a specific test cases before some dependent test cases?
Upvotes: 3
Views: 8268
Reputation: 11
According to the documentation, tests in a single file are run in sequence, not in parallel. This means the best approach is probably to include dependent tests in the same file, in the desired order of execution.
Upvotes: 1
Reputation: 41
You can run your test blocks one after another using test.describe.serial mode.
e.g.
test.describe.serial("Running test sequentially", ()=>{
test("Test block 1 : ", async()=>{
//enter code here
});
test("Test block 2 : ", async()=>{
//enter code here
});
});
But there is a catch in using test.describe.serial mode, subsequent tests won’t be run if an earlier test fails. It is also not works with the flags like fullyParalell: false, or --max-failures, or --bail last two works in running independent test blocks.
I have raised a defect and feature to be added in Playwright to not skip subsequent test if an earlier test fails. Please find the links below:
https://github.com/microsoft/playwright/issues/17266
https://github.com/microsoft/playwright/issues/16199
Upvotes: 4