1.下载安装Ruby
安装Cucumber要用到gem,gem是Ruby程序管理工具,类似于linux中的apt-get。所以要在Windows中安装好Ruby1.9.2的版本相对稳定些,在这里可以下载Ruby,Windows的安装包一路Next就可以了,安装完成后以cmd输入:ruby -v查看版本,如果提示不是内部命令,着加系统环境变量。
升级gems
gem update --system
2.安装Devkit
Devkit是Ruby在Windows下的开发工具集,在这里可以下载Devkit,下载后解压到D:\Devkit目录下,打开cmd运行以下命令
cd d:\Devkit ruby dk.rb init ruby dk.rb review ruby dk.rb install
运行以上命令可以看到以下相应的提示,说明安装成功了
C:\DevKit>ruby dk.rb init [INFO] found RubyInstaller v1.9.2 at C:/Ruby192 Initialization complete! Please review and modify the auto-generated 'config.yml' file to ensure it contains the root directories to all of the installed Rubies you want enhanced by the DevKit. C:\DevKit>ruby dk.rb review Based upon the settings in the 'config.yml' file generated from running 'ruby dk.rb init' and any of your customizations, DevKit functionality will be injected into the following Rubies when you run 'ruby dk.rb install'. C:/Ruby192 C:\DevKit>ruby dk.rb install [INFO] Updating convenience notice gem override for 'C:/Ruby192' [INFO] Installing 'C:/Ruby192/lib/ruby/site_ruby/devkit.rb'
3.安装Cucumber
这时可以打开cmd运行命令安装Cucumber以及相关的一些工具
gem install cucumber gem install selenium-webdriver gem install capybara gem install rspec
安装过程可能出现这种错误:ERROR: Failed to build gem native extension
我也找了很久也找不到问题的原因,谷歌搜后找到国外的网站有提到这个错误,讲到有两种情况会产生这个错误,我把其中一种方法贴出来
If the problem persist, invoke the following commands in the same command prompt:(在cmd里运行以下命令,查看结果)
REG QUERY "HKCU\Software\Microsoft\Command Processor" REG QUERY "HKLM\Software\Microsoft\Command Processor"
Execute each line individually. Once you run it, will see something like this:(当运行上面的命令时,可以看到以下信息)
HKEY_CURRENT_USER\Software\Microsoft\Command Processor CompletionChar REG_DWORD 0x9 DefaultColor REG_DWORD 0x0 EnableExtensions REG_DWORD 0x1 PathCompletionChar REG_DWORD 0x9
The columns of information are Key, Type and Value. If you see a key named AutoRun
, there is a chance this is the culprit of the error you’re receiving.
AutoRun
interferes with Ruby messing with child process executing and by result, affecting gem installation. Please remove it with the following command:(运行以下命令)
REG DELETE "HKCU\Software\Microsoft\Command Processor" /v AutoRun
Once you’re done, try opening a new command prompt and executing gem installation again.(大概意思是去除注册表中的“AutoRun”键)
在cmd中运行Cucumber就可以看到各种提示,因为还没有写features文件,在Windows下feature文件用中文的关键字就无法显示颜色,这时可以安装ansi151.zip,在cmd中ansicon.exe -i安装,ansicon.exe -u删除。但是对utf-8的处理有问题,不建议安装。只要用在feature文件中用英文的关键字就可以显示颜色。