{"id":345874,"date":"2023-02-25T21:01:26","date_gmt":"2023-02-25T21:01:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=345874"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=345874","title":{"rendered":"<span>\u041f\u0438\u0448\u0435\u043c API \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u044b \u043d\u0430 TypeScript + Playwright<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c API \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 TypeScript. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0432\u044b\u0431\u0435\u0440\u0435\u043c playwright.<\/p>\n<p>\u0425\u043e\u0447\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0438 \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u044b \u043e\u0442\u0432\u0435\u0447\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u043c\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430, \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0442\u0435\u043b\u0435 \u043e\u0442\u0432\u0435\u0442\u0430, \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c JSON \u0441\u0445\u0435\u043c\u0443;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0444\u0438\u043a\u0441\u0442\u0443\u0440;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u043e\u0442\u0447\u0435\u0442;<\/p>\n<\/li>\n<\/ol>\n<h2>Requirements<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f API \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u043e\u0432 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>playwright &#8212; yarn add\u00a0playwright\/npm install playwright;<\/p>\n<\/li>\n<li>\n<p>allure-playwright &#8212; yarn add allure-playwright\/npm install allure-playwright;<\/p>\n<\/li>\n<li>\n<p>dotenv &#8212; yarn add dotenv \/npm install dotenv, &#8212; \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0438\u0437 .env \u0444\u0430\u0439\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>ajv- yarn add ajv\/npm install ajv, &#8212; \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 JSON \u0441\u0445\u0435\u043c\u044b;<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u0441\u0442\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 API\u00a0<a href=\"https:\/\/api.sampleapis.com\/futurama\/questions\" rel=\"noopener noreferrer nofollow\">https:\/\/api.sampleapis.com\/futurama\/questions<\/a>. \u0414\u0430\u043d\u043d\u044b\u0439 API \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043f\u0440\u0438\u043c\u0435\u0440. \u041d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 API \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e\u00a0<strong>\u0441\u0443\u0442\u044c\u00a0\u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u043e\u0432 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u0430 \u0436\u0435.<\/strong><\/p>\n<h2>Settings<\/h2>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 .env \u0444\u0430\u0439\u043b<\/p>\n<pre><code class=\"bash\">CI=1 # For playwright  ENV_NAME=\"Local\" # Name of our env just for example, can be \"Dev\", \"Staging\" etc.  ALLURE_RESULTS_FOLDER=\"allure-results\" # Folder where allure results are stored  BASE_URL=\"https:\/\/api.sampleapis.com\" # API endpoint TEST_USER_EMAIL=\"some@gmail.com\" # Some random user just for example TEST_USER_PASSWORD=\"some\" # Some random password just for example<\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 playwright \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043b\u0438\u0448\u044c allure-report. \u0418\u0441\u043a\u043b\u044e\u0447\u0438\u043c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u043b\u044f API \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043f\u043e \u0442\u0438\u043f\u0443 projects, headless, video, screenshot. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u0440\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e playwright \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c\u00a0<a href=\"https:\/\/playwright.dev\/docs\/test-configuration\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. <\/p>\n<p>playwright.config.ts<\/p>\n<pre><code class=\"typescript\">import { defineConfig } from '@playwright\/test'; import { config as dotenvConfig } from 'dotenv'; import { resolve } from 'path';  dotenvConfig({ path: resolve(__dirname, '.env'), override: true });  \/**  * Read environment variables from file.  * https:\/\/github.com\/motdotla\/dotenv  *\/ \/\/ require('dotenv').config();  \/**  * See https:\/\/playwright.dev\/docs\/test-configuration.  *\/ export default defineConfig({   testDir: '.\/tests',   \/* Maximum time one test can run for. *\/   timeout: 30 * 1000,   expect: {     \/**      * Maximum time expect() should wait for the condition to be met.      * For example in `await expect(locator).toHaveText();`      *\/     timeout: 5000   },   \/* Run tests in files in parallel *\/   fullyParallel: true,   \/* Fail the build on CI if you accidentally left test.only in the source code. *\/   forbidOnly: !!process.env.CI,   \/* Retry on CI only *\/   retries: process.env.CI ? 2 : 0,   \/* Opt out of parallel tests on CI. *\/   workers: process.env.CI ? 1 : undefined,   \/* Reporter to use. See https:\/\/playwright.dev\/docs\/test-reporters *\/   reporter: [['html'], ['allure-playwright']],   globalTeardown: require.resolve('.\/utils\/config\/global-teardown'),   \/* Shared settings for all the projects below. See https:\/\/playwright.dev\/docs\/api\/class-testoptions. *\/   use: {     \/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). *\/     actionTimeout: 0,     \/* Base URL to use in actions like `await page.goto('\/')`. *\/     \/\/ baseURL: 'http:\/\/localhost:3000',      \/* Collect trace when retrying the failed test. See https:\/\/playwright.dev\/docs\/trace-viewer *\/     trace: 'on-first-retry'   } });<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"typescript\">dotenvConfig({ path: resolve(__dirname, '.env'), override: true });<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 .env \u0444\u0430\u0439\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435. <\/p>\n<p><strong>\u041b\u0430\u0439\u0444\u0445\u0430\u043a. <\/strong>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0439 (<strong>dev, test, staging, local<\/strong>), \u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432 .env, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <strong>.env.dev, .env.test, .env.staging<\/strong>, \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f. \u0422\u043e\u0433\u0434\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0444\u0430\u0439\u043b\u0430 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"typescript\">dotenvConfig({ path: resolve(__dirname, process.env.ENV_FILE), override: true });<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>ENV_FILE<\/code> \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043b\u0438\u0431\u043e \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 <code>export ENV_FILE=\".env.test\" &amp;&amp; npx playwright test<\/code>  <\/p>\n<h2>Types<\/h2>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 question \u0438\u0437 API\u00a0<a href=\"https:\/\/api.sampleapis.com\/futurama\/questions\" rel=\"noopener noreferrer nofollow\">https:\/\/api.sampleapis.com\/futurama\/questions<\/a>. \u0421\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">{   \"id\": 1,   \"question\": \"What is Fry's first name?\",   \"possibleAnswers\": [     \"Fred\",     \"Philip\",     \"Will\",     \"John\"   ],   \"correctAnswer\": \"Philip\" }<\/code><\/pre>\n<p>utils\\types\\api\\questions.ts<\/p>\n<pre><code class=\"typescript\">export interface Question {   id: number;   question: string;   possibleAnswers: string[];   correctAnswer: string | number; }  export interface UpdateQuestion extends Partial&lt;Omit&lt;Question, 'id'>> {}<\/code><\/pre>\n<p>utils\\types\\api\\authentication.ts<\/p>\n<pre><code class=\"typescript\">export interface AuthUser {   email: string;   password: string; }  export interface APIAuth {   authToken?: string;   user?: AuthUser; }<\/code><\/pre>\n<p><code>AuthUser<\/code> \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 (\u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438).<\/p>\n<p>utils\\types\\api\\client.ts<\/p>\n<pre><code class=\"typescript\">import { APIRequestContext } from '@playwright\/test';  export interface APIClient {   context: APIRequestContext; }<\/code><\/pre>\n<p><code>APIClient<\/code> \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u0434\u043b\u044f \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 API \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432. \u041e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043d\u0438\u0436\u0435, \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u044b.<\/p>\n<h2>Context<\/h2>\n<p>\u0423 playwright \u0435\u0441\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 <a href=\"https:\/\/playwright.dev\/docs\/api\/class-apirequestcontext\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f API \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c baseURL, \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u043e\u043a\u0435\u043d \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, proxy, timeout, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 <a href=\"https:\/\/playwright.dev\/docs\/api\/class-apirequestcontext\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u0435\u0437 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/p>\n<p>core\\context\\default-context.ts<\/p>\n<pre><code class=\"typescript\">import { request } from '@playwright\/test';  export const getDefaultAPIContext = async () => {   return await request.newContext({     baseURL: process.env.BASE_URL   }); };<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API \u0441 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439. \u0412 \u044d\u0442\u043e\u043c API\u00a0<a href=\"https:\/\/api.sampleapis.com\/futurama\/questions\" rel=\"noopener noreferrer nofollow\">https:\/\/api.sampleapis.com\/futurama\/questions<\/a>\u00a0\u043d\u0435\u0442 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u044f \u0443\u043a\u0430\u0437\u0430\u043b \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0434\u043b\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e API Key \u0440\u0430\u0434\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0434\u043b\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.  <\/p>\n<p>core\\context\\auth-context.ts<\/p>\n<pre><code class=\"typescript\">import { APIRequestContext, request } from '@playwright\/test'; import { APIAuth } from '..\/..\/utils\/types\/api\/authentication'; import { getAuthAPIClient } from '..\/api\/authentication-api';  export const getAuthAPIContext = async ({ user, authToken }: APIAuth): Promise&lt;APIRequestContext> => {   let extraHTTPHeaders: { [key: string]: string } = {     accept: '*\/*',     'Content-Type': 'application\/json'   }; API endpoints   if (!user &amp;&amp; !authToken) {     throw Error('Provide \"user\" or \"authToken\"');   }    if (user &amp;&amp; !authToken) {     const authClient = await getAuthAPIClient();     const token = await authClient.getAuthToken(user);      extraHTTPHeaders = { ...extraHTTPHeaders, Authorization: `Token ${token}` };   }   if (authToken &amp;&amp; !user) {     extraHTTPHeaders = { ...extraHTTPHeaders, Authorization: `Token ${authToken}` };   }    return await request.newContext({     baseURL: process.env.BASE_URL,     extraHTTPHeaders   }); };<\/code><\/pre>\n<h3>API Clients<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 API.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043e\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439. \u0414\u043b\u044f\u00a0<a href=\"https:\/\/api.sampleapis.com\/futurama\/questions\" rel=\"noopener noreferrer nofollow\">https:\/\/api.sampleapis.com\/futurama\/questions<\/a>\u00a0\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u043d\u043e \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u0448\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<p>core\\api\\authentication-api.ts<\/p>\n<pre><code class=\"typescript\">import test, { APIRequestContext, APIResponse } from '@playwright\/test'; import { APIRoutes } from '..\/..\/utils\/constants\/routes'; import { APIClient } from '..\/..\/utils\/types\/api\/client'; import { AuthUser } from '..\/..\/utils\/types\/api\/authentication'; import { getDefaultAPIContext } from '..\/context\/default-context';  class AuthAPIClient implements APIClient {   constructor(public context: APIRequestContext) {}    async getAuthTokenApi(data: AuthUser): Promise&lt;APIResponse> {     const stepName = `Getting token for user with email \"${data.email}\" and password \"${data.password}\"`;      return await test.step(stepName, async () => {       return await this.context.post(APIRoutes.Auth, { data });     });   }    async getAuthToken(data: AuthUser): Promise&lt;string> {     \/\/ Should be used like this:      \/\/ const response = await this.getAuthTokenApi(data);     \/\/ const json = await response.json();      \/\/ expect(response.status()).toBe(200);      \/\/ return json.token;      return 'token';   } }  export const getAuthAPIClient = async (): Promise&lt;AuthAPIClient> => {   const defaultContext = await getDefaultAPIContext();   return new AuthAPIClient(defaultContext); };<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c <code>APIClient<\/code> \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c <code>context<\/code> \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432\u043d\u0443\u0442\u0440\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b. <\/p>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f questions:  <\/p>\n<pre><code class=\"typescript\">import test, { APIRequestContext, APIResponse } from '@playwright\/test'; import { expectStatusCode } from '..\/..\/utils\/assertions\/solutions'; import { APIRoutes } from '..\/..\/utils\/constants\/routes'; import { APIClient } from '..\/..\/utils\/types\/api\/client'; import { Question, UpdateQuestion } from '..\/..\/utils\/types\/api\/questions';  export class QuestionsAPIClient implements APIClient {   constructor(public context: APIRequestContext) {}    async getQuestionAPI(questionId: number): Promise&lt;APIResponse> {     return await test.step(`Getting question with id \"${questionId}\"`, async () => {       return await this.context.get(`${APIRoutes.Questions}\/${questionId}`);     });   }    async getQuestionsAPI(): Promise&lt;APIResponse> {     return await test.step('Getting questions', async () => {       return await this.context.get(APIRoutes.Questions);     });   }    async createQuestionAPI(data: Question): Promise&lt;APIResponse> {     return await test.step(`Creating question with id \"${data.id}\"`, async () => {       return await this.context.post(APIRoutes.Questions, { data });     });   }    async updateQuestionAPI(questionId: number, data: UpdateQuestion): Promise&lt;APIResponse> {     return await test.step(`Updating question with id \"${questionId}\"`, async () => {       return await this.context.patch(`${APIRoutes.Questions}\/${questionId}`, { data });     });   }    async deleteQuestionAPI(questionId: number): Promise&lt;APIResponse> {     return await test.step(`Deleting question with id \"${questionId}\"`, async () => {       return await this.context.delete(`${APIRoutes.Questions}\/${questionId}`);     });   }    async createQuestion(data: Question): Promise&lt;Question> {     const response = await this.createQuestionAPI(data);     await expectStatusCode({ actual: response.status(), expected: 201, api: response.url() });      return await response.json();   } }<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>QuestionsAPIClient<\/code>\u0441\u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 CRUD \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a API <a href=\"https:\/\/api.sampleapis.com\/futurama\/questions\" rel=\"noopener noreferrer nofollow\">https:\/\/api.sampleapis.com\/futurama\/questions<\/a>.  <\/p>\n<h2>Utils<\/h2>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u043b\u0443\u0447\u0448\u0435.<\/p>\n<p>\u0425\u0440\u0430\u043d\u0438\u0442\u044c \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0438 \u0431\u0443\u0434\u0435\u043c enum, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f:<\/p>\n<p>utils\\constants\\routes.ts<\/p>\n<pre><code class=\"typescript\">export enum APIRoutes {   Auth = '\/auth',   Info = '\/futurama\/info',   Cast = '\/futurama\/cast',   Episodes = '\/futurama\/episodes',   Questions = '\/futurama\/questions',   Inventory = '\/futurama\/inventory',   Characters = '\/futurama\/characters' } <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p>utils\\fakers.ts<\/p>\n<pre><code class=\"typescript\">const NUMBERS = '0123456789'; const LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; const LETTERS_WITH_NUMBERS = LETTERS + NUMBERS;  export const randomNumber = (start: number = 500, end: number = 2000): number =>   Math.floor(Math.random() * (end - start + 1) + end);  export const randomString = (start: number = 10, end: number = 20, charSet: string = LETTERS_WITH_NUMBERS): string => {   let randomString = '';   for (let index = 0; index &lt; randomNumber(start, end); index++) {     const randomPoz = Math.floor(Math.random() * charSet.length);     randomString += charSet.substring(randomPoz, randomPoz + 1);   }   return randomString; };  export const randomListOfStrings = (start: number = 10, end: number = 20): string[] => {   const range = randomNumber(start, end);    return Array.from(Array(range).keys()).map((_) => randomString()); };<\/code><\/pre>\n<p>\u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430, \u0447\u0442\u043e\u0431\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0447\u0438\u0441\u043b\u043e; \u043d\u0430\u043c \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u0412 \u0441\u0432\u043e\u0438\u0445 \u0436\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0435\u0439\u043a\u0435\u0440\u044b \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/github.com\/faker-js\/faker\" rel=\"noopener noreferrer nofollow\">faker-js<\/a>.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0443\u0442\u0438\u043b\u0438\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 API:<\/p>\n<p>utils\\api\\questions.ts<\/p>\n<pre><code class=\"typescript\">import { randomListOfStrings, randomNumber, randomString } from '..\/fakers'; import { Question, UpdateQuestion } from '..\/types\/api\/questions';  export const getRandomUpdateQuestion = (): UpdateQuestion => ({   question: randomString(),   correctAnswer: randomString(),   possibleAnswers: randomListOfStrings() });  export const getRandomQuestion = (): Question => ({   id: randomNumber(),   question: randomString(),   correctAnswer: randomString(),   possibleAnswers: randomListOfStrings() });<\/code><\/pre>\n<p>utils\\fixtures.ts<\/p>\n<pre><code class=\"typescript\">import { Fixtures } from '@playwright\/test';  export const combineFixtures = (...args: Fixtures[]): Fixtures =>   args.reduce((acc, fixture) => ({ ...acc, ...fixture }), {});<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435\u00a0<code>combineFixtures<\/code>\u00a0&#8212; \u044d\u0442\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0444\u0438\u043a\u0441\u0442\u0443\u0440 \u0432 \u043e\u0434\u0438\u043d. \u041c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u0435\u0437 \u043d\u0435\u0433\u043e, \u043d\u043e \u043c\u043d\u0435 \u0442\u0430\u043a \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u0435\u0435.<\/p>\n<h2>Assertions<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043d\u0430\u0447\u043d\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<p>\u041e\u043f\u0438\u0448\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435:<\/p>\n<p>utils\\assertions\\solutions.ts<\/p>\n<pre><code class=\"typescript\">import { expect, test } from '@playwright\/test';  type ExpectToEqual&lt;T> = {   actual: T;   expected: T;   description: string; };  type ExpectStatusCode = { api: string } &amp; Omit&lt;ExpectToEqual&lt;number>, 'description'>;  export const expectToEqual = async &lt;T>({ actual, expected, description }: ExpectToEqual&lt;T>) => {   await test.step(`Checking that \"${description}\" is equal to \"${expected}\"`, async () => {     expect(actual).toEqual(expected);   }); };  export const expectStatusCode = async ({ actual, expected, api }: ExpectStatusCode): Promise&lt;void> => {   await test.step(`Checking that response status code for API \"${api}\" equal to ${expected}`, async () => {     await expectToEqual({ actual, expected, description: 'Response Status code' });   }); };<\/code><\/pre>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u0438 \u043e\u0431\u0435\u0440\u0442\u043a\u0438, \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u0432 \u043e\u0442\u0447\u0435\u0442\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u043f\u043e \u0442\u0438\u043f\u0443 <code>expect.toEqual<\/code>, \u0447\u0442\u043e \u043d\u0435\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435 \u0436\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0432\u044b\u0448\u0435.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043b\u044f questions:<\/p>\n<p>utils\\assertions\\api\\questions.ts<\/p>\n<pre><code class=\"typescript\">import { Question, UpdateQuestion } from '..\/..\/types\/api\/questions'; import { expectToEqual } from '..\/solutions';  type AssertQuestionProps = {   expectedQuestion: Question;   actualQuestion: Question; };  type AssertUpdateQuestionProps = {   expectedQuestion: UpdateQuestion;   actualQuestion: UpdateQuestion; };  export const assertUpdateQuestion = async ({ expectedQuestion, actualQuestion }: AssertUpdateQuestionProps) => {   await expectToEqual({     actual: expectedQuestion.question,     expected: actualQuestion.question,     description: 'Question \"question\"'   });   await expectToEqual({     actual: expectedQuestion.correctAnswer,     expected: actualQuestion.correctAnswer,     description: 'Question \"correctAnswer\"'   });   await expectToEqual({     actual: expectedQuestion.possibleAnswers,     expected: actualQuestion.possibleAnswers,     description: 'Question \"possibleAnswers\"'   }); };  export const assertQuestion = async ({ expectedQuestion, actualQuestion }: AssertQuestionProps) => {   await expectToEqual({ actual: expectedQuestion.id, expected: actualQuestion.id, description: 'Question \"id\"' });   await assertUpdateQuestion({ expectedQuestion, actualQuestion }); }; <\/code><\/pre>\n<p>\u041c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>assertUpdateQuestion<\/code>, <code>assertQuestion<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0442\u0435\u0441\u0442\u0430\u0445. \u0415\u0441\u043b\u0438 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u044f, \u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u0443\u0447\u0443 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 \u0432 \u0442\u0435\u0441\u0442\u0430\u0445.<\/p>\n<h2>Schema<\/h2>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 JSON \u0441\u0445\u0435\u043c\u044b. \u0414\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/ajv.js.org\/guide\/typescript.html\" rel=\"noopener noreferrer nofollow\">https:\/\/ajv.js.org\/guide\/typescript.html<\/a><\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440:<\/p>\n<p>utils\\schema\\validator.ts<\/p>\n<pre><code class=\"typescript\">import test from '@playwright\/test'; import Ajv, { JSONSchemaType } from 'ajv';  const ajv = new Ajv();  type ValidateSchemaProps&lt;T> = {   schema: JSONSchemaType&lt;T>;   json: T | T[]; };  export const validateSchema = async &lt;T>({ schema, json }: ValidateSchemaProps&lt;T>) => {   await test.step('Validating json schema', async () => {     const validate = ajv.compile(schema);      if (!validate(json)) {       const prettyJson = JSON.stringify(json, null, 2);       const prettyError = JSON.stringify(validate.errors, null, 2);       throw Error(`Schema validation error: ${prettyError}\\nJSON: ${prettyJson}`);     }   }); };<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>validateSchema<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u0445\u0435\u043c\u0443 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442 JSON, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u043d.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0445\u0435\u043c\u0443 \u0434\u043b\u044f questions:<\/p>\n<p>utils\\schema\\api\\questions-schema.ts<\/p>\n<pre><code class=\"typescript\">import { JSONSchemaType } from 'ajv'; import { Question, UpdateQuestion } from '..\/..\/types\/api\/questions';  export const questionSchema: JSONSchemaType&lt;Question> = {   title: 'Question',   type: 'object',   properties: {     id: { type: 'integer' },     question: { type: 'string' },     possibleAnswers: { type: 'array', items: { type: 'string' } },     correctAnswer: { anyOf: [{ type: 'string' }, { type: 'integer' }] }   },   required: ['id', 'question', 'correctAnswer', 'possibleAnswers'] };  export const updateQuestionSchema: JSONSchemaType&lt;UpdateQuestion> = {   title: 'UpdateQuestion',   type: 'object',   properties: {     question: { type: 'string', nullable: true },     possibleAnswers: { type: 'array', items: { type: 'string' }, nullable: true },     correctAnswer: { type: 'string', nullable: true }   } };  export const questionsListSchema: JSONSchemaType&lt;Question[]> = {   title: 'QuestionsList',   type: 'array',   items: {     $ref: '#\/definitions\/question',     type: 'object',     required: ['id', 'question', 'correctAnswer', 'possibleAnswers']   },   definitions: {     question: {       title: 'Question',       type: 'object',       properties: {         id: { type: 'integer' },         question: { type: 'string' },         possibleAnswers: { type: 'array', items: { type: 'string' } },         correctAnswer: { anyOf: [{ type: 'string' }, { type: 'integer' }] }       },       required: ['id', 'question', 'correctAnswer', 'possibleAnswers']     }   } };<\/code><\/pre>\n<p>\u041e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c JSON \u0441\u0445\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u0443\u0442 <a href=\"https:\/\/json-schema.org\/understanding-json-schema\/\" rel=\"noopener noreferrer nofollow\">https:\/\/json-schema.org\/understanding-json-schema\/<\/a>. \u0410 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c JSON \u0441\u0445\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0443\u0442 <a href=\"https:\/\/www.liquid-technologies.com\/online-json-to-schema-converter\" rel=\"noopener noreferrer nofollow\">https:\/\/www.liquid-technologies.com\/online-json-to-schema-converter<\/a>.<\/p>\n<h2>Fixtures<\/h2>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u0432, &#8212; \u044d\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0438\u043a\u0441\u0442\u0443\u0440\u044b.<\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0438\u043a\u0441\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:<\/p>\n<p>fixtures\\users.ts<\/p>\n<pre><code class=\"typescript\">import { Fixtures } from '@playwright\/test'; import { AuthUser } from '..\/utils\/types\/api\/authentication';  export type UsersFixture = {   testUser: AuthUser; };  export const usersFixture: Fixtures&lt;UsersFixture> = {   testUser: async ({}, use) => {     const email = process.env.TEST_USER_EMAIL;     const password = process.env.TEST_USER_PASSWORD;      if (!email || !password) {       throw Error(`Provide \"TEST_USER_EMAIL\" and \"TEST_USER_PASSWORD\" inside .env`);     }      await use({ email, password });   } }; <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0438\u043a\u0441\u0442\u0443\u0440\u044b \u0434\u043b\u044f questions:<\/p>\n<p>fixtures\\questions.ts<\/p>\n<pre><code class=\"typescript\">import { Fixtures } from '@playwright\/test'; import { QuestionsAPIClient } from '..\/core\/api\/questions-api'; import { getAuthAPIContext } from '..\/core\/context\/auth-context'; import { getRandomQuestion } from '..\/utils\/api\/questions'; import { Question } from '..\/utils\/types\/api\/questions'; import { UsersFixture } from '.\/users';  export type QuestionsFixture = {   questionsClient: QuestionsAPIClient;   question: Question; };  export const questionsFixture: Fixtures&lt;QuestionsFixture, UsersFixture> = {   questionsClient: async ({ testUser }, use) => {     const authContext = await getAuthAPIContext({ user: testUser });     const questionsClient = new QuestionsAPIClient(authContext);      await use(questionsClient);   },   question: async ({ questionsClient }, use) => {     const randomQuestion = getRandomQuestion();     const question = await questionsClient.createQuestion(randomQuestion);      await use(question);      await questionsClient.deleteQuestionAPI(question.id);   } }; <\/code><\/pre>\n<p>\u0424\u0438\u043a\u0441\u0442\u0443\u0440\u0430 <code>questionsClient<\/code> \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u043c \u0432 \u0442\u0435\u0441\u0442\u044b \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 questions API. \u0424\u0438\u043a\u0441\u0442\u0443\u0440\u0430 <code>question<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 question \u0447\u0435\u0440\u0435\u0437 API \u0438 \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044e \u0442\u0435\u0441\u0442\u0430 \u0443\u0434\u0430\u043b\u0438\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442. <\/p>\n<h2>Testing<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0441\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b, \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0444\u0438\u043a\u0441\u0442\u0443\u0440\u044b, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0432\u044b\u0448\u0435.<\/p>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c extend \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e test \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\u0437 playwright \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u0441\u0432\u043e\u0438 \u0444\u0438\u043a\u0441\u0442\u0443\u0440\u044b:<\/p>\n<p>tests\\questions-test.ts<\/p>\n<pre><code class=\"typescript\">import { test as base } from '@playwright\/test'; import { questionsFixture, QuestionsFixture } from '..\/fixtures\/questions'; import { usersFixture, UsersFixture } from '..\/fixtures\/users'; import { combineFixtures } from '..\/utils\/fixtures';  export const questionsTest = base.extend&lt;UsersFixture, QuestionsFixture>(   combineFixtures(usersFixture, questionsFixture) ); <\/code><\/pre>\n<p>tests\\questions.spec.ts<\/p>\n<pre><code class=\"typescript\">import { getRandomQuestion, getRandomUpdateQuestion } from '..\/utils\/api\/questions'; import { assertQuestion, assertUpdateQuestion } from '..\/utils\/assertions\/api\/questions'; import { expectStatusCode } from '..\/utils\/assertions\/solutions'; import { questionSchema, questionsListSchema, updateQuestionSchema } from '..\/utils\/schema\/api\/questions-schema'; import { validateSchema } from '..\/utils\/schema\/validator'; import { Question } from '..\/utils\/types\/api\/questions'; import { questionsTest as test } from '.\/questions-test';  test.describe('Questions', () => {   test('Get question', async ({ question, questionsClient }) => {     const response = await questionsClient.getQuestionAPI(question.id);     const json: Question = await response.json();      await expectStatusCode({ actual: response.status(), expected: 200, api: response.url() });     await assertQuestion({ expectedQuestion: question, actualQuestion: json });      await validateSchema({ schema: questionSchema, json });   });    test('Get questions', async ({ questionsClient }) => {     const response = await questionsClient.getQuestionsAPI();     const json: Question[] = await response.json();      await expectStatusCode({ actual: response.status(), expected: 200, api: response.url() });      await validateSchema({ schema: questionsListSchema, json });   });    test('Create question', async ({ questionsClient }) => {     const payload = getRandomQuestion();      const response = await questionsClient.createQuestionAPI(payload);     const json: Question = await response.json();      await expectStatusCode({ actual: response.status(), expected: 201, api: response.url() });     await assertQuestion({ expectedQuestion: payload, actualQuestion: json });      await validateSchema({ schema: questionSchema, json });   });    test('Update question', async ({ question, questionsClient }) => {     const payload = getRandomUpdateQuestion();      const response = await questionsClient.updateQuestionAPI(question.id, payload);     const json: Question = await response.json();      await expectStatusCode({ actual: response.status(), expected: 200, api: response.url() });     await assertUpdateQuestion({ expectedQuestion: payload, actualQuestion: json });      await validateSchema({ schema: updateQuestionSchema, json });   });    test('Delete question', async ({ question, questionsClient }) => {     const deleteQuestionResponse = await questionsClient.deleteQuestionAPI(question.id);     const getQuestionResponse = await questionsClient.getQuestionAPI(question.id);      await expectStatusCode({       actual: getQuestionResponse.status(),       expected: 404,       api: getQuestionResponse.url()     });     await expectStatusCode({       actual: deleteQuestionResponse.status(),       expected: 200,       api: deleteQuestionResponse.url()     });   }); }); <\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043f\u044f\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 CRUD \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f questions API\u00a0<a href=\"https:\/\/api.sampleapis.com\/futurama\/questions\" rel=\"noopener noreferrer nofollow\">https:\/\/api.sampleapis.com\/futurama\/questions<\/a>.<\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u043d\u0430\u0448\u0438\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0442\u0430\u0442\u0443\u0441 \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430, \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430, JSON \u0441\u0445\u0435\u043c\u0443;<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0433\u043e\u0442\u043e\u0432\u044f\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0438\u043a\u0441\u0442\u0443\u0440;<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430 \u043e\u0442\u0447\u0435\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0438\u0436\u0435.<\/p>\n<\/li>\n<\/ol>\n<h2>Report<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0435\u0439 \u043e\u0442\u0447\u0435\u0442\u0430 \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0443\u044e \u0444\u0438\u0447\u0443 playwright, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 setup, teardown. <\/p>\n<p>\u0412 <strong>playwright.config.ts<\/strong> \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c:<\/p>\n<pre><code class=\"typescript\">globalTeardown: require.resolve('.\/utils\/config\/global-teardown')<\/code><\/pre>\n<p>\u041a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>globalTeardown<\/code>. Playwright \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0441\u0435\u0441\u0441\u0438\u0438. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 allure \u043e\u0442\u0447\u0435\u0442\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e global-teardown:<\/p>\n<p>utils\\reporters\\allure.ts<\/p>\n<pre><code class=\"typescript\">import fs from 'fs'; import path from 'path';  export const createAllureEnvironmentFile = (): void => {   const reportFolder = path.resolve(process.cwd(), process.env.ALLURE_RESULTS_FOLDER);   const environmentContent = Object.entries(process.env).reduce(     (previousValue, [variableName, value]) => `${previousValue}\\n${variableName}=${value}`,     ''   );    fs.mkdirSync(reportFolder, { recursive: true });   fs.writeFileSync(`${reportFolder}\/environment.properties`, environmentContent, 'utf-8'); }; <\/code><\/pre>\n<p>utils\\config\\global-teardown.ts<\/p>\n<pre><code class=\"typescript\">import { FullConfig } from '@playwright\/test'; import { createAllureEnvironmentFile } from '..\/reporters\/allure';  async function globalTeardown(_: FullConfig): Promise&lt;void> {   createAllureEnvironmentFile(); }  export default globalTeardown; <\/code><\/pre>\n<p>\u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0441\u0435\u0441\u0441\u0438\u0438 <strong>globalSetup<\/strong>, \u0430 \u043f\u043e\u0442\u043e\u043c \u043e\u0447\u0438\u0441\u0442\u043a\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0441\u0435\u0441\u0441\u0438\u0438 <strong>globalTeardown<\/strong>.<\/p>\n<p>\u0412 \u043e\u0442\u0447\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0438 \u0432 <code>globalTeardown<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/aec\/c87\/c6d\/aecc87c6dc2c56a54650bac25dc327cf.png\" width=\"1897\" height=\"934\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aec\/c87\/c6d\/aecc87c6dc2c56a54650bac25dc327cf.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0442\u0435\u0441\u0442\u044b \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u0442\u0447\u0435\u0442:<\/p>\n<pre><code class=\"bash\">npx playwright test<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043e\u0442\u0447\u0435\u0442:<\/p>\n<pre><code class=\"bash\">allure serve<\/code><\/pre>\n<p>\u041b\u0438\u0431\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043e\u0442\u0447\u0435\u0442 \u0438 \u0432 \u043f\u0430\u043f\u043a\u0435 allure-reports \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b index.html:<\/p>\n<pre><code>allure generate<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7f8\/f8a\/97b\/7f8f8a97bc365197f1cfe6c257ce6601.png\" width=\"1900\" height=\"932\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7f8\/f8a\/97b\/7f8f8a97bc365197f1cfe6c257ce6601.png\"\/><figcaption><\/figcaption><\/figure>\n<p><a href=\"https:\/\/nikita-filonov.github.io\/playwright_typescript_api\/\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u043b\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043e\u0442\u0447\u0435\u0442\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0442\u0443\u0442<\/a>.  <\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412\u0435\u0441\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u00a0<a href=\"https:\/\/github.com\/Nikita-Filonov\/playwright_typescript_api\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043d\u0430 \u043c\u043e\u0435\u043c github<\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/718814\/\"> https:\/\/habr.com\/ru\/post\/718814\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c API \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 TypeScript. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0432\u044b\u0431\u0435\u0440\u0435\u043c playwright.<\/p>\n<p>\u0425\u043e\u0447\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0438 \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u044b \u043e\u0442\u0432\u0435\u0447\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u043c\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430, \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0442\u0435\u043b\u0435 \u043e\u0442\u0432\u0435\u0442\u0430, \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c JSON \u0441\u0445\u0435\u043c\u0443;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0444\u0438\u043a\u0441\u0442\u0443\u0440;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u043e\u0442\u0447\u0435\u0442;<\/p>\n<\/li>\n<\/ol>\n<h2>Requirements<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f API \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u043e\u0432 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>playwright &#8212; yarn add\u00a0playwright\/npm install playwright;<\/p>\n<\/li>\n<li>\n<p>allure-playwright &#8212; yarn add allure-playwright\/npm install allure-playwright;<\/p>\n<\/li>\n<li>\n<p>dotenv &#8212; yarn add dotenv \/npm install dotenv, &#8212; \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0438\u0437 .env \u0444\u0430\u0439\u043b\u0430;<\/p>\n<\/li>\n<li>\n<p>ajv- yarn add ajv\/npm install ajv, &#8212; \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 JSON \u0441\u0445\u0435\u043c\u044b;<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u0441\u0442\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 API\u00a0<a href=\"https:\/\/api.sampleapis.com\/futurama\/questions\" rel=\"noopener noreferrer nofollow\">https:\/\/api.sampleapis.com\/futurama\/questions<\/a>. \u0414\u0430\u043d\u043d\u044b\u0439 API \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043f\u0440\u0438\u043c\u0435\u0440. \u041d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 API \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e\u00a0<strong>\u0441\u0443\u0442\u044c\u00a0\u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u043e\u0432 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u0430 \u0436\u0435.<\/strong><\/p>\n<h2>Settings<\/h2>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 .env \u0444\u0430\u0439\u043b<\/p>\n<pre><code class=\"bash\">CI=1 # For playwright  ENV_NAME=\"Local\" # Name of our env just for example, can be \"Dev\", \"Staging\" etc.  ALLURE_RESULTS_FOLDER=\"allure-results\" # Folder where allure results are stored  BASE_URL=\"https:\/\/api.sampleapis.com\" # API endpoint TEST_USER_EMAIL=\"some@gmail.com\" # Some random user just for example TEST_USER_PASSWORD=\"some\" # Some random password just for example<\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 playwright \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043b\u0438\u0448\u044c allure-report. \u0418\u0441\u043a\u043b\u044e\u0447\u0438\u043c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u043b\u044f API \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043f\u043e \u0442\u0438\u043f\u0443 projects, headless, video, screenshot. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u0440\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e playwright \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c\u00a0<a href=\"https:\/\/playwright.dev\/docs\/test-configuration\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. <\/p>\n<p>playwright.config.ts<\/p>\n<pre><code class=\"typescript\">import { defineConfig } from '@playwright\/test'; import { config as dotenvConfig } from 'dotenv'; import { resolve } from 'path';  dotenvConfig({ path: resolve(__dirname, '.env'), override: true });  \/**  * Read environment variables from file.  * https:\/\/github.com\/motdotla\/dotenv  *\/ \/\/ require('dotenv').config();  \/**  * See https:\/\/playwright.dev\/docs\/test-configuration.  *\/ export default defineConfig({   testDir: '.\/tests',   \/* Maximum time one test can run for. *\/   timeout: 30 * 1000,   expect: {     \/**      * Maximum time expect() should wait for the condition to be met.      * For example in `await expect(locator).toHaveText();`      *\/     timeout: 5000   },   \/* Run tests in files in parallel *\/   fullyParallel: true,   \/* Fail the build on CI if you accidentally left test.only in the source code. *\/   forbidOnly: !!process.env.CI,   \/* Retry on CI only *\/   retries: process.env.CI ? 2 : 0,   \/* Opt out of parallel tests on CI. *\/   workers: process.env.CI ? 1 : undefined,   \/* Reporter to use. See https:\/\/playwright.dev\/docs\/test-reporters *\/   reporter: [['html'], ['allure-playwright']],   globalTeardown: require.resolve('.\/utils\/config\/global-teardown'),   \/* Shared settings for all the projects below. See https:\/\/playwright.dev\/docs\/api\/class-testoptions. *\/   use: {     \/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). *\/     actionTimeout: 0,     \/* Base URL to use in actions like `await page.goto('\/')`. *\/     \/\/ baseURL: 'http:\/\/localhost:3000',      \/* Collect trace when retrying the failed test. See https:\/\/playwright.dev\/docs\/trace-viewer *\/     trace: 'on-first-retry'   } });<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"typescript\">dotenvConfig({ path: resolve(__dirname, '.env'), override: true });<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 .env \u0444\u0430\u0439\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435. <\/p>\n<p><strong>\u041b\u0430\u0439\u0444\u0445\u0430\u043a. <\/strong>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0439 (<strong>dev, test, staging, local<\/strong>), \u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432 .env, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <strong>.env.dev, .env.test, .env.staging<\/strong>, \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f. \u0422\u043e\u0433\u0434\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0444\u0430\u0439\u043b\u0430 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"typescript\">dotenvConfig({ path: resolve(__dirname, process.env.ENV_FILE), override: true });<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>ENV_FILE<\/code> \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u043b\u0438\u0431\u043e \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 <code>export ENV_FILE=\".env.test\" &amp;&amp; npx playwright test<\/code>  <\/p>\n<h2>Types<\/h2>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 question \u0438\u0437 API\u00a0<a href=\"https:\/\/api.sampleapis.com\/futurama\/questions\" rel=\"noopener noreferrer nofollow\">https:\/\/api.sampleapis.com\/futurama\/questions<\/a>. \u0421\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">{   \"id\": 1,   \"question\": \"What is Fry's first name?\",   \"possibleAnswers\": [     \"Fred\",     \"Philip\",     \"Will\",     \"John\"   ],   \"correctAnswer\": \"Philip\" }<\/code><\/pre>\n<p>utils\\types\\api\\questions.ts<\/p>\n<pre><code class=\"typescript\">export interface Question {   id: number;   question: string;   possibleAnswers: string[];   correctAnswer: string | number; }  export interface UpdateQuestion extends Partial&lt;Omit&lt;Question, 'id'>> {}<\/code><\/pre>\n<p>utils\\types\\api\\authentication.ts<\/p>\n<pre><code class=\"typescript\">export interface AuthUser {   email: string;   password: string; }  export interface APIAuth {   authToken?: string;   user?: AuthUser; }<\/code><\/pre>\n<p><code>AuthUser<\/code> \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 (\u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438).<\/p>\n<p>utils\\types\\api\\client.ts<\/p>\n<pre><code class=\"typescript\">import { APIRequestContext } from '@playwright\/test';  export interface APIClient {   context: APIRequestContext; }<\/code><\/pre>\n<p><code>APIClient<\/code> \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u0434\u043b\u044f \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 API \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432. \u041e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043d\u0438\u0436\u0435, \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u044b.<\/p>\n<h2>Context<\/h2>\n<p>\u0423 playwright \u0435\u0441\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 <a href=\"https:\/\/playwright.dev\/docs\/api\/class-apirequestcontext\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f API \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c baseURL, \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u043e\u043a\u0435\u043d \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438, proxy, timeout, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 <a href=\"https:\/\/playwright.dev\/docs\/api\/class-apirequestcontext\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u0435\u0437 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/p>\n<p>core\\context\\default-context.ts<\/p>\n<pre><code class=\"typescript\">import { request } from '@playwright\/test';  export const getDefaultAPIContext = async () => {   return await request.newContext({     baseURL: process.env.BASE_URL   }); };<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API \u0441 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439. \u0412 \u044d\u0442\u043e\u043c API\u00a0<a href=\"https:\/\/api.sampleapis.com\/futurama\/questions\" rel=\"noopener noreferrer nofollow\">https:\/\/api.sampleapis.com\/futurama\/questions<\/a>\u00a0\u043d\u0435\u0442 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u044f \u0443\u043a\u0430\u0437\u0430\u043b \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0434\u043b\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e API Key \u0440\u0430\u0434\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0434\u043b\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.  <\/p>\n<p>core\\context\\auth-context.ts<\/p>\n<pre><code class=\"typescript\">import { APIRequestContext, request } from '@playwright\/test'; import { APIAuth } from '..\/..\/utils\/types\/api\/authentication'; import { getAuthAPIClient } from '..\/api\/authentication-api';  export const getAuthAPIContext = async ({ user, authToken }: APIAuth): Promise&lt;APIRequestContext> => {   let extraHTTPHeaders: { [key: string]: string } = {     accept: '*\/*',     'Content-Type': 'application\/json'   }; API endpoints   if (!user &amp;&amp; !authToken) {     throw Error('Provide \"user\" or \"authToken\"');   }    if (user &amp;&amp; !authToken) {     const authClient = await getAuthAPIClient();     const token = await authClient.getAuthToken(user);      extraHTTPHeaders = { ...extraHTTPHeaders, Authorization: `Token ${token}` };   }   if (authToken &amp;&amp; !user) {     extraHTTPHeaders = { ...extraHTTPHeaders, Authorization: `Token ${authToken}` };   }    return await request.newContext({     baseURL: process.env.BASE_URL,     extraHTTPHeaders   }); };<\/code><\/pre>\n<h3>API Clients<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 API.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043e\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439. \u0414\u043b\u044f\u00a0<a href=\"https:\/\/api.sampleapis.com\/futurama\/questions\" rel=\"noopener noreferrer nofollow\">https:\/\/api.sampleapis.com\/futurama\/questions<\/a>\u00a0\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u043d\u043e \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u0448\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<p>core\\api\\authentication-api.ts<\/p>\n<pre><code class=\"typescript\">import test, { APIRequestContext, APIResponse } from '@playwright\/test'; import { APIRoutes } from '..\/..\/utils\/constants\/routes'; import { APIClient } from '..\/..\/utils\/types\/api\/client'; import { AuthUser } from '..\/..\/utils\/types\/api\/authentication'; import { getDefaultAPIContext } from '..\/context\/default-context';  class AuthAPIClient implements APIClient {   constructor(public context: APIRequestContext) {}    async getAuthTokenApi(data: AuthUser): Promise&lt;APIResponse> {     const stepName = `Getting token for user with email \"${data.email}\" and password \"${data.password}\"`;      return await test.step(stepName, async () => {       return await this.context.post(APIRoutes.Auth, { data });     });   }    async getAuthToken(data: AuthUser): Promise&lt;string> {     \/\/ Should be used like this:      \/\/ const response = await this.getAuthTokenApi(data);     \/\/ const json = await response.json();      \/\/ expect(response.status()).toBe(200);      \/\/ return json.token;      return 'token';   } }  export const getAuthAPIClient = async (): Promise&lt;AuthAPIClient> => {   const defaultContext = await getDefaultAPIContext();   return new AuthAPIClient(defaultContext); };<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c <code>APIClient<\/code> \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c <code>context<\/code> \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u0414\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432\u043d\u0443\u0442\u0440\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b. <\/p>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f questions:  <\/p>\n<pre><code class=\"typescript\">import test, { APIRequestContext, APIResponse } from '@playwright\/test'; import { expectStatusCode } from '..\/..\/utils\/assertions\/solutions'; import { APIRoutes } from '..\/..\/utils\/constants\/routes'; import { APIClient } from '..\/..\/utils\/types\/api\/client'; import { Question, UpdateQuestion } from '..\/..\/utils\/types\/api\/questions';  export class QuestionsAPIClient implements APIClient {   constructor(public context: APIRequestContext) {}    async getQuestionAPI(questionId: number): Promise&lt;APIResponse> {     return await test.step(`Getting question with id \"${questionId}\"`, async () => {       return await this.context.get(`${APIRoutes.Questions}\/${questionId}`);     });   }    async getQuestionsAPI(): Promise&lt;APIResponse> {     return await test.step('Getting questions', async () => {       return await this.context.get(APIRoutes.Questions);     });   }    async createQuestionAPI(data: Question): Promise&lt;APIResponse> {     return await test.step(`Creating question with id \"${data.id}\"`, async () => {       return await this.context.post(APIRoutes.Questions, { data });     });   }    async updateQuestionAPI(questionId: number, data: UpdateQuestion): Promise&lt;APIResponse> {     return await test.step(`Updating question with id \"${questionId}\"`, async () => {       return await this.context.patch(`${APIRoutes.Questions}\/${questionId}`, { data });     });   }    async deleteQuestionAPI(questionId: number): Promise&lt;APIResponse> {     return await<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-345874","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/345874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=345874"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/345874\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=345874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=345874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=345874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}