extent-framework / extentreports-csharp

Extent Reporting Library, .NET
http://extentreports.com
Apache License 2.0
50 stars 40 forks source link

Test is showing fail in Dashboard, even when test is passing #80

Open AakritiGarg91 opened 4 years ago

AakritiGarg91 commented 4 years ago

Here, I am create a featureName before every TestMethod by using CreateTest. In My Test DeleteSyncedDoc(), I am calling a helper function SyncComplete(), which is again calling multiple helper functions. In every helper function, I am creating a Node by using CreateNode(string str) function. I am using it to get all helper function as test steps in Extent report. Extent report is attached in .zip file.

TestCleanUP() is calling after every test where is exp is null, I am explicilty passing the test. My question is if one of my test step fails, but test passes. Is there anyway, I can pass this test in report. In report, I am getting PASSED in right side, but it fails on left side. Please see Screenshot attached Capture ExtentIssue.zip

    [TestInitialize]
    public void TestInitializer()
    {
        featureName = extent.CreateTest(TestContext.TestName.ToString());
    }

public static ExtentTest CreateNode(string str) { ExtentTest testcase; testcase = featureName.CreateNode(str); return testcase; }

public static int IsElementPresent(String id) //helper function { ExtentTest testcase; testcase = featureName.CreateNode("IsElementPresent"); try { session.FindElementByAccessibilityId(id); return 1; } catch (Exception) { exp = ex.ToString(); return -1; } finally { SetStatus(testcase, exp); } }

public static void SetStatus(ExtentTest testcase, string str) { if (str == null) testcase.Pass("Pass"); else testcase.Fail(str); exp = null; }

public static bool SyncComplete() { ExtentTest testcase; testcase = featureName.CreateNode("SyncComplete()"); try { BaseHelper.Sleep(3000); bool value = false; string txt = ""; DefaultWait wait = new DefaultWait(txt); wait.Timeout = TimeSpan.FromMinutes(1); wait.PollingInterval = TimeSpan.FromMilliseconds(200);

            Func<string, bool> waiter = new Func<string, bool>((string txt1) =>
            {
                IWebElement e1 = BaseHelper.Element(BaseHelper.GetAutomationID("TopBarCloudIcon"));
                BaseHelper.Click(e1, 1000);
                BaseHelper.Print(BaseHelper.IsElementPresent(BaseHelper.GetAutomationID("CloudIconTextBlock")));
                if (BaseHelper.IsElementPresent(BaseHelper.GetAutomationID("CloudIconTextBlock")) > 0)
                    txt1 = BaseHelper.Element(BaseHelper.GetAutomationID("CloudIconTextBlock")).Text;
                else
                {
                    BaseHelper.Click(e1, 1000);
                }
                BaseHelper.Element(BaseHelper.GetAutomationID("TopBarCloudIcon")).Click();
                if (txt1 == "No sync errors")
                {
                    value = true;
                    return true;
                }
                return false;
            });

            wait.Until(waiter);
            Assert.IsTrue(value);
            return value;
        }
        catch (Exception e)
        {
            exp = e.ToString();
            return false;
        }
        finally
        {
            SetStatus(testcase, exp);
        }
    }

[TestCategory("CDO"), TestMethod()] public void DeleteSyncedDoc() { try { SyncComplete(); } catch (Exception e) { exp = e.ToString(); } }

[TestCleanup] public void TestCleanUP() { if ((session != null) && !BaseHelper.IsHomePage()) { if (BaseHelper.IsDocumentOpen()) { session.FindElementByAccessibilityId(BaseHelper.GetAutomationID("HomeButton")).Click(); }

        }

        if (exp == null)
        {
            if (TestContext.CurrentTestOutcome == UnitTestOutcome.Passed)
            {
                featureName.Pass("PASSED");
            }
            else if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed)
            {
                featureName.Fail("FAILED");
            }
        }
        else
        {
            featureName.Fail(exp);
        }
        exp = null;
    }
anshooarora commented 4 years ago

The test failed, which is why the color in the right pane is red. What are you trying to do?

AakritiGarg91 commented 4 years ago

A test is calling multiple helper functions. All helper functions are creating a test step as in attached Screenshot. sometimes what happens is, one of the helper function fails(say element is not visible, but on retry it is present) and test executes perfectly.

here, we are explicitly passing this test by using

if (TestContext.CurrentTestOutcome == UnitTestOutcome.Passed) { featureName.Pass("PASSED"); }

Test is showing green tick on left side and red cross on right.

what best I can do here.

namilkimfree commented 4 years ago

image

image

image

My visual studio result is fail and create ExtentTest,Fail("Fail");

I'm Throw Exception but test result pass. Why is it still showing pass?

My test code `

    [Given(@"""(.*)"" Test (.*) Test")]
    public void ExceptionTest(string categoryCd, int prdId)
    {
            throw new Exception();
    }

string summary = _scenarioContext.StepContext.StepInfo.Text;

        switch (steptype)
        {
            case StepDefinitionType.Given:
                _scenario.CreateNode<Given>(summary).Fatal(_scenarioContext.TestError?.InnerException);
                break;
            case StepDefinitionType.When:
                _scenario.CreateNode<When>(summary).Fail(_scenarioContext.TestError.InnerException?.Message);
                break;
            case StepDefinitionType.Then:
                _scenario.CreateNode<Then>(summary).Fail(_scenarioContext.TestError.Message);
                break;
            default:
                break;
        }

`