Is there a way to slow down execution of Watir Webdriver under Cucumber?

坚强是说给别人听的谎言 提交于 2019-12-18 09:45:41

问题


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

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


回答1:


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.

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

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




回答2:


Not universally. You could Monkey Patch the element_call method to add a sleep after every interaction with a Selenium Element. Import this code after requiring watir-webdriver.

module Watir
  class Element
    alias_method :watir_element_call, :element_call
    def element_call &block
      watir_element_call &block
      sleep 1
    end          
  end    
end

Also note, that Monkey Patching is generally a bad idea, and when I change the implementation (which I plan to), this code will break.



来源:https://stackoverflow.com/questions/33268930/is-there-a-way-to-slow-down-execution-of-watir-webdriver-under-cucumber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!