Solved

c# equivalent of Java Properties()

Posted on 2014-04-16
4
1,011 Views
Last Modified: 2014-10-04
Hi Guys,

I'm setting up a automated test framework using Visual Studio with the Selenium libraries. I had a similar one working in java but due to where I'm working now the preferred tool is Visual Studio and c#. The java code below allows me to import a properties file and retrieve the values during the code. For example if the or.properties file had the line myButton=//INPUT[@name='txtMyButton'] the the code below OR.getProperty("myButton") would return thye XPath value form the file. I was wondering if there is a way to do something similar in c#. That is have a file which stores all the XPath locations and they can be retrieved using a more meaningful name for the user so I'. not hardcoding the XPath values in the code.

fs  = new FileInputStream(System.getProperty("user.dir")+"\\src\\com\\hybrid\\config\\or.properties");
OR= new Properties();
OR.load(fs);

OR.getProperty("myButton")

Open in new window


Any ideas would be very appreciated

Thanks
0
Comment
Question by:victoriaharry
  • 2
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40005711
Use app settings or settings, either of which end up in the application's configuration file, just in different sections.
0
 

Author Comment

by:victoriaharry
ID: 40005785
Thanks for the prompt response.

I'm really looking for a way I can use a string value to pass the matching value in a text file. In Java OR.getProperty("myButton") would bring back the value for the myButton property. This is because down the track I want to read the values from excel and perform the action on the object. For example the user would have some lines in excel such as Click myButton and the code would find the matching XPath value for myButton and perform the click operation.
Hope this makes sense
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40005799
It's the same kind of thing. For instance, with AppSettings you would have:

string xpath = ConfigurationManager.AppSettings["myButton"];

Open in new window


With settings you would have:

string xpath = Properties.Settings.Default.MyButton;

Open in new window


Settings gives you an actual code identifier to use. This is because you actually create one when you enter the identifier name within the project properties window:

e.g.

Screenshot
0
 

Author Comment

by:victoriaharry
ID: 40005850
ok thanks,

do you have to use appSettings or can you load different configuration files and use them as needed. ie environments.config, or.config, etc. Each config file would have different keys and values which I can access
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question