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

Full code

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

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

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

JavaScript
await page.goForward();

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

JavaScript
await page.goBack();

The below command refresh the browser.

JavaScript
await page.reload();

click command

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

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

Fill command

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

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