Understanding System setProperty in Selenium

Related Product On This Page What is System class in Java?May 10, 2026 · 5 min read · Tool Comparison

Related Product

Understanding System setProperty in Selenium

The first measure in automating tests for a website or web app is deciding which browser to quiz. As a result, delineate the system place and initializing the browser object becomes necessary, particularly before writing. ThesetProperty ()method helps QAs do incisively that.

This article explains thesetPropertymethod in Selenium with a sample program.

What is System class in Java?

  • System is a Java class that belongs to thejava.lang package.
  • System is a final class and does not provide any public constructor; hence, it can not be instantiated.
  • This mean it can not be inherited to override its methods.
  • As a System class restricts to inherit and override, it provides various pre-built class battleground and methods facilitating standard input, standard output, access to externally outlined properties and environment variable, a means of loading file and library, and a utility method for quickly copying a portion of an array.

What is setProperty in Selenium?

The setProperty () method in Selenium is a part of the System class in Java and is apply to set a scheme property. A scheme property is a key-value duad that the Java runtime environment can use during the execution of a programme.

System.setProperty ()will set system place that QAs can access via any class running as a part of that java process (JVM).

setProperty in Selenium

setProperty () in Selenium, is much apply to define the position of the browser driver executables (like chromedriver.exe for Chrome, geckodriver.exe for Firefox, etc.).

Parameters:

Key: This is the name of the system property.

Value:This is the value of the system holding.

setProperty () methodhelps to set the system holdingkey to experience the value asvalue.

The system setProperty method has two attribute & # 8211; “propertyName” and “value. ” The propertyName represents the name of the browser-specific driver, and the value points to the itinerary of that browser driver.

The java.lang.System.setProperty ()method lay the system property indicated by the conditionkey.

Syntax:

public static String setProperty (String key, String value)

Returns:

This method would retrovert the premature value of the system property in the form of String, or null if it did not have one.

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Throws:

  • SecurityException− If a protection director exist and its checkPermission method doesn & # 8217; t allow setting the specified property.
  • NullPointerException− If the key or value is null.
  • IllegalArgumentException− If the key is empty.

In Selenium, setProperty () can be used to set the driver path of the respective browser.

Read More:

What is the use of the setProperty method? (with Examples)

To automate tests for a specific browser, QAs need to download the browser-specific driver first as browser do not have built-in servers for. These drivers act as a span between test scripts and browsers for test mechanization.

One can ascertain the consummate list of uncommitted browser drivers on theofficial siteof Selenium. Once the driver is downloaded for a specific browser, QAs demand thesetProperty ()method to define the path for that driver before writing any test cases.
This helps the identify the browser on which tests will be executed.

Let ’ s analyze this with examples:

System.setProperty (`` webdriver.chrome.driver '', `` D: \\Browser Binaries\\chromedriver_win32\\chromedriver.exe '');

Here, setProperty () has two parameters:

Key: “ webdriver.chrome.driver ”Value: “ D: \\Browser Binaries\\chromedriver_win32\\chromedriver.exe ” (Path of the practicable)

Here, the key implies the Selenium WebDriver uses Google Chrome driver to execute on the Chrome browser.

Value implies the placement from where the Chrome executable should be called.

If you like to run on Firefox browser, download the binary and set the values accordingly. The sampling is as below:

Key: “ webdriver.gecko.driver ”Value: & lt; Firefox binary file location & gt;

Note:Binary file location value should be update per your system itinerary.

We need to initialize the browser as the scheme properties are set now.

For Chrome browser:

WebDriver driver = new ChromeDriver ();

For Firefox browser:

WebDriver driver = new FirefoxDriver ();

Example 1: Launching BrowserStack site using Selenium employ setProperty method

public class SetPropertyExample {public still void main (String args []) {System.setProperty (`` webdriver.chrome.driver '', `` D: \\Browser Binaries\\chromedriver_win32\\chromedriver.exe ''); // Initializing the browser driver WebDriver driver = new ChromeDriver (); // Navigating to BrowserStack site driver.get (`` https: //www.browserstack.com ''); System.out.println (`` BrowserStack is launched successfully on Chrome! ``); driver.close ();}}

Example 2: Passing Key as Null

public class NullPointerExceptionExample {public static void principal (String args []) {System.setProperty (null, `` D: \\Browser Binaries\\chromedriver_win32\\chromedriver.exe ''); //Initializing the browser driver WebDriver driver = new ChromeDriver (); //Navigating to BrowserStack website driver.get (`` https: //www.browserstack.com ''); System.out.println (`` BrowserStack is launch successfully on Chrome! ``); driver.close ();}}

Example 3: Passing Key as Empty

public grade SetPropertyExample {public static void independent (String args []) {System.setProperty (`` '', `` D: \\Browser Binaries\\chromedriver_win32\\chromedriver.exe ''); // Initializing the browser driver WebDriver driver = new ChromeDriver (); // Navigating to BrowserStack site driver.get (`` https: //www.browserstack.com ''); System.out.println (`` BrowserStack is establish successfully on Chrome! ``); driver.close ();}}

Why use BrowserStack Automate to run Selenium Tests?

You should run Selenium Java Tests on a real gimmick cloud like for below reasons:

  • Naturalistic Testing Conditions: provide access to a all-embracing spectrum of device and environments, ascertain examination reflect actual user conditions accurately.
  • Enhanced Security: Maintained with high security measure, real device clouds offer secure, insulate try environments, denigrate data breach hazard.
  • Broad Browser and OS Coverage: Helps identify compatibility issues across various browser and operating systems, enhance user experience.
  • Performance Insights: Real devices yield authentic performance data necessary for optimizing covering reactivity.
  • Scalability and Accessibility: Facilitates scalable and accessible examination, suitable for distributed teams.
  • CI/CD Integration: Integrates swimmingly with CI/CD pipelines for continuous testing and early subject detection.
  • Cost-Effectiveness: Although initially more costly, it saves on long-term disbursement related to fix and support.

Conclusion

The System.setProperty () method forms the base for test case automation on any browser. Naturally, QAs must understand how to use this key method for all automation intent inSelenium.

QAs can use BrowserStack ’ s cloud Selenium grid to fulfil their for multiple browsers on various devices. BrowserStack also proffer with popular frameworks and like Jenkins, CircleCI, and TeamCity to make the test process faster and more convenient using plugins.

Tags
25,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free