Page 1 of 1
Get name of test module within code
Posted: Mon Apr 18, 2011 3:20 pm
by APSoftware
Hey Guys!
As mentioned in this thread
http://www.ranorex.com/forum/test-suite ... t2064.html, I want to write the status of a testmodule to teamcity in the teardown.
My question is now, is it possible to get the name of test module within the teardown?
Regards
Stefan
Re: Get name of test module within code
Posted: Tue Apr 19, 2011 8:11 am
by APSoftware
Problem Solved!
Code: Select all
public string TestModuleName = GetPrivateFieldValue<string>(TestReport.CurrentTestCaseActivity, "name");
public static T GetPrivateFieldValue<T>(Activity obj, string propName)
{
if (obj == null)
throw new ArgumentNullException("obj");
Type t = obj.GetType();
FieldInfo fi = null;
while (fi == null && t != null)
{
fi = t.GetField(propName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
t = t.BaseType;
}
if (fi == null)
throw new ArgumentOutOfRangeException("propName",
string.Format("Field {0} was not found in Type {1}", propName, obj.GetType().FullName));
return (T)fi.GetValue(obj);
}
Re: Get name of test module within code
Posted: Tue Apr 19, 2011 8:52 am
by Support Team
And you don't even need the reflections you used to get the name. You can use the TestReport.CurrentTestModuleActivity.TestModuleName to get the current module name and TestReport.CurrentTestCaseActivity.TestCaseName to get the name of the current test case.
Regards,
Alex
Ranorex Team
Re: Get name of test module within code
Posted: Tue Apr 19, 2011 9:41 am
by APSoftware
Oh, is that easy....