Solved

c# equivalent of Java Properties()

Posted on 2014-04-16
4
971 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

776 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