2017-01-30 68 views
0

我試圖修復一箇舊的自動測試腳本的工作。我是編程新手,我有這麼多:權限被拒絕訪問屬性「textContent」(Selenium :: WebDriver :: Error :: JavascriptError

# Check if I can play some game 
Then(/^I should be able to play (.+)$/) do |game_name| 
    # TODO: better check for game play, game end, score count 

    if page.has_content?("GUEST") 
    find(:css, ".play", :text => "Play").click 
    else 
    start_game(game_name) 
    end 
#Here is where the error pops up: 
    if page.has_content?('Writing') 
    # Dont wait for players to join 
    expect(page.has_content?('Waiting for players')).to eq(true) 
    else 
    # Check for game object 
    page.should have_css("object#game") 

    # Check if correct game loading 
    current_url.should match(/#{GameWorld::GAMES[game_name]}/) 
    end 

    #Quick escape 
    ensure_on?('city') 
end 

可能有人給我如何解決這一問題的提示

,我得到的是錯誤:?

`Error: Permission denied to access property "textContent" (Selenium::WebDriver::Error::JavascriptError)` . 

如果需要更多的信息,讓我知道

任何改進方法都會很棒。另外,我接受關於如何自動進行理智測試的所有建議。

+0

請添加要使用你與這個錯誤得到堆棧跟蹤和水豚的版本,硒的webdriver和Firefox –

+0

我使用最新的Firefox - 45.7.0。此外,寶石版本是:水豚(2.12.0,2.11.0)和硒-webdriver(3.0.5,3.0.3)。 –

+0

我的答案是否解決了這個問題? (你選擇它作爲回答,但後來添加了寶石版本) - 如果沒有添加完整的錯誤信息stacktrace。 –

回答

0

不知道你使用的是什麼版本,很難準確地說出你所得到的錯誤是什麼,但我猜想升級到最新版本的水豚可能會修復這個錯誤。除此之外,測試中還有一些需要改進的地方。

  1. has_xxx?方法已經等待行爲內置的,當你希望他們檢查了事情發生的95 +%的時間是有用的,但如果它更像是50/50那麼你的測試速度較慢比它需要。

  2. 切勿使用預期對的has_xxx?方法的結果,而不是僅僅使用have_xxx匹配,因爲當有故障

  3. 你不應該使用current_url/current_path與錯誤信息會更具描述性和有用eq/match匹配器,而應該使用has_current_path匹配器。這將使您的測試更穩定,因爲內置了重試行爲。

  4. 不要混淆expect和should語法,它會導致難以閱讀/理解測試。

把所有在一起,你的測試應該更像

# Check if I can play some game 
Then(/^I should be able to play (.+)$/) do |game_name| 
    # TODO: better check for game play, game end, score count 

    expect(page).to have_content(game_name) # This should be something that is on the page for both GUEST and logged in users just to verify the page has loaded 
    if page.has_content?("GUEST", wait: false) #disable the waiting/retrying behavior since we now know the page is already loaded 
    find(:css, ".play", :text => "Play").click 
    else 
    start_game(game_name) 
    end 

    expect(page).to have_content('Something') # Same as above - check for something that will be on the page when the actions triggered by the `click` or `start_game` calls above have finished 

    if page.has_content?('Writing', wait: false) #disable waiting because previous line has assured page is loaded 
    # Dont wait for players to join 
    expect(page).to have_content('Waiting for players') 
    else 
    # Check for game object 
    expect(page).to have_css("object#game") 

    # Check if correct game loading 
    expect(page).to have_current_path(/#{GameWorld::GAMES[game_name]}/) 
    end 

    #Quick escape 
    ensure_on?('city') 
end 
+0

謝謝,會試試看。感謝您的幫助! –

相關問題