Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

c# equivalent of Java Properties()

Posted on 2014-04-16
4
Medium Priority
?
1,499 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 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Six Sigma Control Plans
Screencast - Getting to Know the Pipeline

963 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