简体   繁体   中英

Failed to run custom step with the selenium cucumber ruby

I am writing a test for desktop web automation using the selenium cucumber ruby . 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. This step is defined in the custom_step.rb. I have used the submit command of the Selenium Cucumber Ruby API . The custom_step.rb is the following file:

    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:

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. I suspect that I might have omitted some commands for the selenium web driver 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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