2013-03-20 38 views
0
Scenario: Testing with prompt popups 
Given I am on the frames page 
When I popup the prompt and enter "Jared Gatorboy" 
    SyntaxError: missing ; before statement (Selenium::WebDriver::Error::JavascriptError) 
    ./features/support/pages/frames_page.rb:35:in `block in prompt_value' 
    ./features/support/pages/frames_page.rb:34:in `prompt_value' 
    ./features/step_definitions/web01_steps.rb:35:in `block (2 levels) in <top (required)>' 
    ./features/step_definitions/web01_steps.rb:34:in `/^I popup the prompt and enter "(.*?)"$/' 
    features/web01.feature:20:in `When I popup the prompt and enter "Jared Gatorboy"' 
Then the message from the prompt should read "enter your name" 
And the default value from the prompt should be "John Doe" 

./features/support/pages/frames_page.rb獲取調用從頁面對象寶石提示方法

def prompt_value(value) 
in_frame(:id => 'frame_3') do |frame| 
    @prompt_response = prompt(value, frame) do 
    button_element(:id => 'prompt_button', :frame => frame).click 
    end 
end 
@prompt_response 
end 

./features/step_definitions/web01_steps.rb

當一個JavaScript錯誤
When(/^I popup the prompt and enter "(.*?)"$/) do |value_to_enter| 
on_page(FramesPage) do |page| 
    @prompt_response = page.prompt_value(value_to_enter) 
end 
end 

App URL

回答

0

你能告訴我你使用的是什麼瀏覽器和驅動程序?在頁面對象測試套件中有一個使用此頁面的測試。下面是步驟定義

When /^I trigger a prompt within a frame$/ do 
    @page.in_frame(:id => 'frame_3') do |frame| 
    @msg = @page.prompt("Cheezy", frame) do 
     @page.button_element(:id => 'prompt_button', :frame => frame).click 
    end 
    end 
end 

它看起來是你在你的步驟具有相同的邏輯和測試使用兩個硒的webdriver和的Watir-的webdriver作爲司機的最新的Firefox工作。