有没有办法在 Cucumber 下减慢 Watir Webdriver 的执行速度? [英] Is there a way to slow down execution of Watir Webdriver under Cucumber?

查看:13
本文介绍了有没有办法在 Cucumber 下减慢 Watir Webdriver 的执行速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以减慢 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.

这篇关于有没有办法在 Cucumber 下减慢 Watir Webdriver 的执行速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆