what has gone wrong, we probably don't want to kill our test run if we are unable to capture it or write a screenshot to disk for some reason. To make sure that we don't disrupt the test run we catch the error, and log it out to the console for future reference. We then carry on with what we were doing before.
You cannot cast all driver implementations in Selenium into a TakesScreenshot object. As a result we capture the ClassCastException for driver implementations that cannot be cast into a TakesScreenshot object and augment them instead.
We don't just augment everything because a driver object that doesn't need to be augmented will throw an error if you try. It is usually RemoteWebDriver instances that need to be augmented. Apart from augmenting the driver object when required, the main job of this function is to generate a lename for the screenshot. We want
to make sure that the lename is unique so that we don't accidentally overwrite any screenshots. To do this we use the current timestamp, and the name of the current test. We could use a randomly generated GUID (Globally Unique Identi er) but timestamps make it easier to track what happened at what time. Finally we want to log the absolute path to the screenshot out to console. This will make it easy to nd any screenshots that have been created.
As you may have noticed in the preceding code, we are using a system property to get the directory that we save our screenshots in; we need to set this system property in our POM. We need to modify the maven-failsafe-plugin section so that it looks like this:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.17</version> <configuration>
<parallel>methods</parallel> <threadCount>${threads}</threadCount> <systemProperties>
Comments
0 comments
Please sign in to leave a comment.