Solved

c# equivalent of Java Properties()

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

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 74

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 …
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…

759 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

18 Experts available now in Live!

Get 1:1 Help Now