【问题标题】:How to write a simple Cucumber script如何编写一个简单的 Cucumber 脚本
【发布时间】:2017-05-16 22:56:53
【问题描述】:

我正在按照教程运行我的第一个 Cucumber 脚本:

Feature: guru99 Demopage Login   
In order to Login in Demopage we have to enter login details

Scenario: 
Register On Guru99 Demopage without email
Given I am on the Guru99 homepage
When enter blank details for register
Then error email shown

我在 Idea 中有项目,但运行时出现错误。

使用 chrome 时:

Failed to open TCP connection to 127.0.0.1:9515 (No connection could be made because the target machine actively refused it.

我不知道如何解决它。

使用 Firefox 时,脚本成功打开浏览器但之后失败:

require 'watir'
require 'colorize'
Selenium::WebDriver::Firefox::Binary.path='C:\soft\Mozilla Firefox\firefox.exe'
case ENV['BROWSER']
  when 'chrome'
    browser = Watir::Browser.new :chrome
  when 'firefox'
    browser = Watir::Browser.new :firefox
end

Given(/^I am on the Guru99 homepage$/)do
  @browser = Watir::Browser.new :firefox
  @browser.goto "http://demo.guru99.com"
end

When(/^enter blank details for register$/) do
  browser.text_filed(:name,"emaiid").set("")
  browser.button(:name,"btnLogin").click
end

Then(/^error email shown$/) do
  puts "Email is Required!".red
  browser.close
end

然后返回:

NoMethodError: undefined method `text_filed' for nil:NilClass

在这一行:

browser.text_filed(:name,"emaiid").set("")

我发现了一些我需要编写一个类来调用方法的参考资料。我试过但没有成功。

【问题讨论】:

标签: ruby google-chrome firefox methods cucumber


【解决方案1】:

连接被拒绝,我不确定,但“Watir+Cucumber Connection refused”看起来可以解决。

复制意大利面:

AfterConfiguration do |config|
   yourCodeStartUp()                    # Put your SETUP code here including the launch of webdriver
   at_exit 
       yourCodeTearDown()               # Put your CLOSING routine here
       puts 'stopped'
   end
end

代码错误是拼写错误,应该是browser.text_field(...

【讨论】:

  • >一些标志更改可能会解决这个问题,谢谢。去谷歌>代码错误是我的错字耻辱>
  • 他们。我应该将我的场景代码粘贴到括号中吗?那么他们所说的“关闭程序”是什么意思。恐怕我不太明白=\
【解决方案2】:

关于您在 chrome 上观察到的问题,听起来您需要更新 chromedriver(并确保 exe 在 PATH 中)。如果您运行的是 chrome v56-58,则需要 ChromeDriver 2.29。

关于NoMethodError: undefined method 错误,您在调用text_field 方法时有一个错字(即browser.text_filed)。

【讨论】:

  • 嗨。是的,我已经纠正了我的错字,脚本在 Firefox 中运行。关于 chrome,我相信我已经使用了 2.29,但我会 2check。路径没问题。
【解决方案3】:

不,我弄错了,我有一个旧版本的 chromedriver。现在它也在 chrome 中运行。非常感谢。感谢您的时间!

所以,答案是: 1.更新chromedriver。 2. 再次检查您的代码是否有错别字。

真的很简单,但花了我很多时间%

【讨论】:

  • 如果根本问题是错字和配置相关的,最好删除这个问题。 chromedriver 的问题已经回答了很多次了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-16
  • 1970-01-01
  • 1970-01-01
  • 2012-07-08
  • 1970-01-01
相关资源
最近更新 更多