繁体   English   中英

无法使用硒黄瓜红宝石运行自定义步骤

[英]Failed to run custom step with the selenium cucumber ruby

我正在使用硒黄瓜红宝石编写用于桌面Web自动化的测试。 我的测试包括预定义步骤和自定义步骤。

但是,由于自定义步骤引起的错误,我的测试无法运行。

我运行的功能文件:

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

当我提交I​​D为“ custSearchSimple”的表单时,这是一个自定义步骤。 此步骤在custom_step.rb中定义。 我已经使用了Selenium Cucumber Ruby APISubmit命令。 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

当我通过运行黄瓜功能/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)

我找不到使用Selenium Cucumber Ruby API编写自定义步骤的任何示例。 我怀疑我可能已经省略了一些用于Selenium Web驱动程序ruby的命令。 找不到我找不到的东西。 有谁知道为什么我会收到此错误?

也许我很困惑,但是:

When(/^I submit the form with id "(.*?)"$/) do |arg1|
  submit_form arg1
end

def submit_form(form_id)
  submit("id", form_id)
end

你想做什么? submit_form不是一个黄瓜步骤,而是一个红宝石方法-可能是为什么您得到Cucumber::UndefinedDynamicStep

暂无
暂无

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

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