This prompted me to add this to tips and tricks. I test in multiple environments sometimes so my screenshots which I save to a shared drive I amend the driver onto. This way one test that generates 10 images has a driver attached. So if I test in 3 I have 30 unique screenshots that tell me what browser was used.
Here is my code (modified from research online, not from scratch)
sure it gets pretty intensive the way I set it up so I can reuse everything. All my test cases have a master file I import so when I change environments or screenshot locations I change it in one method and it affects all my test cases.
I’ll edit out our company data below and replace it with “program”
by importing that method above I can call my method which basically has a hard coded path of where I want to store my screenshots. Then I amend this in the test case with the name of the test and a folder for the suite. So after this I have “screenShotPath” which include the universal path and the name of the test case. I do this in every test case.
Then I do this whenever I capture a screenshot (again company data removed).
WebUI.takeScreenshot(screenShotPath + currentWebDriver + ' - 01 name of screen shot.jpg', FailureHandling.OPTIONAL)
so by combining my two strings I end up create all screenshots in a single folder with the webdriver in the name. I start with webdriver so all the chrome ones are together and all the firefoxes etc. I also use a number at the start of each screenshot to keep these in order. though I use the report that gets emailed I can also see that driver in those emails and I like to keep these screenshots in a location I can reference after a run. So I can use them for defects or test artifacts. Here is an example of the out put from some of these.
First the suite, I create a master suite with all tests and then add each of these suite into an all environment suite like this: