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.

    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


Please enter your comment!
Please enter your name here