This code takes a when fail, but name it like my class. How to named screenshot like test? Example: public void ClickMyAccount() fail and screenshot must be named ClickMyAccount.png(or other image type). I don’t know in advance which test will fail.

[OneTimeTearDown]
    public void TestFail()
    {
        if (TestContext.CurrentContext.Result.Outcome != ResultState.Success)
        {
            string screensLocation = @"E:";
            string testName = TestContext.CurrentContext.Test.Name;
            var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
            screenshot.SaveAsFile(screensLocation + testName + ".png");
        }
    }



Source link https://sqa.stackexchange.com/questions/34812/taking-screenshot-and-name-it-like-failed-test-using--

LEAVE A REPLY

Please enter your comment!
Please enter your name here