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
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'
答案 0 :(得分:0)
解决方案是改变
class FormEdit
include Capybara::DSL
到
module FormEdit
extend Capybara::DSL