2013-08-28 50 views
0

運行我的功能文件時出現此錯誤。Ruby頁面對象Gem - 無法爲提供的瀏覽器選擇平臺(RuntimeError)

無法挑選所提供的瀏覽器(RuntimeError)需要

幫助的平臺,請。

這是代碼;

class GooglePage 
    include PageObject 

    def self.visitor 
    visit("http://www.google.com") 
    end 

end 

env.rb

require 'selenium-webdriver' 
require 'page-object' 
require 'rubygems' 
require 'page-object/page_factory' 

World (PageObject::PageFactory) 
@browser = Selenium::WebDriver.for :firefox 


Step-Definitions 

require_relative 'GooglePage' 

Given(/^I am on the Google home page$/) do 
    visit(GooglePage) 
    # visit('http://www.google.com') 

    on(GooglePage).visitor 
end 

回答

0

這是行不通的:

visit(GooglePage) 

,因爲你已經在GooglePage不叫PAGE_URL(LN低於4)

class GooglePage 
    include PageObject 

    page_url "http://www.google.com"  

    def self.visitor 
    visit("http://www.google.com") 
    end 

end 
0

招行@browser =硒:: WebDriver.for:火狐以前方法hooks.rb

Before do 
    @browser = Selenium::WebDriver.for :firefox 
end 

After do 
    @browser.close 
end 
0

什麼,如果你讓你的耙文件密碼的標籤和瀏覽器和網址,例如 rake my_task BROWSER=chrome URL=http://google.com.au

和掛鉤將檢查BROWSER是否爲chrome,然後將使用特定的Webdriver作爲chrome。但是如何在PageObject中傳遞URL呢?

從掛鉤

目前我有FF:

when "chrome" then 
    caps = Selenium::WebDriver::Remote::Capabilities.chrome 
    caps.version = "40.0.2214.115 m" 
    caps.native_events = false 
    caps.javascript_enabled= true 

    # This is for increasing the default timeout to 180 
    client = Selenium::WebDriver::Remote::Http::Default.new 
    client.timeout = 180 

    browser = Selenium::WebDriver.for :chrome 
    browser.manage.window.maximize 


end 

Before do 
browser.cookies.clear 
@browser = browser 
end 

After do 
unless ENV["BROWSER"].eql? "ie" 
    browser.close 
    sleep 2 
end 
end 

然後在我的主頁pageobject我有FF:

class HomePage 
include PageObject 

page_url("#{ENV['URL']}") 

#opens the url defined in ENV['URL'] 
def goto_homepage 
    visit(HomePage) 
end 

end 

使用的Watir,網址得到開業,硒所以嘗試了這一點它不會工作。

相關問題