I didn't understand when I used System.setProperty
to define a parameter, where the data is stored?
If say that I used System.setProperty
in one java file, then can I use the properties anywhere? But this is not true, I can't use it anywhere, only in the same java file I called setProperty
.
I really do not know why and what the function of this method is.
The setProperty and getProperty action tags are used for developing web applications with Java Beans. In web development, The Bean class is mostly used because it is a reusable software component that represents data. The jsp:setProperty action tag sets a property value or values in a Bean using the setter method.
setProperty manages the initialization of the Chrome driver in the first step. The System. setProperty() method forms the basis for test case automation on any browser. Naturally, QAs must understand how to use this fundamental method for all automation purposes in Selenium.
The getProperty(String key) method in Java is used to returns the system property denoted by the specified key passed as its argument.It is a method of the java.
setProperty(“propertyName”, “value”)” . It implies that it sets the system property 'propertyName' to have the value 'value'. While testing with Selenium, you will make use of the setProperty method because the browser doesn't have a built-in server to run the automation code.
System
class has a static
member variable named props which is of type Properties
. Adding to that, Properties
is a subtype of Hashtable
class. All the property values are stored as Key and Value. So, datastore is Hashtable
.Answering the other question, You can very well use System.getProperty(propertyKey)
method throughout your application since it is a public static method. You haven't understood how java programs work. When you run a Java program, you are actually starting a JVM instance. That instance will have its own System properties. That is where you have to put your property. When you run the other program, that will have its own System properties. So, you cannot expect a property which you set in one JVM instance to be accessible from another JVM instance! You can access the System.getProperty(propertyKey)
in all classes running in the same JVM instance. Hope you can understand!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With