Пример #1
0
 protected void Test(Action action)
 {
     try
     {
         if (isTestEnabled.Value)
         {
             action();
         }
         else
         {
             const string msg = "Test is not " +
                                "enabled in input file. This line of input file is being ignored.";
             LogInfo(msg);
             Assert.Inconclusive(msg);
         }
     }
     catch (Exception e) when(!(e is AssertInconclusiveException))
     {
         try
         {
             var screenShot = TakeScreenShot.ScreenShot(Driver);
             extentTest.Log(Status.Fail, "Unhandled Exception " + e, MediaEntityBuilder.CreateScreenCaptureFromPath(screenShot).Build());
         }
         catch (Exception)
         {
             extentTest.Log(Status.Fail, "Unhandled Exception " + e);
         }
         LogError("Unhandled Exception", e);
         throw;
     }
 }
Пример #2
0
        /**
         * Check a string is the same as expected value with soft assertion
         *
         * @param details  text to be added to the test report
         * @param actual   String to compare
         * @param expected expected value of the string
         */
        public void CheckText(string expected, string actual, string logDescription = null)
        {
            switch (_extentMode)
            {
            case "Normal":
                var screenShot = TakeScreenShot.ScreenShot(Driver);
                if (actual.Equals(expected))
                {
                    try
                    {
                        extentTest.Log(Status.Pass, logDescription + " Checking Text. Expected: " + expected + "    Actual: " + actual, MediaEntityBuilder.CreateScreenCaptureFromPath(screenShot).Build());
                    }
                    catch (IOException e)
                    {
                        extentTest.Log(Status.Pass, logDescription + " Checking Text. Expected: " + expected + "    Actual: " + actual);
                        Logger.Error(e);
                    }
                }
                else
                {
                    try
                    {
                        extentTest.Log(Status.Fail, logDescription + " Checking Text. Expected: " + expected + "    Actual: " + actual, MediaEntityBuilder.CreateScreenCaptureFromPath(screenShot).Build());
                    }
                    catch (IOException e)
                    {
                        extentTest.Log(Status.Fail, logDescription + " Checking Text. Expected: " + expected + "    Actual: " + actual);
                        Logger.Error(e);
                    }
                }
                break;

            case "Fast":
                if (actual.Equals(expected))
                {
                    extentTest.Log(Status.Pass, logDescription + " Checking Text. Expected: " + expected + "    Actual: " + actual);
                }
                else
                {
                    extentTest.Log(Status.Fail, logDescription + " Checking Text. Expected: " + expected + "    Actual: " + actual);
                }
                break;

            default:
                if (actual.Equals(expected))
                {
                    extentTest.Log(Status.Pass, logDescription + " Checking Text. Expected: " + expected + "    Actual: " + actual);
                }
                else
                {
                    extentTest.Log(Status.Fail, logDescription + " Checking Text. Expected: " + expected + "    Actual: " + actual);
                }
                break;
            }
        }
Пример #3
0
        /**
         * Check an elements text is the same as expected value
         *
         * @param details  text to be added to the test report
         * @param element  element that you want to get the text for
         * @param expected expected value of the element
         */
        public void CheckElementText(IWebElement element, string details, string expected)
        {
            switch (_extentMode)
            {
            case "Normal":
                var screenShot = TakeScreenShot.ScreenShot(Driver);
                if (element.Text.Equals(expected))
                {
                    try
                    {
                        extentTest.Log(Status.Pass, details + "Expected: " + expected + "    Actual: " + element.Text, MediaEntityBuilder.CreateScreenCaptureFromPath(screenShot).Build());
                    }
                    catch (IOException e)
                    {
                        extentTest.Log(Status.Pass, details + "Expected: " + expected + "    Actual: " + element.Text);
                        Logger.Error(e);
                    }
                }
                else
                {
                    try
                    {
                        extentTest.Log(Status.Fail, details + "Expected: " + expected + "    Actual: " + element.Text, MediaEntityBuilder.CreateScreenCaptureFromPath(screenShot).Build());
                    }
                    catch (IOException e)
                    {
                        extentTest.Log(Status.Fail, details + "Expected: " + expected + "    Actual: " + element.Text);
                        Logger.Error(e);
                    }
                }
                break;

            case "Fast":
                if (element.Text.Equals(expected))
                {
                    extentTest.Log(Status.Pass, details + "Expected: " + expected + "    Actual: " + element.Text);
                }
                else
                {
                    extentTest.Log(Status.Fail, details + "Expected: " + expected + "    Actual: " + element.Text);
                }
                break;

            default:
                if (element.Text.Equals(expected))
                {
                    extentTest.Log(Status.Pass, details + "Expected: " + expected + "    Actual: " + element.Text);
                }
                else
                {
                    extentTest.Log(Status.Fail, details + "Expected: " + expected + "    Actual: " + element.Text);
                }
                break;
            }
        }
Пример #4
0
        public void ExtentFail(string logMessage)
        {
            switch (_extentMode)
            {
            case "Normal":
                var screenShot = TakeScreenShot.ScreenShot(Driver);
                try
                {
                    extentTest.Log(Status.Fail, logMessage, MediaEntityBuilder.CreateScreenCaptureFromPath(screenShot).Build());
                }
                catch (IOException e)
                {
                    extentTest.Log(Status.Fail, logMessage);
                    Logger.Info(e);
                }
                break;

            case "Fast":
                extentTest.Log(Status.Fail, logMessage);
                break;
            }
        }
Пример #5
0
        public void ExtentTrue(bool value, string logDescription = null)
        {
            switch (_extentMode)
            {
            case "Normal":
                var screenShot = TakeScreenShot.ScreenShot(Driver);
                if (value)
                {
                    try
                    {
                        extentTest.Log(Status.Pass, logDescription + " Asserting true: " + value.ToString(), MediaEntityBuilder.CreateScreenCaptureFromPath(screenShot).Build());
                        Assert.IsTrue(value);
                    }
                    catch (IOException e)
                    {
                        extentTest.Log(Status.Pass, logDescription + " Asserting true: " + value.ToString());
                        Logger.Error(e);
                        Assert.IsTrue(value);
                    }
                }
                else
                {
                    try
                    {
                        extentTest.Log(Status.Fail, logDescription + " Asserting true: " + value.ToString(), MediaEntityBuilder.CreateScreenCaptureFromPath(screenShot).Build());
                        Assert.IsTrue(value);
                    }
                    catch (IOException e)
                    {
                        extentTest.Log(Status.Fail, logDescription + " Asserting true: " + value.ToString());
                        Logger.Error(e);
                        Assert.IsTrue(value);
                    }
                }
                break;

            case "Fast":
                if (value)
                {
                    extentTest.Log(Status.Pass, logDescription + " Asserting true: " + value.ToString());
                    Assert.IsTrue(value);
                }
                else
                {
                    extentTest.Log(Status.Fail, logDescription + " Asserting true: " + value.ToString());
                    Assert.IsTrue(value);
                }
                break;

            default:
                if (value)
                {
                    extentTest.Log(Status.Pass, logDescription + " Asserting true: " + value.ToString());
                    Assert.IsTrue(value);
                }
                else
                {
                    extentTest.Log(Status.Fail, logDescription + " Asserting true: " + value.ToString());
                    Assert.IsTrue(value);
                }
                break;
            }
        }