有没有办法在 Cucumber 下减慢 Watir Webdriver 的执行速度?没有办法、速度、Watir、Cucumber

由网友(人间四月天)分享简介:有什么办法可以减慢 Cucumber 下 Watir WebDriver 的执行速度?Is there any way we can slow down the execution of Watir WebDriver under Cucumber?我想直观地跟踪 Watir 执行的操作.目前,它对我的​​眼睛来说...

有什么办法可以减慢 Cucumber 下 Watir WebDriver 的执行速度?

Is there any way we can slow down the execution of Watir WebDriver under Cucumber?

我想直观地跟踪 Watir 执行的操作.目前,它对我的​​眼睛来说太快了.

I would like to visually track the actions performed by Watir. At the moment, it goes too fast for my eyes.

推荐答案

虽然 Watir 本身没有减慢执行速度的 API,但您可以使用底层 Selenium-WebDriver 的 AbstractEventListener 来添加暂停在某些类型的操作之前/之后.

While Watir itself does not have an API for slowing down the execution, you could use the underlying Selenium-WebDriver's AbstractEventListener to add pauses before/after certain types of actions.

如果您想查看操作的结果,您可能希望在更改值并单击元素后暂停.这将通过创建以下 AbstractEventListener 并在创建浏览器时将其传入来完成:

Given you want to see the result of actions, you probably want to pause after changing values and clicking elements. This would be done by creating the following AbstractEventListener and passing it in when creating the browser:

class ActionListener < Selenium::WebDriver::Support::AbstractEventListener    
  def after_change_value_of(element, driver) 
    sleep(5)
  end

  def after_click(element, driver) 
    sleep(5)
  end
end

browser = Watir::Browser.new :firefox, :listener => ActionListener.new

有关您可以监听的事件的完整列表,请参阅Selenium::WebDriver::Support::AbstractEventListener 文档.

For a full list of events that you can listen for, see the Selenium::WebDriver::Support::AbstractEventListener documentation.

阅读全文

相关推荐

最新文章