使用page-object-gem初始化页面对象

时间:2014-08-26 20:24:42

标签: ruby-on-rails ruby capybara page-object-gem

我有一系列测试,我已经为其编写了页面对象。我试图将它们转换为使用page-object-gem

page_object_base.rb

require_relative '../../selenium_helper'

module PageObjects
  class PageObjectBase

    def initialize(element = nil)
      @page = Capybara.current_session
      @element = element
    end

    def element
      @element
    end

    def click
      @element.click
    end

  end
end

sign_in_form.rb (请注意,下面注释掉的代码是我尝试使用page-object-gem替换的内容。)

require_relative '../../../selenium_helper'

module PageObjects
  module Users
    class SignInForm < PageObjectBase

      include PageObject

      def heading
        @page.find('.top_b').text
      end

      text_field(:email, :id => 'user_email')
      text_field(:password, :id => 'user_password')

      #def email=(email)
      #  @page.fill_in 'user_email', :with => email
      #end
      #
      #def email
      #  @page.find('#user_email').value
      #end
      #
      #def password=(password)
      #  @page.fill_in 'user_password', :with => password
      #end
      #
      #def password
      #  @page.find('#user_password').value
      #end

      def sign_in
        @page.find('#sign_in').click
        PageObjects::Roadmap::Roadmaps.new
      end
    end
  end
end

verify_login_test.rb

require File.expand_path("../../../selenium_helper", __FILE__)

class VerifyLoginTest < MyApp::SeleniumIntegrationTest

  test "user can login and logout" do
    visit new_user_session_path
    sign_in = PageObjects::Users::SignInForm.new
    assert_equal 'Sign in to MyApp', sign_in.heading
    sign_in.email     = email
    sign_in.password  = 'test123'
    home_page = sign_in.sign_in
    assert_equal email, home_page.current_user
  end
end

当我运行测试时,我得到以下内容:

  1) Error:
test_owner_can_login_and_logout(VerifyLoginTest):
ArgumentError: wrong number of arguments (0 for 1)
    /opt/rubies/1.9.3-p429/lib/ruby/gems/1.9.1/gems/page-object-1.0.2/lib/page-object.rb:59:in `initialize'
    /Users/me/src/myapp/test/integration/users/verify_login_test.rb:52:in `new'
    /Users/me/src/myapp/test/integration/users/verify_login_test.rb:52:in `verify_login_and_logout'
    /Users/me/src/myapp/test/integration/users/verify_login_test.rb:6:in `block in <class:VerifyLoginTest>'
    /opt/rubies/1.9.3-p429/lib/ruby/gems/1.9.1/gems/mocha-1.0.0/lib/mocha/integration/mini_test/version_230_to_2101.rb:36:in `run'

任何帮助都将非常感激。

0 个答案:

没有答案