-2

How to take screenshot for every 10 seconds in selenium that is from beginning of TC to end of TC.

Say my TC duration is 100 sec I need 10 screenshots in total.

  • 1
    your question is similar to this : https://stackoverflow.com/a/3423347/7820277 – Shubham Sep 10 '18 at 13:04
  • @Shubham I know how to take screenshot in selenium but want to take screenshots until a TC completes – Yenike Raghu Ram Sep 10 '18 at 13:11
  • Time based screenshots are not recommended. You can instead use listeners and implement screenshots to be taken after a particular action on a web page. – SelThroughJava Sep 10 '18 at 13:51
  • can you just share your code may be then we can have more clarity – Shubham Sep 10 '18 at 15:21
  • Upvoted because this is the top Google search result and the only question on Stack Overflow trying to answer this question. It really shouldn't have been downvoted. I want to know if it's possible to take a screenshot with Selenium every 100ms. – NobleUplift Sep 25 '19 at 20:19

1 Answers1

0

You would not be able to achieve this with Selenium as it is single threaded. Any request must wait for the previous request to finish.

If you had a single process, even if you check after every command whether 10 seconds had passed, it would never be exactly 10 seconds as it is likely that a command was being processed during the exact moment. You would end up with screenshots of unequal periods between.

Even if you had 2 processes running; 1 executing the test commands, the other performing screenshots at exactly 10 seconds, you would still run in to the same issue.

As Selenium is single threaded, it would not process the request for a screenshot until any concurrent command had finished executing. Again you would end up with unequal periods between screenshots.

If you desperately need screenshots every 10 seconds, then you could look at using "GridExtras" (https://github.com/groupon/Selenium-Grid-Extras). This exposes a HTTP endpoint to take screenshots outside of Selenium, and if you had a 2 processes, the 2nd process could call this endpoint every 10 seconds.

Do not be put off by the fact it is called "Grid Extras". I personally use it to capture video without using Selenium Grid and instead I have a standalone selenium server running along side an instance of Grid Extras.

Robbie Wareham
  • 3,380
  • 1
  • 20
  • 38