我正在致力于使用 playwright 创建一个成熟的测试自动化框架,该框架将具有 TDD 和 BDD 选项。为了实现 TDD 部分,我使用了 playwright 测试运行器,但是 playwright 文档似乎没有包含任何关于如何将其与 BDD 集成的内容。
但是,我已经创建了 BDD 结构并且能够运行剧作家测试。我当前面临的问题是 playwright.config.ts 中提到的超时在 BDD 中不起作用,并且当超过默认超时 5000 毫秒时,测试通常会失败。错误堆栈跟踪如下:
× When User launches Youtube # BDD\Steps\YoutubeSteps.ts:5
Error: function timed out, ensure the promise resolves within 5000 milliseconds
at Timeout.<anonymous> (D:\TestAutomationFrameworks\PlaywrightTs\node_modules\@cucumber\cucumber\src\time.ts:52:14)
at listOnTimeout (node:internal/timers:573:17)
at processTimers (node:internal/timers:514:7)
我尝试在here搜索文档,但找不到与 BDD 相关的任何内容
我尝试将 playwright.config.ts 包含在我的 cucumber.json require 块中:
{
"default": {
"paths": [
"./BDD/Features/*.feature"
],
"require": [
"./BDD/Steps/*.ts",
"./BDD/Hooks/Hooks.ts",
"./playwright.config.ts"
],
"requireModule": ["ts-node/register"],
"forceExit": true
}
}
我的 playwright.config.ts 中提到了超时,如下所示:
const config: PlaywrightTestConfig = {
use: {
headless:Config.headless,
video:{
mode:'on'
},
viewport:null
},
outputDir:'./TestResults',
timeout:120000,
fullyParallel:true,
reporter:[['junit',{outputFile:'./TestResults/TestResults.xml'}]]
};
注意:在 tdd 中使用 playwright 测试运行程序时,超时效果很好。