首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@ Variables在Gherkins/Cucumber测试中为空

问@ Variables在Gherkins/Cucumber测试中为空
EN

Stack Overflow用户
提问于 2016-04-27 19:21:14
回答 1查看 75关注 0票数 0

这是我的测试,但是即使@timeout_exception在代码运行期间工作,它在测试期间也是空的。那么,如何测试是否设置了此变量呢?

代码语言:javascript
复制
Then(/^the output should be '(.*)'$/) do |expectedException|
  expect(@timeout_exception).to eq(expectedException)
end

这是包exec cucumber运行的输出。

代码语言:javascript
复制
And the output should be 'Execution Timeout Error: This deployment has taken too long to run'                                     # features/step_definitions/my_steps.rb:309

  expected: "Execution Timeout Error: This deployment has taken too long to run"
       got: nil

  (compared using ==)
   (RSpec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/my_steps.rb:310:in `/^the output should be '(.*)'$/'
  features/timeout_lengthy_deploys.feature:25:in `And the output should be 'Execution Timeout Error: This deployment has taken too long to run''

Failing Scenarios:
cucumber features/timeout_lengthy_deploys.feature:11 # Scenario: Normal deploy that times out because it takes too long
EN

回答 1

Stack Overflow用户

发布于 2016-04-27 21:06:42

Selenium有自己的等待时间,如果设置的等待时间少于预期的等待时间,那么您将永远不会看到预期的等待被触发。讲得通?

下面将页面加载的最大等待时间设置为5秒

代码语言:javascript
复制
@browser.driver.manage.timeouts.page_load = 5

脚本超时是另一个原因(通常与Ajax一起使用)

代码语言:javascript
复制
@browser.driver.manage.timeouts.script_timeout = 5
@browser.execute_script("return jQuery.active")

隐式等待是Selenium等待元素上的操作完成的最长等待时间。如果这首先触发,那么您的期望将失败。

代码语言:javascript
复制
@browser.driver.manage.timeouts.implicit_wait = 5

我建议在测试之前将implicit_wait设置为比超时更高的值,然后在测试结束后将其设置回来。顺便说一句,如果你的超时引发了一个异常,你将需要一个救援块。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36888292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档