简体   繁体   English

我如何选择不运行黄瓜功能

[英]how do I optionally not run a cucumber feature

I want to not run certain cucumber feature if, say, I'm on windows. 我想不要运行某些黄瓜功能,比如说,我在窗户上。 Google and the cucumber docs seemed to turn up dry so appealing here. 谷歌和黄瓜文档似乎变得干涸,所以在这里很吸引人。

Thanks! 谢谢!

Supporting Tyler's answer I would like to propose this additional information: 支持Tyler的回答我想提出这些额外的信息:

Use Cucumber Profiles 使用黄瓜配置文件

If you are running the system on multiple different environments you may want to create a profile file and then simply define a default profile for you which excludes the file. 如果您在多个不同的环境中运行系统,则可能需要创建配置文件,然后只为您定义一个排除该文件的默认配置文件。

# config/cucumber.yml
##YAML Template
---
windows: --tags ~@not-windows
default: --tags @not-windows

Execution (on a non-windows system / default) 执行(在非Windows系统/默认情况下)

$ cucumber

Execution (on a windows system): 执行(在Windows系统上):

$ cucumber -p windows

You could set the default to whichever environment you are currently on to save yourself having to remember which features do not executing; 您可以将默认值设置为当前所处的环境,以节省自己必须记住哪些功能不执行; allowing you to just execute cucumber . 让你只是执行cucumber

Use Cucumber Rake Task 使用黄瓜耙任务

Create a rake task that checks your environment and includes the tag you want: 创建一个rake任务,检查您的环境并包含您想要的标记:

require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'

WINDOWS_PLATFORM = /mswin|win32|mingw/ unless defined? WINDOWS_PLATFORM

Cucumber::Rake::Task.new(:features) do |t|
  tags = (RUBY_PLATFORM =~ WINDOWS_PLATFORM ? "~@not-windows" : "@not-windows")
  t.cucumber_opts = "features #{tags}"
end

Execution (on either platform): 执行(在任一平台上):

$ rake features

This should automatically include the right tag based on your environment. 这应该根据您的环境自动包含正确的标记。

The best way to approach this would likely be using tags. 处理此问题的最佳方法可能是使用标签。

For example, if you add a tag like @not-windows to a feature you can then customize your cucumber execution to ignore this. 例如,如果您向某个功能添加@not-windows等标记,则可以自定义黄瓜执行以忽略此功能。

@not-windows
Feature: Your feature that causes a problem
  your scenarios

If you then run your tests with cucumber --tags ~@not-windows it will run all cukes that are not tagged by @not-windows. 如果你用cucumber --tags ~@not-windows运行测试,它将运行所有没有被@ not-windows标记的cukes。 The ~ is what causes the "not" behavior, you could run ONLY these tags by doing cucumber --tags @not-windows . 〜是导致“不”行为的原因,你可以通过执行cucumber --tags @not-windows来运行这些标签。 Using the first cucumber line while in Windows, you can block the problematic features (or individual scenarios) from running but if you're on another OS and run cucumber normally, these will still be ran. 在Windows中使用第一个黄瓜线,你可以阻止运行中有问题的功能(或个别场景),但如果你在另一个操作系统并正常运行黄瓜,这些仍将运行。

Reference: https://github.com/cucumber/cucumber/wiki/Tags 参考: https//github.com/cucumber/cucumber/wiki/Tags

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM