Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
访问属性“textContent”(Selenium::WebDriver::Error::JavascriptError)的权限被拒绝_Javascript_Ruby On Rails_Selenium_Cucumber_Capybara - Fatal编程技术网

访问属性“textContent”(Selenium::WebDriver::Error::JavascriptError)的权限被拒绝

访问属性“textContent”(Selenium::WebDriver::Error::JavascriptError)的权限被拒绝,javascript,ruby-on-rails,selenium,cucumber,capybara,Javascript,Ruby On Rails,Selenium,Cucumber,Capybara,我正在尝试修复一个旧的自动测试脚本以供工作使用。我是编程新手,我已经做到了这一点: # 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", :tex

我正在尝试修复一个旧的自动测试脚本以供工作使用。我是编程新手,我已经做到了这一点:

# 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)` . 
如果需要更多信息,请告诉我


任何改进的方法都是很好的。此外,我接受所有关于自动进行心智测试的方法的建议。

如果不知道您使用的是什么版本,很难说是什么原因导致了错误,但我猜升级到最新版本的Capybara可能会修复该错误。除此之外在你的测试中有一些地方需要改进

has_xxx?方法有一个内置的等待行为,当你期望他们检查的事情在95%以上的时间内发生时,这很有用,但是如果它更像50/50,那么你的测试会比需要的慢

不要对has_xxx?方法的结果使用期望值,而应使用have_xxx匹配器,因为当出现故障时,错误消息将更具描述性和实用性

决不应将当前url/current路径与eq/match匹配器一起使用,而应使用have\u current\u路径匹配器。这将使测试更加稳定,因为它内置了重试行为

不要混合使用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

请添加因该错误而获得的堆栈跟踪以及您使用的Capybara、selenium webdriver和Firefox版本我使用最新的Firefox-45.7.0。此外,gem版本有:Capybara 2.12.0、2.11.0和selenium webdriver 3.0.5、3.0.3。我的答案解决了问题吗?您选择了答案,但随后添加了gem版本-如果没有添加stacktrace的完整错误消息。我明天上班时必须检查它。我会让你知道。谢谢你的帮助。谢谢,我会尝试一下。谢谢你的帮助!