2015-10-17 68 views
1

我正在使用 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 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 

当我通过运行黄瓜功能/ 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 driver ruby​​的一些命令。有些东西缺失,我找不到。有谁知道我为什么会遇到这个错误?

回答

0

也许我在这里感到困惑,但:

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

+0

是的,确切地说,提交是一个ruby函数。 对不起,我最近意识到我应该使用selenium webdriver来调用submit ruby​​函数。我刚刚更新了我的帖子。 现在,我收到了NoMethodError错误。 –

+0

您正在尝试在浏览器对象上调用'submit',而不是在表单/ Selenium :: WebDriver :: Element上调用'submit'。你需要首先通过'form = driver.find_element(id:form_id)'然后'form.submit'来找到你的表单。看看是否有帮助。 –