how can I call the test case result on runtime to another file to update test case result in testRail?

  • Thread starter Thread starter Amna Khalid 001
  • Start date Start date
A

Amna Khalid 001

Guest
I am using Nunit C# in selenium webdriver. My code is


public class MainProjectFIle
{
private IWebDriver WDriver;
private log4net.ILog Testlog;


[TestInitialize]
public void wd()
{
WDriver = Helper.GetWebDriver(helperconst.browserType.Chrome);
Testlog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}
[Priority(1)]
[TestMethod]
public void search()
{
Testlog.Info("Test ID:001, This test will select the criteria and update the customer dropdown");

Testlog.Info("Step 1/1 : Select customer from cutomer dropdown");
var dc = gmethods.GetSelectElement(WDriver, dpo.customermenu);
dc.SelectByText(dpc.customer);
}
[TestCleanup]
public void CleanUp()
{
WDriver.Close();
WDriver.Quit();
}
}


In dpo page:


public static class dpo
{
public const string customermenu = "[data]";
}


In dpc page


public static class dpc
{
public const string customer = "A";
}


In gmethods page:


static public SelectElement GetSelectElement(IWebDriver drv, string elem)
{
SelectElement a = new SelectElement(drv.FindElement(By.CssSelector(elem)));
return a;
}


In TestRailPO file the code is


public class TestRailPO
{
class TestResultKeeper
{
public static TestResult TestResult { get; set; }
public static ResultState ResultState => TestResult?.ResultState ?? ResultState.Failure;
public static bool IsPassed => ResultState == ResultState.Success;
public static Exception Exception { get; set; }
}

// Custom NUnit 3 attribute to extend test method
public class LogTestAttribute : Attribute, IWrapTestMethod
{
public TestCommand Wrap(TestCommand command)
{
// Wrap test command
return new LogTestResultCommand(command);
}
}

class LogTestResultCommand : DelegatingTestCommand
{
public LogTestResultCommand(TestCommand innerCommand)
: base(innerCommand)
{

}

public override TestResult Execute(TestExecutionContext context)
{
try
{
var result = innerCommand.Execute(context);

// Set test result to TestResultKeeper

TestResultKeeper.TestResult = result;
TestResultKeeper.Exception = null;

return result;
}
catch (Exception e)
{
// Exception thrown from test. Test failed.

TestResultKeeper.TestResult = null;
TestResultKeeper.Exception = e.InnerException;
throw;
}
}
}
}
}
I ma using MStest and the code for keeping test case result is in Nunit. Can someone help me to correct this and I want to saved testcase result in TestResultKeepr. I want to call that result in the form of 1 and 2, 1 for pass 2 for fail To update test case result on runtime in the variable ttresult in TestRailPM file. The code for in testRailPM is

public class TestRailPM
{
public void testrail()
{

string testRunID = CreateTestRun.CreateRun(testRailUrl, testRailUser, testRailPassowrd, projectId, suiteId, milestoneId, "Automation of TestCases", "Automated Test Cases", testRailUserId, false, testCaseIds);
int testRunIdInInt = Convert.ToInt16(testRunID);

int[] newTestRunCaseIds = GetTestCases.getTestCaseIds(testRailUrl, testRailUser, testRailPassowrd, testRunIdInInt, true);
int[] originalTestCaseIds = GetTestCases.getTestCaseIds(testRailUrl, testRailUser, testRailPassowrd, testRunIdInInt, false);


int singleTestCaseId = 98765;

UpdateTestRun.updateSingleTestCaseInATestRun(ttresult, "testCaseComments", testRailUserId);
}
}

How can I do that?

Continue reading...
 
Back
Top