代码之家  ›  专栏  ›  技术社区  ›  mmar

黄瓜量角器没有使用多个标签运行

  •  0
  • mmar  · 技术社区  · 7 年前

    我有几个场景标记为@test和@high。当我使用以下语法的单个标记运行时,它运行良好。

    包裹json

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

    但当我运行这个程序时,要运行同时带有@test和@high标记的场景,什么都不会发生,只会调用0个场景。

    包裹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或场景。下面是我的软件包版本。

    "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
    
    2 回复  |  直到 7 年前
        1
  •  3
  •   KyleFairns    7 年前

    答复

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

    为此,你需要 or 标记表达式中的关键字。

    "@test or @high" 这就是你想要的。

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

    要运行单个标记,请执行以下操作:

    • --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
  •  0
  •   mmar    7 年前

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

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

    而不是像

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