How to get test case name using code, while execution

Class library usage, coding and language questions.
akommalapati
Posts: 21
Joined: Wed Dec 07, 2011 2:54 pm
Location: India

How to get test case name using code, while execution

Post by akommalapati » Tue Dec 13, 2011 1:29 pm

Hi,

I have a requirement that i want to read the excel data based on the test case name.
i have reusable actions i want to get the current test case name using code in the reusable actions then get the data from the excel based on the test cases name.

Can u please help me out

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get test case name using code, while execution

Post by Support Team » Tue Dec 13, 2011 2:15 pm

Hi,

the test case name can be accessed using following code snippet within your user code modules:
String name = TestCase.Current.Name;
Kind regards,
Tobias
Ranorex Support Team
.
Image

akommalapati
Posts: 21
Joined: Wed Dec 07, 2011 2:54 pm
Location: India

Re: How to get test case name using code, while execution

Post by akommalapati » Wed Dec 14, 2011 11:50 am

Thanks for the code, worked perfectly.

Thanks
Ajay

Balamurali
Posts: 2
Joined: Mon Feb 25, 2013 1:09 pm

Re: How to get test case name using code, while execution

Post by Balamurali » Mon Feb 25, 2013 1:34 pm

Hi,

I tried to use TestCase.Current.Name in my user code module. But I'm getting the below error. What could be the possible reason?

Object reference not set to an instance of an object.
Show/Hide Stacktrace
at SampAutomation.supportlibraries.ExecuteTest.Ranorex.Core.Testing.ITestModule.Run() in c:\Users\pceqa\Documents\Ranorex\Core\SampAutomation\SampAutomation\supportlibraries\ExecuteTest.cs:line 53 at Ranorex.Core.Testing.TestSuiteModule.RunInternal(DataContext parentDataContext)

Thanks,
-Bala.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get test case name using code, while execution

Post by Support Team » Tue Feb 26, 2013 2:54 pm

Hello,

The reference to this object is not available if you run a code or recording module only.
You might need to run the whole TestCase to get the current name of it.

Could you please try to run the TestCase?
If it is still not working, could you please post the code you use for it.

Thank you.

Regards,
Markus (T)
.
Image

Balamurali
Posts: 2
Joined: Mon Feb 25, 2013 1:09 pm

Re: How to get test case name using code, while execution

Post by Balamurali » Tue Feb 26, 2013 5:02 pm

Thanks Markus for your reply.

As you suggested, I have called at test case level. It works fine.

Thanks,
-Bala.

pramoodd
Posts: 13
Joined: Tue Mar 26, 2013 8:45 am

Re: How to get test case name using code, while execution

Post by pramoodd » Tue Apr 09, 2013 6:38 am

I tried to access the testcase name from code.
Is that possible?
I tried Using this code.

Code: Select all

TestCase.Current.Name
but it says that The name 'TestCase' does not exist in the current context (CS0103) -
C:\Users\parnepalli\Documents\Ranorex\RanorexStudio Projects\IDSys\IDSys\MailLogger.cs:329,58


I wanna show the test case name in my mail.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get test case name using code, while execution

Post by Support Team » Wed Apr 10, 2013 1:01 pm

Hi,

Did you add the correct namespace to you class "using Ranorex.Core.Testing;"?

Regards,
Markus
.
Image