【问题标题】:cucumber protractor is not running with multiple tags黄瓜量角器没有运行多个标签
【发布时间】:2018-05-26 16:59:35
【问题描述】:

我很少有使用@test 和@high 标记的场景。当我使用具有以下语法的单个标签运行时,它可以正常工作。

package.json

"smoke": "babel-node node_modules/protractor/bin/protractor protractorConf.js --presets-env --cucumberOpts.tags \"@smoke\"",

但是当我运行它时,运行带有@test 和@high 标记的场景时,什么都没有发生,并且调用了0 个场景。

package.json

"high": "babel-node node_modules/protractor/bin/protractor protractorConf.js --presets-env --cucumberOpts.tags \"@test,@high\""

我尝试了以下许多选项,但没有任何效果。

--cucumberOpts.tags "@test" --cucumberOpts.tags "@high"
--cucumberOpts.tags @test --cucumberOpts.tags @high
--cucumberOpts.tags "(@test and @high)"
--cucumberOpts.tags "@test and @high"

请帮助我了解如何运行多个 AND 和 OR 场景。以下是我的包版本。

"cucumber": "^4.2.1",
"protractor": "^5.3.2",
"protractor-cucumber-framework": "^5.0.0"

下面是我调用命令时的实际输出。

c:\Personal\ATDD  (protractortest@1.0.0)
λ npm run high

> protractortest@1.0.0 high c:\Personal\ATDD
> babel-node node_modules/protractor/bin/protractor protractorConf.js --presets-env --cucumberOpts.tags "@test,@high"

(node:8100) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[11:48:21] I/launcher - Running 1 instances of WebDriver
[11:48:21] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
(node:8100) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.


0 scenarios
0 steps
0m00.000s
Cucumber HTML report c:\Personal\ATDD\reports\html/cucumber_reporter.html generated successfully.
[11:48:25] I/launcher - 0 instance(s) of WebDriver still running
[11:48:25] I/launcher - chrome #01 passed

【问题讨论】:

    标签: protractor cucumber cucumberjs


    【解决方案1】:

    回答

    为了解释发生了什么,您希望指定的两个标签都运行,即使场景没有两个标签。

    为此,您需要在标签表达式中使用or 关键字。

    "@test or @high" 就是你要找的。​​p>

    更多关于标签表达式的信息

    运行单个标签:

    • --cucumberOpts.tags "@tag1" - 运行带有 @tag1 标记的场景
    • --cucumberOpts.tags "not @tag1" - 运行未使用 @tag1 标记的场景

    如果要运行多个标签,或者指定不运行的标签:

    • --cucumberOpts.tags "@tag1 or @tag2" - 运行带有 @tag1@tag2 或两者标记的场景
    • --cucumberOpts.tags "@tag1 and @tag2" - 运行带有 @tag1@tag2 标记的场景
    • --cucumberOpts.tags "@tag1 not @tag2" - 运行带有 @tag1 标记但未使用 @tag2 标记的场景

    对于更复杂的标记表达式,您可以使用括号来清楚起见,或更改运算符优先级:

    • --cucumberOpts.tags "@tag1 and not (@tag2 or @tag3)" - 运行带有 tag1 标记的场景,其中没有标签 @tag2 或 @tag3
    • --cucumberOpts.tags "(not @tag1) and (@tag2 or @tag3)" - 运行未标记为 @tag1 但标记为 @tag2@tag3 或两者兼有的场景

    【讨论】:

      【解决方案2】:

      我在这里发现了问题。实际上,我误解了 @test 和 @high 会调用任何一个标记的场景。我现在知道它会调用一个带有@test & @high 标记的场景,如下所示

      @smoke @test @high
      Scenario: ...
      Given ... 
      When ...
      Then ...
      

      不喜欢

      @smoke @test
      Scenario: ...
      Given ... 
      When ...
      Then ...
      
      @smoke @high
      Scenario: ...
      Given ... 
      When ...
      Then ...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多