FluentAutomation icon indicating copy to clipboard operation
FluentAutomation copied to clipboard

Can't get any screenshots with ScreenshotPrefix option enabled

Open pashidlos opened this issue 10 years ago • 4 comments

Without this option I get screenshots but I want to set specific name for each, Even when I try to do it like this: FluentSettings.Current.ScreenshotPrefix = "test"; it doesn't work

pashidlos avatar Feb 10 '15 14:02 pashidlos

What happens? Do the screenshots not get created anywhere or just not with the test prefix?

stirno avatar Feb 11 '15 03:02 stirno

They don't get created anywhere

pashidlos avatar Feb 11 '15 07:02 pashidlos

Is it posible to set screenshot prefix as a test method name? As I do for log output: Console.WriteLine(MethodBase.GetCurrentMethod().Name);

pashidlos avatar Feb 11 '15 08:02 pashidlos

Decided to do like this. Failed test name is the screenshot name. Last link is also printed. I perform screenshot action on test failure (add this step to TearDown)

public DriverTearDown(IWebDriver driver)
        {
            if (TestContext.CurrentContext.Result.Status == TestStatus.Failed)
            {
                string screenshotName = Regex.Replace(TestContext.CurrentContext.Test.Name, "[^a-zA-Z0-9(),]", "");  //Remove invalid characters
                string screenshotPath = AppDomain.CurrentDomain.BaseDirectory; //Get application path
                const string screenshotExtention = ".jpeg"; //Set extention
                driver.TakeScreenshot()
                    .SaveAsFile(screenshotName + screenshotExtention, ImageFormat.Jpeg);
                throw new Exception(
                                    " \nUrl was: " + driver.Url +
                                    " \nScreenshot: " + screenshotPath +"\\"+ screenshotName + screenshotExtention);
            }
        }

Exception helps to see this info in html-report.

pashidlos avatar Feb 17 '15 10:02 pashidlos