剧作家:.toBeVisible() 超时被忽略

问题描述 投票:0回答:1

我在 Playwright 1.18 toBeVisible() 期望中遇到了不明确的行为。 这是测试行:

await expect(this.page.locator('.top-row .close i')).toBeVisible({timeout: 2000 })

如果元素不可见,它将永远挂起。

如果我跳到

toBeTruthy.js -> toBeTruthy
代码,我会看到尽管收到了选项,超时仍计算为0:

由于某种原因,使用的

_toMatchText
匹配器当前超时。这是一个错误还是我做错了什么?

Package.json:

"devDependencies": {
    "@playwright/test": "^1.18",
    "allure-commandline": "^2.17.2",
    "allure-playwright": "^2.0.0-beta.14",
    "rimraf": "3.0.2"
  }

剧作家配置:

import { PlaywrightTestConfig, devices } from '@playwright/test';

const config: PlaywrightTestConfig = {
  testDir: './spec',
  timeout: 10 * 1000,

  expect: {
    timeout: 3 * 1000
  },

  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 5 : 1,

  reporter: [
    ['line'],
    ['json', { outputFile: './test-results/results.json' }],
    ['./util/test-start-stop-reporter.ts'],
    ['allure-playwright']
  ],

  use: {
    baseURL: 'http://localhost:8080',
    screenshot: 'only-on-failure',
    channel: 'chrome', //https://playwright.dev/docs/browsers#chromium
    headless: false,
    viewport: { width: 1820, height: 950 },
    ignoreHTTPSErrors: true,
    video: 'retain-on-failure',

    actionTimeout: 5 * 1000,
    navigationTimeout: 30 * 1000,
    launchOptions: {
      args: ['--window-position=1980,10'],
      devtools: process.env.PWDEBUG ? true : false,
    },

  },

  projects: [
    {
      name: 'Google Chrome',
      use: {
        channel: 'chrome',
      },
    },
  ],
  outputDir: 'test-results/',
};
export default config;
javascript automated-tests playwright playwright-test
1个回答
0
投票

toBeVisible 是一个自动重试断言,它不仅检查可见性,而且不断重新检查,直到断言变为 true 或超时。

// A specific element is visible.
await expect(page.getByText('Welcome')).toBeVisible({timeout:5000}); 
© www.soinside.com 2019 - 2024. All rights reserved.