【问题标题】:Failed to run custom step with the selenium cucumber ruby无法使用硒黄瓜红宝石运行自定义步骤
【发布时间】:2016-01-16 07:28:27
【问题描述】:

我正在使用 selenium cucumber ruby。 我的测试包括预定义和自定义步骤。

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

我运行的功能文件:

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

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

当我通过运行 cucumber features/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​​ 的命令。缺少一些我找不到的东西。有谁知道我为什么会收到这个错误?

【问题讨论】:

    标签: ruby selenium selenium-webdriver cucumber automated-tests


    【解决方案1】:

    也许我在这里很困惑,但是:

    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 的原因。

    【讨论】:

    • 是的,提交正是一个 ruby​​ 函数。抱歉,我最近意识到我应该使用 selenium webdriver 来调用提交 ruby​​ 函数。我刚刚更新了我的帖子。现在,我收到 NoMethodError 错误。
    • 您尝试在浏览器对象上调用submit,而不是在表单/Selenium::WebDriver::Element 上。您需要先通过form = driver.find_element(id: form_id)form.submit 之类的操作找到您的表单。看看有没有帮助。
    猜你喜欢
    • 2019-04-27
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 2013-06-17
    相关资源
    最近更新 更多