Capybara与子类没有方法错误

时间:2015-03-16 20:46:53

标签: ruby capybara

require 'rubygems'
require 'capybara'
require 'capybara/dsl'


Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.domain.com'


module Test
  include Capybara::DSL

  class Bot 
    include Capybara::DSL

    def login(username,password)
      #STEP 1
      uri = "https://www.domain.com"
      visit(uri)

      # LOG IN FORM
      find('#username').set(username)
      find('#password').set(password)

      find('#submitButton').click
    end

    def goto_page2
      #STEP 2
      uri_cert = 'https://www.domain.com/page1'
      visit(uri_cert)
      find('#submitButton').click      
    end 


    def form(answers)
      # Step 3
      FormEdit.q1(answers['q1'])
    end

    #####################################
    # Questions for the form

    class FormEdit
      include Capybara::DSL

      #STEP 3
      # true for Yes
      # false for No

      def self.q1(yesno)

        #yesno
        id = (yesno) ? '#radioyes' : '#radioNo'
        find(id).set(true) 
      end
    end
  end
end

RUN SCRIPT

t = Test::Bot.new

username = 'myusername'

password = 'mypassword'

t.login(username, password)

answers = { q1:true }

t.form(answers)

运行时出错:

FormEdit.q1(answers['q1'])
NoMethodError: undefined method `find' for Test::Bot::FormEdit:Class
from test_script.rb:56:in `q1'

任何建议?

1 个答案:

答案 0 :(得分:0)

解决方案是改变

class FormEdit
      include Capybara::DSL

module FormEdit
      extend Capybara::DSL