Permission denied to access property "textContent" (Selenium::WebDriver::Error::JavascriptError
Permission denied to access property "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)` .
如果需要更多信息,请告诉我。
任何改进方法都会很棒。此外,我接受所有关于自动化完整性测试的建议。
在不知道您使用的是什么版本的情况下,很难确切地说出是什么导致了您遇到的错误,但我猜想升级到最新版本的 Capybara 可能会修复该错误。除此之外,您的测试中还有一些需要改进的地方。
has_xxx?
方法有一个等待行为 built-in 当您期望他们检查的事情在 95% 以上的时间内发生时,这很有用,但如果它更多像 50/50 那么你的测试比它需要的要慢。
永远不要对 has_xxx?
方法的结果使用预期,而只是使用 have_xxx
匹配器,因为错误消息在出现故障时会更具描述性和有用性
你不应该将 current_url
/current_path
与 eq
/match
匹配器一起使用,而应该使用 have_current_path匹配器。由于重试行为 built-in,这将使您的测试更加稳定。
不要混用 expect 和 should 语法,这会导致难以 read/understand 测试。
综合起来,你的测试应该更像
# 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
我正在尝试修复旧的自动化测试脚本以供工作。我是编程新手,我已经做到了这一点:
# 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?
方法有一个等待行为 built-in 当您期望他们检查的事情在 95% 以上的时间内发生时,这很有用,但如果它更多像 50/50 那么你的测试比它需要的要慢。永远不要对
has_xxx?
方法的结果使用预期,而只是使用have_xxx
匹配器,因为错误消息在出现故障时会更具描述性和有用性你不应该将
current_url
/current_path
与eq
/match
匹配器一起使用,而应该使用 have_current_path匹配器。由于重试行为 built-in,这将使您的测试更加稳定。不要混用 expect 和 should 语法,这会导致难以 read/understand 测试。
综合起来,你的测试应该更像
# 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