Browser Commands In Playwright Automation

In this blog, we will discuss browser commands in playwright.

Full code

import {test,expect} from '@playwright/test'
test.describe('Home page test suite', async () => {   
    test(plawright browser commands',async({page})=>{
    await page.goto("<url for the application under test>") 
    await page.locator('#testid').click();    
    await page.goForward(); 
    await page.goBack(); 
    await page.reload(); 
    await page.locator('//input[@id="test"]').fill('Test');
  })
});

Explanation

The below command opens the browser with the desired webpage.

await page.goto("url of the application under test")

The below command navigates backward. Equivalent to forward button in the browser.

await page.goForward();

The below command navigates backward. Equivalent to back button in the browser.

await page.goBack();

The below command refresh the browser.

await page.reload();

click command

The below command locates the web element using the locator and click the element.

await page.locator('#testid').click();

Fill command

The below command locates the web element using the locator and enter input inside the input field.

await page.locator('//input[@id="test"]').fill('Test');

Note
We can locate elements using xpath, CSS selectors, test selectors, and playwright inbuilt selectors as well.

Thank you, Happy learning......