1

我正在使用 Selenium 与 Capybara 和 Cucumber 在 Ruby Mine 中针对 Chrome 浏览器运行自动化测试。我已将 selenium-webdriver 更新为 4.0.0.alpha5 版本(之前的版本是 3.13.1),之后我发现访问 Capybary 函数时发生了一些异常,当发生此错误时,我总是收到此消息:

NameError: uninitialized constant Selenium::WebDriver::Error::UnhandledError

我希望在文档中找不到与元素相关的错误或任何有意义的原因,此消息阻止解决代码中的潜在问题。

如何避免此消息?为了正确捕获异常,是否需要进行任何错误配置?

- 编辑 -

堆栈跟踪:

NameError: uninitialized constant Selenium::WebDriver::Error::UnhandledError
./features/step_definitions/dspFramework_steps/navigation.rb:314:in `assertPageTitle'
./features/step_definitions/dspFramework_steps/navigation.rb:293:in `/^I assert that the page's title is( not)? "([^"]*)"/'
./features/step_definitions/dspFramework_steps/common_steps.rb:260:in `/^I click the site logo$/'
./features/dspApps_features/DSPCommon_features/DSPCommon_Add_DebugLog_CustomWebapp.feature:23:in `Then I click the site logo'

assertPageTitle 方法在这一行失败

if pageFocus.has_selector?('span.highcharts-title')
4

1 回答 1

0

我已经通过将 capybara gem 更新到目前的最新版本(3.33.0)解决了这个问题,在此之前,我一直在使用 3.10.1 版本进行测试。更新后,之前的错误不再发生,当我在测试中强制出错时,我收到了来自 Capybara 的正确错误消息:

Capybara::ExpectationNotMet: expected to find css ".detailtable" within #<Capybara::Node::Element tag="div" path="/HTML/BODY[1]/DIV[1]/DIV[2]/DIV[3]/DIV[1]"> at least 1 time but there were no matches
于 2020-11-09T10:11:09.333 回答