This is a migrated thread and some comments may be shown as answers.

How do I use custom classes in my test?

5 Answers 114 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dearborn I.T. Operations
Top achievements
Rank 1
Dearborn I.T. Operations asked on 20 Dec 2013, 09:13 PM
Hey everyone,
I'm having trouble trying to figure out the most efficient way to build my suite of tests.  The issue is, I have tests that do environment specific things.  For example, in one of my tests, I query our qa environment database to get a specific value back which is then used to help datadrive the test.  Now what if I want to run this same test in UAT or Prod?  This means I need to change in all the tests which environment I am pointing to.  I want to be able to just have to change one value in a test and then everything will run in the correct environment.

My idea was creating a custom C# class that has functions that based on which environment you are in, returns the correct value.

Here's a quick example of what I want.

public String getUrl(Environment env)
{
if(env == Environment.QA)
{
return "qaurl";
}else if(env == Environment.UAT)
{
return "uatUrl"
}
}

Is this possible in Test Studio?  If so, where can I create my C# class to use and reference it in my project?  I am not familiar with the C# way since I'm coming from a Java background.















5 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 2
answered on 23 Dec 2013, 01:06 PM
I use many custom classes all the time.  Basic idea is here: http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/utility-in-standalone.aspx

If you use the Visual Studio plugin, you can just create a new class, and if necessary, have it inherit from BaseWebAii.

Also, you may want to think about reading your config from an external file.  That way you don't have to modify your code from UAT to production.
0
Boyan Boev
Telerik team
answered on 24 Dec 2013, 12:15 PM
Hi,

@Daniel, thank you very much for you input again.

@Mike, if you have any additional questions, please do not hesitate to contact us again.

Regards,
Boyan Boev
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Mario
Top achievements
Rank 1
answered on 24 Dec 2013, 02:44 PM
Hey Daniel,
Could you elaborate on reading the config from an external file?  Where is the original config stored?  I would like to read runtime values in dynamically so this would be a huge help.

Thanks,
Mario
0
Daniel
Top achievements
Rank 2
answered on 24 Dec 2013, 02:49 PM
I simply create an XML file with values I use for my tests and place it in the Data directory.  I then use code to read those values at runtime (also write to).  I think there might be a built in way to read a config file specific for the tests, but I haven't needed that yet.  My own methods have worked out.
0
Boyan Boev
Telerik team
answered on 25 Dec 2013, 01:10 PM
Hi Mario,

You can store any information in an external file and then read it runtime. The config file is in the rood directory of the project.

Please check out this article for more information.

Thank you and Merry Christmas!

Regards,
Boyan Boev
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Dearborn I.T. Operations
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 2
Boyan Boev
Telerik team
Mario
Top achievements
Rank 1
Share this question
or