-1

Someone knows how I can save screenshots without replacing the existing one. That is, I need to keep all the photos of the test cases to be used as evidence.

I have tried with the following scomandos:

  • StoreEval / new Date (). GetDate () / date
  • StoreEval / new Date (). GetMonth () / month

But only saves the capture of this form "photograph (15) .jpg" when I use getdate or "photograph (7)" when I use getmonth, and when running the test case again, the system replaces the same-

Thanks a lot

copo20
  • 1
  • 1

2 Answers2

0

You can do something like below code. I am using N-unit and selenium C#. You can use it as per your requirement.

            Screenshot ScreenImage = ((ITakesScreenshot)driver).GetScreenshot();
            string Date = DateTime.Now.Date.ToString("MM-dd-yyyy");
            string TimeNow = DateTime.Now.TimeOfDay.ToString().Replace(":", "_");
            string FolderPath = Your Path where you want to save the screenhot + "\\" + Date;

            DirectoryInfo dir = new DirectoryInfo(FolderPath);
            if (!dir.Exists)
            {
                dir.Create();
            }

            ScreenImage.SaveAsFile(FolderPath + "\\" + "Test" + "_" + TimeNow + ".jpg", ImageFormat.Jpeg);
Kapil
  • 397
  • 4
  • 6
0

By Assuming you are using Java with selenium IDE.

You can use UUID to generate the random number.

UUID uuid = UUID.randomUUID();
String screenShotFileName = imageLocation + uuid + ".png";

Refer How unique is UUID? to know how unique it is.

LMKR
  • 647
  • 5
  • 12