コード例 #1
0
ファイル: BaseTest.cs プロジェクト: Magenic/MAQS
 /// <summary>
 /// Attach an associated file to the text context
 /// </summary>
 private void AttachAssociatedFile(string path)
 {
     // You can only attach files to VS Unit tests so check that first
     if (this.IsVSTest())
     {
         this.TestContext.AddResultFile(path);
     }
     else
     {
         NUnitTestContext.AddTestAttachment(path);
     }
 }
コード例 #2
0
        private string TakeScreenshot(string screenshotName)
        {
            int attempt = 0;

            while (attempt < 5)
            {
                attempt++;
                IntegrationTestBase.Log($"Saving error screenshot: {screenshotName} for test run {TestRunTimestamp}");
                string path = CreatePngPath(screenshotName, this.GetType().Name);
                IntegrationTestBase.Log($"{path}");
                try
                {
                    Screenshot screen = this.Screenshooter.GetScreenshot();
                    screen.SaveAsFile(path, ScreenshotImageFormat.Png);
                    TestContext.AddTestAttachment(path);
                    return(path);
                }
                catch (UnhandledAlertException alertException)
                {
                    IntegrationTestBase.Log($"Attempt {attempt} - Unexpected alert {screenshotName} for test run {TestRunTimestamp}.\r\n{alertException}");

                    IAlert unexpectedAlert = this.Driver.SwitchTo().Alert();
                    IntegrationTestBase.Log($"Attempt {attempt} - Alert text: [{unexpectedAlert?.Text}]");
                    unexpectedAlert?.Dismiss();
                    try
                    {
                        Screenshot screen = this.Screenshooter.GetScreenshot();
                        screen.SaveAsFile(path, ScreenshotImageFormat.Png);
                    }
                    catch (Exception screenshotError)
                    {
                        IntegrationTestBase.Log($"Attempt {attempt} - Error while saving screenshot after dismissing alert: {screenshotError}");
                    }
                }
                catch (Exception screenshotError)
                {
                    IntegrationTestBase.Log($"Attempt {attempt} - Error while saving screenshot: {screenshotError}");
                }
            }

            return("Failed to take screenshot");
        }
コード例 #3
0
ファイル: TestContextTests.cs プロジェクト: yaakov-h/nunit
 public void NoneExistentFileThrowsFileNotFoundException()
 {
     Assert.That(() => TestContext.AddTestAttachment("NotAFile.txt"), Throws.InstanceOf <FileNotFoundException>());
 }
コード例 #4
0
ファイル: TestContextTests.cs プロジェクト: yaakov-h/nunit
 public void InvalidFilePathsThrowsArgumentException(string filePath)
 {
     Assert.That(() => TestContext.AddTestAttachment(filePath), Throws.InstanceOf <ArgumentException>());
 }
コード例 #5
0
ファイル: TestContextTests.cs プロジェクト: yaakov-h/nunit
 public void FilePathAndDescriptionDoesNotThrow()
 {
     Assert.That(() => TestContext.AddTestAttachment(_tempFilePath, "Description"), Throws.Nothing);
 }
コード例 #6
0
ファイル: TestContextTests.cs プロジェクト: yaakov-h/nunit
 public void FilePathOnlyDoesNotThrow()
 {
     Assert.That(() => TestContext.AddTestAttachment(_tempFilePath), Throws.Nothing);
 }