Playwright intercept site request and serve a mocked object - yelenagotraining/E2EFrameworks GitHub Wiki
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)
}));
})