What is System setProperty in Selenium? How does it work?
Testing is an essential process of software development. There are many things that can go wrong if you do not test a software application. Therefore, double check on the developed software is a good practice to ensure it meets the quality demands.
As you are aware, today’s IT world depends on the Automation Testing of an application. Why? It’s just because of the features, frameworks, performance, and quality test results. This is also possible if we have a tool or a framework that caters to the above needs. One such framework is Selenium.
The first step in automating tests for a website or web application is deciding which browser to use. Consequently, before writing test scripts, it becomes necessary to define the system properties and initialize the browser object. That’s where the setProperty() method comes into the picture.
In this blog, let’s understand what setProperty in Selenium is and how it works.
Table Of Contents
- 1 What is System setProperty in Selenium?
- 2 What is the use of setProperty method?
- 3 Demo: Illustrating setProperty in Selenium
- 4 Testsigma To The Rescue
- 5 Summary
- 6 Frequently Asked Questions
What is System setProperty in Selenium?
setProperty is a method that implies setting the properties for the browser for creating test cases. This method is considered to be the first step to defining while writing test cases. You will see how it is used in the next section of the blog.
setProperty in Selenium
Let’s take a look at the command below to understand what it means
The above command setProperty has two attributes:
- Name of the property, and
- Property value
In the above command – webdriver.chrome.driver is the name of the property. This explains that the Selenium WebDriver is using a Google Chrome Driver to execute the test cases on the Google Chrome Browser.
In case you are using Firefox browsers, the property name will be – webdriver. gecko.driver.
Note: Firefox browser uses Gecko driver.
The path – “C:\\Data\\ChromeDriver\\chromedriver.exe” – represents the property value. This implies that your ChromeDriver executable file is present in that location and you are calling the chrome driver by specifying the path where you have downloaded and saved the driver in your local system.
Note: This path can vary from person to person. How to configure the Browser drivers can be understood by referring to this blog here.
As soon as you set the system properties, you need to initialize a browser with the help of the command below. As we are using Chrome Driver, we will create an object of the Chrome browser.
The rest of the code or the test methods can be written after instantiating the browser instance. N0w, let’s understand why it is used.
What is the use of setProperty method?
While testing with Selenium, the setProperty method is used because the browser doesn’t have a built-in server to run the automation code. You will need a Chrome/IE/Gecko driver server to communicate your Selenium code to the browser.
In simple words, to set the path of the driver for the respective browser, you will need the system.setProperty.With the help of setProperty method, server communication can be achieved. I’ve explained how to do that below.
Let’s now take a small example for Chrome Browser and understand how this method is used and how it works.
Demo: Illustrating setProperty in Selenium
When you execute the above code, it will launch the Google.com website in Google Chrome using ChromeDriver, where the initialization of the driver is handled by system.setProperty method. This has to be the first line of code that needs to be executed in your Selenium script before any test method to initialize the driver. That’s how it works. If you wish to use Firefox Browser and Gecko Driver, you can use them accordingly.
This will also search for the Testsigma keyword in Google Chrome and click on the search icon. This is achieved through the locators, sendkeys method, and click button.
One can check the complete list of available browser drivers on the official site of Selenium. Once the driver is downloaded for a specific browser, QAs need the setProperty()method to define the path for that driver before writing any test cases.
When using Selenium, 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.
To write any test case, the first step is to set the system properties for a specific browser or web application. To execute the test case, you need to have a specific browser driver configured into the system. This is a complex process, as one needs to have strong coding skills, understand the problem statement, configure all the dependencies, and execute the test cases.
Just imagine how it would be if you were asked to carry out testing without the coding knowledge and all the other technical aspects. Sounds Interesting!
Yes, that’s exactly what Testsigma does. The next section talks about how Testsigma can help you create and run test cases with ease.
Note: You can also compare the difference between Selenium and Testsigma and how Testsigma takes an edge over Selenium.
Testsigma To The Rescue
Testsigma is a cloud-based test automation tool built to address the challenges that came with traditional tools. Some of the major problems that Testsigma aims to solve are huge initial time, cost and resources, Slow test development speed, High maintenance cost, Less or no Reusability of test cases, support for Collaboration, and many more.
Testsigma offers several features including:
- Codeless automation, not just limited to basic tests
- Lets everyone on your team automate testing – including QAs &SMEs
- Platform with all the essential elements for continuous testing
- Enhance the platform’s automation capabilities for all your custom needs
- In sprint test automation for fast-faced Agile and DevOps teams
- Customizable object spy for every application that makes your tests robust
- AI to reduce maintenance and improve the team’s efficiency
- Reduce regression testing from weeks to minutes
- Increased maintainability and reusability and reliability
This brings us to the end of the blog on system setProperty in Selenium.
In this blog, we understood the system setProperty in Selenium and why it is necessary. As mentioned earlier, there are various web browser drivers for every browser. Here, we learned how to set system properties for Chrome Driver. Similarly, we can set the system properties for Firefox browser using Gecko Driver, Microsoft Edge driver for Edge browser, etc.
As Selenium supports multiple browsers and browser versions, so is the reason for various browser drivers. These drivers are necessary to establish a connection to the server. That’s where system setProperty in Selenium is used.
Frequently Asked Questions
How can we set the system property for ChromeDriver?
To set the system setProperty for ChromeDriver, take a look at the below
How do you create a system property?
- You can set system properties programmatically by using Java. java.lang.System.setProperties() method is used to create the system properties.
- The -D option of the java command can be used.
- The jt400.properties file can also be used to create system property.
- Using a Properties class.