Open AakritiGarg91 opened 4 years ago
The test failed, which is why the color in the right pane is red. What are you trying to do?
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.
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;
}
`
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 ExtentIssue.zip
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);
[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(); }