0

I want a screenshot as soon as I enter the wrong password

namespace UITest. 
{
    [TestClass]
    public class Firefox
    {
        [TestMethod]
        public void AMDP()
        {
            Driver.Navigate().GoToUrl("https://Google.de");

            Driver.Manage().Window.Maximize();

            //Add Username
            Thread.Sleep(waitingTime);
            Driver.FindElement(SoeUser).SendKeys("TestUser");

            // Add password
            Thread.Sleep(waitingTime);
            Driver.FindElement(SoePW).SendKeys("Testpw");

        }
    }
}

My code looks something like this

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
Almir
  • 1
  • 1

1 Answers1

0

Try this:

public void TakeScreenshot(IWebDriver driver,string pathWithFileName)
{
    try
    {            
        ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(pathWithFileName, ScreenshotImageFormat.Png);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        throw;
    }
}
Vemula Dheeraj
  • 64
  • 1
  • 11
  • Thanks but unfortunately it still doesn't work. I'm just learning C# and I'm a bit overwhelmed. Maybe I'm doing something wrong too @Vemula Dheeraj – Almir Aug 15 '22 at 13:06
  • What is the error you are seeing? @Almir – Vemula Dheeraj Aug 15 '22 at 13:25
  • @Almir Can you try this and let me know if this works? ITakesScreenshot ts = (ITakesScreenshot)driver; var screenshot = ts.GetScreenshot().AsBase64EncodedString; MediaEntityBuilder.CreateScreenCaptureFromBase64String(screenshot, "screenShotNameand Path").Build(); – Vemula Dheeraj Aug 15 '22 at 13:32
  • The Part "MediaEntityBuilder" doesn´t work... @Vemula Dheeraj – Almir Aug 15 '22 at 13:52