小编Gus*_*Gus的帖子

Playwright JavaScript - 如何在不同的测试中重用定位器变量?

我希望能够在所有测试中使用定位器变量,而不必每次在每个测试中都定义它。就像是:

// @ts-check
const { test, expect } = require('@playwright/test');

test.beforeEach( async ({ page }) => {
  await page.goto('[desired URL]');  
});

// I want to make this variable global to be able to use it within all the tests.
const signInBtn = page.getByTestId('some-button'); // how to resolve 'page' here??

test.describe('My set of tests', () => {

  test('My test 1', async ({ page }) => {
    await expect(page).toHaveTitle(/Some-Title/);
    await expect(signInBtn).toBeEnabled();     // I wanna use the variable here...
  });
  
  test('My test 2', …
Run Code Online (Sandbox Code Playgroud)

javascript playwright playwright-test

2
推荐指数
1
解决办法
2131
查看次数

标签 统计

javascript ×1

playwright ×1

playwright-test ×1