Нет описания

restFixture.js 724B

12345678910111213141516171819202122232425262728
  1. import { test as base } from '@playwright/test';
  2. import fs from 'node:fs';
  3. import dotenv from 'dotenv';
  4. const _API_URL = 'http://127.0.0.1:8000';
  5. export const test = base.extend({
  6. rest: async ({ playwright }, use) => {
  7. // Set up the fixture.
  8. const envFile = fs.readFileSync('../.env');
  9. const env = dotenv.parse(envFile);
  10. const apiContext = await playwright.request.newContext({
  11. baseURL: _API_URL,
  12. extraHTTPHeaders: {
  13. 'Authorization': `Bearer ${env.IRIS_ADM_API_KEY}`,
  14. 'Content-Type': 'application/json'
  15. },
  16. });
  17. // Use the fixture value in the test.
  18. await use(apiContext);
  19. // Clean up the fixture.
  20. await apiContext.dispose();
  21. },
  22. });