Skip to content

Playwright intercept site request and serve a mocked object

Lena edited this page Jun 15, 2021 · 1 revision

Create mock object

const mockResponseObject = {
  "userLocationsts":[
    {"userPersonalInfoId": 1,"locationId": 42159, "name":"New Dominion Freight", "isSelected": true}
  ],
  "isThirdPartyVisibility": true,
  "isShowThirdParty": true
}

Inside the test

test('customer home page intercept location rule', async ({page, context, browser}) => {
      await page.route('**/MyCarrierAPI//api/Account/GetUserLocationRule', (route) => route.fulfill( {
      status:200,
      contentType: 'application/json',
      body: JSON.stringify(mockResponseObject)
   }));
})

Clone this wiki locally