2017-01-30 85 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

谢谢,会试试看。感谢您的帮助! –

相关问题