Beispiel #1
0
        public void SoftAssertIsFalseTest()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(), "UnitTests.SoftAssertUnitTests.SoftAssertIsFalseTest", MessageType.GENERIC, true));

            softAssert.IsFalse(2 == 1, "Test");
            softAssert.FailTestIfAssertFailed();
        }
Beispiel #2
0
        public void AcceptNUnitAsserts()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(), "UnitTests.SoftAssertUnitTests.AcceptNUnitAsserts"));

            softAssert.Assert(() => NUnit.Framework.Assert.AreEqual("a", "a"), "1");
            softAssert.FailTestIfAssertFailed();
        }
Beispiel #3
0
        public void TryLogFallsBackToConsole()
        {
            // Calculate a file path
            string path = Path.GetTempFileName();

            this.Log = new BrokenLogger();
            string logMessage = "TryLogFail";

            try
            {
                // Pipe the console to this file
                using (ConsoleCopy consoleCopy = new ConsoleCopy(path))
                {
                    this.TryToLog(MessageType.INFORMATION, logMessage);
                }
            }
            finally
            {
                this.Log = new ConsoleLogger();
                string logContents = File.ReadAllText(path);
                File.Delete(path);

                SoftAssert.Assert(() => Assert.IsTrue(logContents.Contains(logMessage), $"Log message was '{logContents}'  which does not contain '{logMessage}'"));
                SoftAssert.Assert(() => Assert.IsTrue(logContents.Contains("Logging failed because"), $"Log message was '{logContents}'  which does not contain 'Logging failed because'"));
            }

            SoftAssert.FailTestIfAssertFailed();
        }
Beispiel #4
0
        public void SoftAssertFailTest()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(), "UnitTests.SoftAssertUnitTests.SoftAssertFailTest"));

            softAssert.AreEqual("Yes", "No", "Utilities Soft Assert", "Message is not equal");
            softAssert.AreEqual("Yes", "NoAgain", "Utilities Soft Assert 2");
            softAssert.FailTestIfAssertFailed();
        }
Beispiel #5
0
        public void SoftAssertAssertFailsWithPassingAction()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(),
                                                                  "UnitTests.SoftAssertAssertFailsWithPassingAction"));

            softAssert.AssertFails(() => Assert.IsTrue(true), typeof(AggregateException), "assertName");
            softAssert.FailTestIfAssertFailed();
        }
Beispiel #6
0
        public void CapturesNUnitAssertFail()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(), "UnitTests.SoftAssertUnitTests.RespectNUnitFails"));

            softAssert.Assert(() => NUnit.Framework.Assert.AreEqual("a", "b"), "1");

            softAssert.FailTestIfAssertFailed();
        }
Beispiel #7
0
        public void SoftAssertActionWithEmptyAssertionName()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(),
                                                                  "UnitTests.SoftAssertActionWithEmptyAssertionName"));

            softAssert.Assert(() => Assert.IsTrue(true), string.Empty);
            softAssert.FailTestIfAssertFailed();
        }
Beispiel #8
0
        public void SoftAssertAssertMethodWithFailureMessage()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(),
                                                                  "UnitTests.SoftAssertAssertMethodWithFailureMessage"));

            softAssert.Assert(() => Assert.Fail(), "SoftAssertName", "Failure Message");
            softAssert.FailTestIfAssertFailed();
        }
Beispiel #9
0
        public void CapturesVSAssertFail()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(), "UnitTests.SoftAssertUnitTests.RespectVSFailsFails"));

            softAssert.Assert(() => Assert.AreEqual("a", "b"), "2");

            softAssert.FailTestIfAssertFailed();
        }
Beispiel #10
0
        public void ConfigSections()
        {
            var keysAndValues = Config.GetSectionDictionary("MagenicMaqS");

            SoftAssert.Assert(() => Assert.AreEqual("TXT", keysAndValues["LogType"], "Base configuration not respected"), "2");
            SoftAssert.Assert(() => Assert.AreEqual("SAMPLEGen", keysAndValues["SectionOverride"], "Override not respected"), "3");
            SoftAssert.Assert(() => Assert.AreEqual("SAMPLEGenz", keysAndValues["SectionAdd"], "Run settings addition not respected"), "4");
        }
Beispiel #11
0
        public void SoftAssertIsTrueTestFailure()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(), "UnitTests.SoftAssertUnitTests.SoftAssertFailTest", MessageType.GENERIC, true));

            softAssert.IsTrue(1 == 2, "Test");
            softAssert.IsTrue(1 == 2, "Test1");
            softAssert.IsTrue(true, "Test2");
            softAssert.FailTestIfAssertFailed();
        }
Beispiel #12
0
        public void ConfigSections()
        {
            var keysAndValues = Config.GetSection("MagenicMaqS");

            SoftAssert.Assert(() => Assert.AreEqual(9, keysAndValues.Count, "Expect 9 values, 6 from app.config plus 3 from run settings file"), "1");
            SoftAssert.Assert(() => Assert.AreEqual("TXT", keysAndValues["LogType"], "Base configuration not respected"), "2");
            SoftAssert.Assert(() => Assert.AreEqual("SAMPLEGen", keysAndValues["SectionOverride"], "Override not respected"), "3");
            SoftAssert.Assert(() => Assert.AreEqual("SAMPLEGenz", keysAndValues["SectionAdd"], "Run settings addition not respected"), "4");
        }
Beispiel #13
0
        public void SoftAssertManuallySetExpectedAssertsFails()
        {
            SoftAssert softAssert = new SoftAssert(
                new FileLogger(LoggingConfig.GetLogDirectory(),
                               "UnitTests.SoftAssertManuallySetExpectedAssertsFails"));

            softAssert.AddExpectedAsserts("one");
            softAssert.FailTestIfAssertFailed();
        }
Beispiel #14
0
        public void SoftAssertDidFailCheck()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(), "UnitTests.SoftAssertUnitTests.SoftAssertIsTrueTest", MessageType.GENERIC, true));

            softAssert.IsTrue(true, "Test1");
            Assert.IsFalse(softAssert.DidSoftAssertsFail());

            softAssert.IsTrue(1 == 2, "Test2");
            Assert.IsTrue(softAssert.DidSoftAssertsFail());
        }
        public void SeleniumCreateNewTestObject()
        {
            this.CreateNewTestObject();
            SeleniumTestObject newTestObject = TestObject;

            Assert.AreEqual(WebDriver.ToString(), newTestObject.WebDriver.ToString());
            Assert.AreEqual(Log.ToString(), newTestObject.Log.ToString());
            Assert.AreEqual(SoftAssert.ToString(), newTestObject.SoftAssert.ToString());
            Assert.AreEqual(PerfTimerCollection.ToString(), newTestObject.PerfTimerCollection.ToString());
        }
Beispiel #16
0
        public void ThenICheckLinkToImageForEachPress_Releases()
        {
            foreach (var pressRelease in ScenarioContext.Current["PressReleasesWithLinkToImage"] as List <PressRelease> )
            {
                TestPressReleasesFeatureSteps.message = string.Format(
                    Resource.CorrectLinkToImageOfPressReleases,
                    pressRelease.Id);

                SoftAssert.That(pressRelease.SizeOfImageByAnnouncement != 0, TestPressReleasesFeatureSteps.message);
            }
        }
Beispiel #17
0
        public void ThenICheckLinkToDownloadPDFOfPress_Releases()
        {
            foreach (var pressRelease in ScenarioContext.Current["PressReleasesWithLinkToDownloadPDF"] as List <PressRelease> )
            {
                TestPressReleasesFeatureSteps.message = string.Format(
                    Resource.CorrectLinkToDownloadPDFOfPressReleases,
                    pressRelease.Id);

                SoftAssert.That(pressRelease.SizeOfFileToDownloadPDF != 0, TestPressReleasesFeatureSteps.message);
            }
        }
Beispiel #18
0
        public void SoftAssertVerifyCheckForFailures()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(), "UnitTests.SoftAssertUnitTests.SoftAssertVerifyCheckForFailures"));

            softAssert.AreEqual("Yes", "Yes", "Utilities Soft Assert", "Message is not equal");

            softAssert.FailTestIfAssertFailed();
            Assert.IsTrue(softAssert.DidUserCheck());

            softAssert.AreEqual("Yes", "Yes", "Utilities Soft Assert", "Message is not equal");
            Assert.IsFalse(softAssert.DidUserCheck());
        }
Beispiel #19
0
        public void ThenICheckAnnouncementIsNotNullForEachPress_Releases()
        {
            foreach (var pressRelease in ScenarioContext.Current["PressReleasesWithAnnouncement"] as List <PressRelease> )
            {
                TestPressReleasesFeatureSteps.message = string.Format(
                    Resource.AnnouncementOfPressReleaseIsNotNull,
                    pressRelease.Id);

                SoftAssert.That(
                    !string.IsNullOrEmpty(pressRelease.Announcement),
                    TestPressReleasesFeatureSteps.message);
            }
        }
Beispiel #20
0
        public static void VerifyTrue(string message, bool condition)
        {
            var result = SoftAssert.VerifyTrue(message, condition);

            if (!result)
            {
                LoggerFail("Failure: " + message + " -- Condition: " + condition);
            }
            else
            {
                LoggerPass("Success: Validated. Condition: " + condition);
            }
        }
Beispiel #21
0
 public void Test1()
 {
     DriverUtils.GoToUrl("https://www.google.by");
     Thread.Sleep(3000);
     SoftAssert.IsTrue(false, "assert 1");
     DriverUtils.TypeInElement(By.Name("q"), "google");
     Thread.Sleep(5000);
     SoftAssert.IsTrue(false);
     DriverUtils.Submit(By.Name("q"));
     SoftAssert.IsTrue(true, "assert 3");
     Thread.Sleep(2000);
     SoftAssert.IsTrue(false, "assert 4");
 }
        //General validation method
        public void verifyTrue(String message, String expectedData, String actualData)
        {
            bool result = SoftAssert.verifyTrue(message, expectedData, actualData);

            if (!result)
            {
                loggerFail("Failure: " + message + " -- Expected: " + expectedData + "  -- Actual: " + actualData);
            }
            else
            {
                loggerPass("Success: Validated. Expected: " + expectedData + " Actual: " + actualData);
            }
        }
        /// <summary>
        /// Verify hierarchical logging is respected
        /// </summary>
        /// <param name="logger">The logger we are checking</param>
        /// <param name="filePath">Where the log output can be found</param>
        /// <param name="logLevelText">The type of logging</param>
        /// <param name="levels">What should appear for each level</param>
        private void TestHierarchicalLogging(Logger logger, string filePath, string logLevelText, Dictionary <string, int> levels)
        {
            // Create a soft assert
            SoftAssert softAssert = new SoftAssert(logger);

            // Get the log level
            MessageType logLevel = (MessageType)Enum.Parse(typeof(MessageType), logLevelText);

            logger.SetLoggingLevel(logLevel);

            // Set the logger options to set the log level and add log entries to the file
            logger.LogMessage(logLevel, "\nThe Loglevel is set to " + logLevel);

            // Message template
            string logLine = "Test Log item {0}";

            // Log the test messages
            logger.LogMessage(MessageType.VERBOSE, logLine, MessageType.VERBOSE);
            logger.LogMessage(MessageType.INFORMATION, logLine, MessageType.INFORMATION);
            logger.LogMessage(MessageType.ACTION, logLine, MessageType.ACTION);
            logger.LogMessage(MessageType.STEP, logLine, MessageType.STEP);
            logger.LogMessage(MessageType.GENERIC, logLine, MessageType.GENERIC);
            logger.LogMessage(MessageType.SUCCESS, logLine, MessageType.SUCCESS);
            logger.LogMessage(MessageType.WARNING, logLine, MessageType.WARNING);
            logger.LogMessage(MessageType.ERROR, logLine, MessageType.ERROR);

            // Give the write time
            Thread.Sleep(250);

            // Get the file content
            string logContents = this.ReadTextFile(filePath);

            // Verify that only the logged messages at the log level or below are logged
            foreach (KeyValuePair <string, int> keyValue in levels)
            {
                if ((keyValue.Key != "Row") && (keyValue.Key != "LogLevel"))
                {
                    // Verify the number of times that the message type is found.
                    int count = Regex.Matches(logContents, string.Format(logLine, keyValue.Key)).Count;
                    softAssert.AreEqual(keyValue.Value.ToString(), count.ToString(), "Looking for " + keyValue.Key);
                }
            }

            // Set the log level so that the soft asserts log
            logger.SetLoggingLevel(MessageType.VERBOSE);

            // Fail test if any soft asserts failed
            softAssert.FailTestIfAssertFailed(logContents);
        }
Beispiel #24
0
 public void Test1()
 {
     SoftAssert.IsTrue(false);
     DriverUtils.GoToUrl("https://www.google.by");
     Thread.Sleep(3000);
     SoftAssert.IsTrue(false, "assert 1");
     DriverUtils.TypeInElement(By.Name("q"), "google");
     Thread.Sleep(5000);
     SoftAssert.IsTrue(false);
     DriverUtils.Submit(By.Name("q"));
     SoftAssert.IsTrue(true, "assert 3");
     Thread.Sleep(2000);
     SoftAssert.IsTrue(false, "assert 4");
     TestContext.AddTestAttachment(@"C:\Users\kapatsevich\Downloads\ValeryKapatsevich.jpeg", "Added screenshot for Class1.Test1");
 }
Beispiel #25
0
        public void ValidLoginTest()
        {
            string         username                = "******";
            string         password                = "******";
            string         expectedGreeting        = $"Welcome {username}!";
            string         expectedTimeDescription = "The current time is:";
            AHomePageModel homePage                = startingPage.LoginWithValidCredentials(username, password);

            SoftAssert.AreEqual(expectedGreeting, homePage.GetGreetingMessage());
            SoftAssert.AreEqual(expectedTimeDescription, homePage.GetTimeDiscription());
            DateTime time;

            SoftAssert.IsTrue(DateTime.TryParse(homePage.GetTime(), out time), "Time Parsing");
            SoftAssert.FailTestIfAssertFailed();
        }
Beispiel #26
0
        public void ThenICheckTitleIsNotNullForEachPress_Releases()
        {
            foreach (var pressRelease in ScenarioContext.Current["PressReleasesWithTitle"] as List <PressRelease> )
            {
                TestPressReleasesFeatureSteps.message = string.Format(
                    Resource.TitleOfPressReleaseIsNotNull,
                    pressRelease.Id,
                    pressRelease.Title.ElementAt(0),
                    pressRelease.Title.ElementAt(1));

                SoftAssert.That(
                    pressRelease.Title.All(
                        title => !string.IsNullOrWhiteSpace(title)),
                    TestPressReleasesFeatureSteps.message);
            }
        }
Beispiel #27
0
        public void DirectFlight()
        {
            StartPage startPage = new StartPage();

            startPage.FillInForm("Минск", "Париж");
            FindTicketsPage findTicketsPage = new FindTicketsPage(startPage.getDriver());

            findTicketsPage.FilterFlight();
            SoftAssert ticketsWithDirectFligtAssert = new SoftAssert();

            foreach (IWebElement elem in ticketsDirectFlight)
            {
                ticketsWithDirectFligtAssert.IsTrue(elem.Displayed && !elem.Text.Contains("ПРЯМОЙ ПЕРЕЛЁТ"));
            }
            ticketsWithDirectFligtAssert.VerifyAll();
            Browser.CloseBrowser(findTicketsPage.getDriver());
        }
        public void after()
        {
            //Debug.Assert(SoftAssert.getErrorCount().CompareTo(0) == 0, "Error: Errors were found in test. Count: " + SoftAssert.getErrorCount());


            Debug.WriteLineIf(!(SoftAssert.getErrorCount().CompareTo(0) == 0), "Error: Errors were found in test. Count: " + SoftAssert.getErrorCount());

            driver.Close();
            driver.Quit();

            extentReports.EndTest(extentTestReport);
            extentReports.Flush();
            if (SoftAssert.getErrorCount() > (0))
            {
                Assert.Fail("Test failed!");
            }
        }
Beispiel #29
0
        public void AccessibilityCheckVerbose()
        {
            WebDriver.Navigate().GoToUrl(TestSiteUrl);
            WebDriver.Wait().ForPageLoad();

            string filePath = ((IFileLogger)Log).FilePath;

            SeleniumUtilities.CheckAccessibility(this.TestObject);

            string logContent = File.ReadAllText(filePath);

            SoftAssert.Assert(() => Assert.IsTrue(logContent.Contains("Found 20 items"), "Expected to find 20 pass matches."));
            SoftAssert.Assert(() => Assert.IsTrue(logContent.Contains("Found 62 items"), "Expected to find 62 inapplicable matches."));
            SoftAssert.Assert(() => Assert.IsTrue(logContent.Contains("Found 6 items"), "Expected to find 6 violations matches."));
            SoftAssert.Assert(() => Assert.IsTrue(logContent.Contains("Found 0 items"), "Expected to find 0 incomplete matches."));
            SoftAssert.FailTestIfAssertFailed();
        }
Beispiel #30
0
        public void SoftAssertFailsInvalidTest()
        {
            SoftAssert softAssert = new SoftAssert(new FileLogger(LoggingConfig.GetLogDirectory(), "UnitTests.SoftAssertUnitTests.SoftAssertFailsInvalidTest"));

            softAssert.AssertFails(() => this.MethodThrowsNullException(), typeof(NotImplementedException), "Assert Method Throws Explicit Exception", "Failed to assert that method threw a NotImplementedException");

            int one = 1;

            softAssert.AssertFails(
                () =>
            {
                one        = 0;
                var result = 9 / one;
            },
                typeof(NullReferenceException),
                "Assert  dividing by zero throws a null reference",
                "Failed to assert that we couldn't divide by zero");

            softAssert.FailTestIfAssertFailed();
        }