1

How to take Screenshots using Selenium Web Driver ? I am using a Grid Configuration having 2 nodes. I need to take screen shots at every defined interval from both nodes.

Please do not specify the way to take screenshot. I want the Test cases not to call a common method every time to take screenshot. Rather another thread should be always active which can take screenshots at an interval.

Aryasindhu Sahu
  • 103
  • 1
  • 13

1 Answers1

1

You will have to have multiple threads, and pass the driver instances to both of them, and one thread will perform the test, while another thread will sit on a timer, taking a screenshot every X seconds.

I don't recommend this, however, here's why:

  1. It's probably going to throw a lot errors. What happens if you try to take a screenshot while the driver is booting up, or going to a page? It may not even have the capability to take a screenshot while doing simple things.

  2. Unless you are going to be taking screenshots every half second, and putting it into a video, (which is going to slow down your test), the majority of the screenshots are not going to be useful, and the useful ones are going to be hard to find in the massive amount of screenshots taken.

  3. If you want to include another driver, you're going to have to pass it to the thread as well, taking a third screenshot.

So, in conclusion, I ask why you want this...because I would be happy to suggest an alternative solution that will still fit your needs.

Nathan Merrill
  • 7,648
  • 5
  • 37
  • 56
  • Actually the testcases are run over night. And only failed testcases take screenshot. But some testcases still need to be checked later to know exactly what happened then. If something fails or even if some testcase does some work and I might need to see its flow. So I need it. – Aryasindhu Sahu Sep 27 '13 at 12:50
  • FYI, if you have seen the SauceLab framework, it takes screenshot for every request it receives. How is that possible ? Is there a way to configure at the hub or the node so that it takes screenshots on every request ?? – Aryasindhu Sahu Sep 27 '13 at 12:51
  • I have found that a simple screenshot on fail has been all I've needed to properly debug what has happened. There have been a few rare cases when that wasn't true, but then I can manually add some screenshots and run it again. – Nathan Merrill Sep 27 '13 at 14:20
  • Its all right but still I need screenshots at some interval. Can you please have a look at the saucelab website ? I believe you shall get the idea of what I am saying. [link](https://saucelabs.com/) – Aryasindhu Sahu Sep 30 '13 at 06:10
  • I have not seen saucelab...and I have no idea how they implement it...but if I were to try to take a screenshot with each action, I would create a wrapper around the driver/webelements that would then take a screenshot on each action with the webelements. However...that's a design choice...and something you would have to implement yourself. – Nathan Merrill Sep 30 '13 at 13:43
  • Ok, thank you. I am trying to create wrapper around the driver. – Aryasindhu Sahu Oct 01 '13 at 07:47
  • Hey, just wanted to note that saucelabs do not record the browser/emulator it self, it records a screen, if you have only one driver run on a time, like you do not have any parallel drivers running together, you could record the whole screen, and there is a lot of libraries for that. and also there is some libraries that support grid, and also remote tests – Khalid Abdlqader Dec 17 '15 at 10:19