我正在使用 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
的当我提交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
当我通过运行黄瓜功能/ 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的一些命令。有些东西缺失,我找不到。有谁知道我为什么会遇到这个错误?
是的,确切地说,提交是一个ruby函数。 对不起,我最近意识到我应该使用selenium webdriver来调用submit ruby函数。我刚刚更新了我的帖子。 现在,我收到了NoMethodError错误。 –
您正在尝试在浏览器对象上调用'submit',而不是在表单/ Selenium :: WebDriver :: Element上调用'submit'。你需要首先通过'form = driver.find_element(id:form_id)'然后'form.submit'来找到你的表单。看看是否有帮助。 –