コード例 #1
0
        /// <summary>
        /// Take a screenshot, save to a file and attach to allure report.
        /// </summary>
        /// <param name="driver"></param>
        /// <param name="testId"></param>
        /// <param name="testName"></param>
        /// <param name="lifecycle"></param>
        /// <returns></returns>
        public bool CaptureScreenshot(IWebDriver driver, string testId, string testName, Allure.Commons.AllureLifecycle lifecycle)
        {
            try
            {
                // Get the screenshot from Selenium WebDriver and save it to a file
                Screenshot ss     = ((ITakesScreenshot)driver).GetScreenshot();
                string     ssName = testName
                                    // + testId
                                    + DateTime.Now.ToString("yyyyMMddTHHmmss");
                ssName = Regex.Replace(ssName, @"[^0-9a-zA-Z]+", "") + ".png";
                string screenshotFile = lifecycle.ResultsDirectory + "\\" + ssName;
                ss.SaveAsFile(screenshotFile, ScreenshotImageFormat.Png);

                // Add that file to NUnit results
                lifecycle.AddAttachment(screenshotFile);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #2
0
 public AuthenticatedPageTests(WebDriverSetup.BrowserType browser)
 {
     myBrowser    = browser;
     lifecycle    = Allure.Commons.AllureLifecycle.Instance;
     oDriverSetup = new WebDriverSetup();
 }