[英]Failed to run custom step with the selenium cucumber ruby
I am writing a test for desktop web automation using the selenium cucumber ruby . 我正在使用硒黄瓜红宝石编写用于桌面Web自动化的测试。 My test includes both predefined and custom steps.
我的测试包括预定义步骤和自定义步骤。
However, my test fails to run due to an error caused by a custom step. 但是,由于自定义步骤引起的错误,我的测试无法运行。
The feature file that I run: 我运行的功能文件:
Feature: Login a customer
Scenario: Go in a call
Given I navigate to <url>
...
When I submit the form with id "custSearchSimple"
....
And I wait for 5 sec
Then element having id "accNumber" should be present
The When I submit the form with id "custSearchSimple" is a custom step. 当我提交ID为“ custSearchSimple”的表单时,这是一个自定义步骤。 This step is defined in the custom_step.rb.
此步骤在custom_step.rb中定义。 I have used the submit command of the Selenium Cucumber Ruby API .
我已经使用了Selenium Cucumber Ruby API的Submit命令。 The custom_step.rb is the following file:
custom_step.rb是以下文件:
require 'selenium-cucumber'
# Do Not Remove This File
# Add your custom steps here
# $driver is instance of webdriver use this instance to write your custom code
#firefox browser instantiation
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "https://localhost/telebet"
When(/^I submit the form with id "(.*?)"$/) do |arg1|
element= driver.submit(:id,"#{arg1}")
end
When I run the feature file by running cucumber features/name_of_the_file.feature, I get the NoMethodError error: 当我通过运行黄瓜功能/name_of_the_file.feature运行功能文件时,出现NoMethodError错误:
When I submit the form with id "custSearchSimple" # features/step_definitions/custom_steps.rb:12
private method `submit' called for #<Selenium::WebDriver::Driver:0x94c4bde4bdff4d6 browser=:firefox> (NoMethodError)
I could not find any example using the Selenium Cucumber Ruby API for writing custom steps. 我找不到使用Selenium Cucumber Ruby API编写自定义步骤的任何示例。 I suspect that I might have omitted some commands for the selenium web driver ruby.
我怀疑我可能已经省略了一些用于Selenium Web驱动程序ruby的命令。 Something is missing that I could not find.
找不到我找不到的东西。 Does anyone know why I get this error?
有谁知道为什么我会收到此错误?
Maybe I am confused here but: 也许我很困惑,但是:
When(/^I submit the form with id "(.*?)"$/) do |arg1|
submit_form arg1
end
def submit_form(form_id)
submit("id", form_id)
end
Would do what you want? 你想做什么?
submit_form
isn't a cucumber step, it's a ruby method - probably why you're getting Cucumber::UndefinedDynamicStep
. submit_form
不是一个黄瓜步骤,而是一个红宝石方法-可能是为什么您得到Cucumber::UndefinedDynamicStep
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.