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
Get name of test module within code
-
- Posts: 8
- Joined: Tue Sep 14, 2010 10:43 am
Re: Get name of test module within code
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);
}
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Get name of test module within code
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
Regards,
Alex
Ranorex Team
-
- Posts: 8
- Joined: Tue Sep 14, 2010 10:43 am
Re: Get name of test module within code
Oh, is that easy.... 
