How to capture Screenshot in Selenium C#

38 views
Skip to first unread message

Haritha Upuluri

unread,
Feb 15, 2024, 12:38:20 AM2/15/24
to Selenium Users
Hello Guys,
Could anyone help me how to Capture screenshot in  BDD  Spec flow framework using Selenium C#. I have used the below code to capture screenshot but I could not get the screenshot. Any one please help me. 

  public string addScreenshot(IWebDriver driver, ScenarioContext scenarioContext)
        {
            ITakesScreenshot takesScreenshot = (ITakesScreenshot)driver;
            Screenshot screenshot = takesScreenshot.GetScreenshot();
            string screenshotLocation = Path.Combine(testresultspath, scenarioContext.ScenarioInfo.Title + ".png");
            screenshot.SaveAsFile(screenshotLocation);
            return screenshotLocation;
        }
Thank you.
Regards
Haritha

Nortier David

unread,
Feb 15, 2024, 2:45:58 AM2/15/24
to seleniu...@googlegroups.com

Hello

 

The code seems to be good

What about the error ?

 

De : seleniu...@googlegroups.com <seleniu...@googlegroups.com> De la part de Haritha Upuluri
Envoyé : jeudi 15 février 2024 02:59
À : Selenium Users <seleniu...@googlegroups.com>
Objet : [selenium-users] How to capture Screenshot in Selenium C#

 

ATTENTION : cet e-mail provient d'une personne externe. Vérifiez toujours l’expéditeur avant d’ouvrir les pièces jointes ou de cliquer sur les liens.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/735381bb-05bc-478b-80c6-f33fa73400can%40googlegroups.com.


====== DISCLAIMER ======

https://www.cph.be/maildisclaimer

Prakash Suryawanshi

unread,
Feb 15, 2024, 2:47:45 AM2/15/24
to seleniu...@googlegroups.com
Try below modified code:

Here's the modified code assuming testresultspath is a parameter passed into the method:

public string AddScreenshot(IWebDriver driver, ScenarioContext scenarioContext, string testresultspath)

{
    ITakesScreenshot takesScreenshot = (ITakesScreenshot)driver;
    Screenshot screenshot = takesScreenshot.GetScreenshot();
    string screenshotLocation = Path.Combine(testresultspath, scenarioContext.ScenarioInfo.Title + ".png");
    screenshot.SaveAsFile(screenshotLocation);
    return screenshotLocation;
}
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/735381bb-05bc-478b-80c6-f33fa73400can%40googlegroups.com.


--
thanks & regards,


Prakash P Suryawanshi
9545456632
Reply all
Reply to author
Forward
0 new messages