-
Clone the repository:
git clone https://github.com/perilevy/Playwright.git cd Playwright
-
Install dependencies:
npm install
-
Install Playwright browsers:
npx playwright install
-
Run the Playwright test:
npm test
api-test.spec.js
: Contains the Playwright test
-
Open the
api-test.spec.js
file: -
Write a test that mocks a GET request to the API
https://jsonplaceholder.typicode.com/posts/1
. The mock should intercept a GET request to /posts/1 and reply with a 200 status and a body containing a title of 'mocked title'. -
In the same test, perform a GET request to https://jsonplaceholder.typicode.com/posts/1 using native fetch API.
-
Check the title of the response body. It should be 'mocked title', which is the title provided by the mock.
-
Write another command that mocks a PATCH request to the API. The mock should intercept a PATCH request to /posts/1 and reply with a 200 status and a body containing a title of 'new mocked title'.
-
In the same test, perform a PATCH request to https://jsonplaceholder.typicode.com/posts/1 using native fetch API. The request body should contain a title of 'new mocked title'.
-
Run
npm test
to see the test passes