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.
Authorized API context
From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python
Authorized API context
Now that we have generated our GitHub API token, we can create an API context to store the same and reuse the authorization. So in our conftest.py, we'll go ahead and define our API context, and let's make it a pytest fixture. And let's set the scope to session because we only want to create the API context per session. And we'll also require the playwright fixture, that is the playwright instance. And I can go ahead and import its type. So from sync API, import the playwright type. So let's hint on its type now. And then we can create a new context using leright request dot new context to this we have to provide the extra HTTP headers which will contain our headers along with the token. So the first header we need to set is accept and the value for the same will be application vnd github v3 plus json of course i'm writing this off from my scratchpad and you can find the same in the resources the second header which we need to set is authorization authorization like this and the value…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.