Solved

c# equivalent of Java Properties()

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now