0

I have a customized HTML(created thru XML/XSLT) test status report that basically lists the steps, results and comments of the results from executed automated scripts. Since I am still new to programming, I was wondering what are the best ways to get the captured screenshot(using the ITakesScreenshot in Selenium) filename and insert this filename in the XML node? My below code is for screenshot Capture:

  public static void takeScreenShot()
    {
        string currentDate = DateTime.Now.ToString("ddd, ddMMMyyyy HHmm");
        ITakesScreenshot screenshotHandler = Driver as ITakesScreenshot;
        Screenshot screenshot = screenshotHandler.GetScreenshot();
        string dir = @"C:\Documents\";
        screenshot.SaveAsFile(dir + currentDate + fileName + ".png", ImageFormat.Png);
    }

and below is my insert values on an XML node:

 private static void InsertValues(string ID, string Step, string Result, string Comment)
    {

        var xmlDoc = XDocument.Load(xmltoLoad);

        var newElement = new XElement("TestCase",  new XAttribute("Id", ID),
                           new XElement("Screenshot", ""),
                           new XElement("Step", Step),
                           new XElement("Result", Result),
                           new XElement("Comments", Comment));
        xmlDoc.Element("TestResults").Add(newElement);
        xmlDoc.Save(xmltoLoad);

    }

I was trying to do

string filename = screenshot.SaveAsFile(dir+currentDate+fileName+".png", ImageFormat.png);

But I receive an error that the void cannot be converted to string, which I understand. Is there something that I can do or are there any other approach on this?

1 Answer 1

2

.SaveAsFile() doesn't return anything so there is no return to stuff into filename. Is there some reason you can't just do

string filename = dir + currentDate + fileName + ".png";
screenshot.SaveAsFile(filename, ImageFormat.png);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.