Playwright Group Tests

Profile picture for user arilio666

Playwright is a Node.js library that allows for automated testing of web applications and is built on top of the WebKit, Firefox, and Chromium browser engines. A Playwright group test is a test that runs multiple browser instances concurrently, allowing for the testing of interactions between different pages or browser contexts. Group tests in Playwright allow for testing scenarios such as multiple users logging into a website simultaneously or a user navigating between other pages while keeping their session data.

We can group tests and give them names, or we can also assign hooks to them too.

test.describe('two tests', () => {
 test('one', async ({ page }) => {
   // ...
 });
 test('two', async ({ page }) => {
   // ...
 });
});

Example:

test.describe('Tests', () => {
   test('one', async ({ page }) => {
       await page.goto("http://autopract.com/selenium/upload1/");
       const cancelButton = await page.locator('//button[@type="reset"]');
       const box = await cancelButton.boundingBox();
       
       console.log(box.height);
       console.log(box.width);
   });
 
   test('two', async ({ page }) => {
       await page.goto('https://www.programsbuzz.com/course/appium-tutorial')
       const hide = await page.locator('div[class="paragraph paragraph--type--chapter paragraph--view-mode--default active"] div[class="field field--name-field-topic-name field--type-entity-reference field--label-hidden field__items"]')
      
       await expect(hide).toBeVisible()
      
       const hideTab = await page.locator('div[class="paragraph paragraph--type--chapter paragraph--view-mode--default active"] div[class="field field--name-field-chapter-name field--type-string field--label-hidden field__item"]');
       hideTab.click()
       
      
       await expect(hide).toBeHidden()
   });
 });
  • Two tests with different approaches are performed here using the group test.