为什么黄瓜量角器不会完全忽略没有要运行的标签的特征文件?

use*_*625 5 protractor cucumberjs

我正在使用黄瓜量角器框架来运行功能文件。

在我的 config.js 中,我有:

specs: [
    "../../features/XXX1.feature",
    "../../features/XXX2.feature",
    ... 
    "../../features/XXXn.feature",                            
],

cucumberOpts: {
    tags: "@mytag",
},
Run Code Online (Sandbox Code Playgroud)

在我的功能文件 XXX1.feature 中,我设置了这个标签“@mytag”:

  @mytag
  Scenario Outline: my Flow
    Given I am running test case one
    ....
Run Code Online (Sandbox Code Playgroud)

但不在任何其他功能文件中,如 XXX2.feature、XXX3.feature 等。

我期望量角器仅运行 XXX1.feature,而不运行 XXX2.feature。确实如此,当谈到 XXX2.feature 时,它​​会启动浏览器,什么也不做,然后输出以下内容:

[14:35:53] I/testLogger - [chrome #01-2] PID: 14272
[chrome #01-2] Specs: D:\ptfbc\ui\features\XXX2.feature
[chrome #01-2]
[chrome #01-2] [14:35:44] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
[chrome #01-2]
[chrome #01-2]
[chrome #01-2] 0 scenarios
[chrome #01-2] 0 steps
[chrome #01-2] 0m00.000s
Run Code Online (Sandbox Code Playgroud)

但它仍然不够好。由于 XXX2.feature 中没有标签“@mytag”。它不应该跳过功能文件 XXX2.feature 并且根本不启动浏览器吗?

为每个没有“@mytag”的不合格功能文件启动浏览器也很耗时。

有没有一种配置方法可以避免这种情况?

编辑

功能和 hook.ts

capabilities: {
    browserName: "chrome",
    shardTestFiles: true,
    maxInstances: 1,
    'chromeOptions': {
        'args': [
            'disable-infobars'//,'headless=true','disable-gpu=true',
        ],
        'prefs': {
            'credentials_enable_service': false,
            'download': {
                'prompt_for_download': false,
                'directory_upgrade': true,
            }
        }
    }
},


const { BeforeAll, After, Status } = require("cucumber");
import * as fs from "fs";
import { browser } from "protractor";
import { config } from "../config/config";  

BeforeAll({timeout: 300 * 1000}, async () => {
    await browser.get(config.baseUrl);
});

After(async function(scenario) {
        // screenShot is a base-64 encoded PNG
         const screenShot = await browser.takeScreenshot();
         this.attach(screenShot, "image/png");
});
Run Code Online (Sandbox Code Playgroud)

Bha*_*r S 0

您犯了一个小错误,将其更改为 Before 而不是 beforeAll。

并确保您有一个给定的小黄瓜,以便每个场景都导航到主页或网址。

Given I am navigating to homepage
Run Code Online (Sandbox Code Playgroud)

这将有你的browser.navigate(url)