Changing the speed of tests?

Upgrade with more context: Selenium 1 had a command called "setSpeed". This allowed to slow down the execution of each command in X milliseconds. The team behind Selenium 2 (Webdriver) decided to abandon this team, and now there is no way to slow down the tests for working at speeds where it is easy to visually control the application at run time. I read the explanations of the developers about why they were deprecated, as well as suggested workarounds such as using implicit_waits, but this does not solve the problem for me (or other people complaining about obsolescence). However, I was hoping to get around this by setting a global execution speed that would apply either to each method in unittest, or to the entire test suite.

The original subject: I have different unit tests that I would like to run using different delays between the teams. I know that I can continue to copy and paste time.sleep between commands, but of course, is there a way to simply set a universal sleep that will be executed before each command in the specified method?

  def test_x_test(self): driver = self.driver time.sleep(2) print("running the First selenium command such as click button") time.sleep(2) print("running another Selenium command such as click link ") time.sleep(2) self.driver.quit() if __name__ == '__main__': unittest.main() 
+4
source share
1 answer

And now the answer is so obvious.

Create a helper method that controls the actions of the webdriver and before it performs the paused action:

There will be pseudocode-ish below since I no longer have access to the Python development environment at work

 #passing in Webdriver instance and the command we want to execute into our helper method webdriverHelper(driver, command): #this 2 second sleep will get run each time time.sleep(2) if command == "click": driver.getElement.click() elif command== "getText": driver.getElement.getText() etc............... 
+1
source

Source: https://habr.com/ru/post/1445617/


All Articles