From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

API request context

API request context

In the previous lesson, we learned how to make an API call, get the response from the API and use the response data in our test. In this lesson, we'll go ahead and learn how to make this API call using the API request context. Now using the page, we can of course make an API call, but the API request context is a more better and efficient way to perform the same. So let's go ahead and learn how to do it. To create an API context, we require the playwright instance. So let's request the playwright fixture in our test function. And it is the type of playwright. Now we can go ahead and remove the page navigation code. To create an API context, we can use the playwright instance request attribute and the new context method like this you will notice that the new context method takes many arguments which we will use later on now we'll go ahead and just store it as api context like this so there we have our api request context now to make an api call using our context we can use the same and…

Contents