What is Chrome Options class?
Chrome options class is used to manipulate various properties of Chrome driver. Chrome options class is generally used in conjunction with Desired Capabilities.
HP Unified Functional Testing is a functional testing tool that integrates the features of various other HP products (Quickest Professional, WinRunner, and HP Service Test). Functional tests are automated by recording the actions of a user on the application or system under test. Scripts are used to store the recorded actions in UFT. Scripts can.
Example:
Below example shows a way to open Chrome browser in maximized mode using ChromeOptions class. We need to pass an instance of ChromeOptions class to the web driver initialization.
Below are the list of available and most commonly used arguments for ChromeOptions class
- start-maximised: Opens Chrome in maximize mode
- incognito: Opens Chrome in incognito mode
- headless: Opens Chrome in headless mode
- disable-extensions: Disables existing extensions on Chrome browser
- disable-popup-blocking: Disables pop-ups displayed on Chrome browser
- make-default-browser: Makes Chrome default browser
- version: Prints chrome browser version
- disable-infobars: Prevents Chrome from displaying the notification 'Chrome is being controlled by automated software
In this tutorial, you will learn
Desired Capabilities class
Desired capabilities class is used to modify multiple properties of web driver. Desired Capabilities class provides a set of key-value pairs to change individual properties of web driver such as browser name, browser platform, etc. Most commonly used method of Desired Capabilities class is setCapability method. Desired Capabilities is most frequently used with Selenium Grid where the same test case needs to be executed on different browsers.
Example:
Below example shows the way to enable chrome browser to accept SSL certificates on websites by default using Desired Capabilities class.
Below are the most commonly used pre-defined capability types.Capability Name | Description |
ACCEPT_SSL_CERTS | This property tells the browser to accept SSL Certificates by default |
PLATFORM_NAME | This property is used to set the operating system platform used to access the web site |
BROWSER_NAME | This property is used to set the browser name for a web driver instance |
VERSION | This property to used to set the browser version |
Chrome Options for Adblocker extension
Adblocker extension of the Chrome browser can be handled using Chrome Options and Desired Capabilities class. Below are the steps to access AdBlocker extension on the Chrome browser using Desired Capabilities class.
Step 1) AdBlocker extension must be installed on Chrome browser before using Chrome Options class
Step 2) Extract the CRX File corresponding to AdBlocker extension through http://crxextractor.com/
Step 3) Pass the downloaded CRX File path to Chrome Options class
Step 4) Instantiate the web driver using the desired capabilities class and chrome options object
Example:
Below example demonstrates how to activate ad blocker extension on the Chrome browser using Chrome Options and Desired Capabilities class.
Extract CRX File:
Below steps demonstrate the process of extracting CRX File through Ad Blocker through the web site - http://crxextractor.com/
Step 1) Go to http://crxextractor.com/ and click start button
Step 2) Enter the chrome extension – Ad Blacker URL under the textbox. URL for Adblock on Chrome web store is https://chrome.google.com/webstore/detail/adblock/gighmmpiobklfepjocnamgkkbiglidom
and click ok
Step 3) On clicking the OK Button, the label of the button will change to Get .CRX as below. Click on Get .CRX button, CRX file corresponding to the extension will be downloaded
Step 4) Save the file onto the local machine, make a note of the path saved. The next step is to pass the saved path to Chrome Options class
Sample Code:
- You will see ads at http://demo.guru99.com/ as below
- With AdBlocker extension enabled on Chrome browser ads should be disabled
Code Explanation:
- Initially, you need to set the path to the chromedriver.exe file using set property method since you are using Chrome Browser for testing
- You need to set the path to CRX File to add extensions method
- Then you need to create an object of desired capabilities class and pass it to web driver instance. From Selenium 3.8.1 version, driver capabilities class is deprecated and you need to merge capabilities object with Chrome Options object before passing the same as an argument to Chrome Driver constructor
- Open the URL - http://demo.guru99.com/test/simple_context_menu.html with Ad Blocker extension enabled
- Maximize and close the browser
NOTE: We are enabling AdBlocker extension on the Chrome browser through automation script instead of manually enabling Adblocker extension on the Chrome browser. CRX File is a way to access ad blocker extension using automation script
Output:
Chrome browser will be enabled with AdBlocker extension enabled as below without any ads
Chrome Options for Incognito mode
Chrome Options can be used for incognito mode by using the pre-defined argument –incognito.
Below is the sample code to accomplish the same.
Sample Code:
Code Explanation:
- Initially, you need to set the path to the chromedriver.exe file using set property method since you are using Chrome Browser for testing
- Then you need to create an object of Chrome Options class and pass it to web driver instance. Since we want to open Chrome browser in incognito mode, you need to pass the argument –incognito to Chrome Options class.
- Next, create an object of Desired Capabilities class and merge the Desired Capabilities class object with Chrome Options class object using merge method
- You need to create an object of Chrome Driver class and pass the Chrome Options object as an argument
- Finally, we need to pass the URL - http://demo.guru99.com/test/simple_context_menu.html to the driver.get method
- Maximize and close the browser
Output:
The chrome browser window will be opened in Incognito mode as below
Chrome Options for Headless Chrome
A Headless browser runs in the background. You will not see the browser GUI or the operations been operated on it.
Chrome Options for running Chrome browser in headless mode can be accomplished by using the predefined arguments –headless.
Sample code to accomplish it is mentioned below.
Example:
Code Explanation:
- Initially, you need to set the path to the chromedriver.exe file using set property method since you are using Chrome Browser for testing
- Next, create an object of Chrome Options class and pass it to web driver instance. Since we want to open Chrome browser in headless mode, we need to pass the argument –headless to Chrome Options class.
- Create an object of Desired Capabilities class and merge the Desired Capabilities class object with Chrome Options class object using merge method
- Create an object of Chrome Driver class and pass the Chrome Options object as an argument
- Finally, we need to pass the URL - http://demo.guru99.com/ to the driver.get method
- Print the page title and close the browser
Output
The browser will not be visible for the above code as Chrome will be working in Headless mode. Page title will be fetched and displayed as below.
Summary:
- Chrome options class is used to manipulate various properties of Chrome driver
- Desired Capabilities class provides a set of key-value pairs to modify individual properties of web driver such as browser name, browser platform, etc.
- To manipulate any extensions of Chrome browser, CRX File corresponding to the extension must be extracted and must be added to Chrome Options class
- --incognito and –headless are predefined arguments provided by Chrome Options class for using Chrome browser in incognito mode and headless mode
All of a sudden UFT tool stopped identifying objects in Chrome all the objects get identified as Win object. I have my UFT extension enabled.
1 Answer
See the below comment from user Phenomite in the MicroFocus forums - It seems Chrome released a silent patch which messed things up for UFT/LeanFT(UFT Pro):
This is caused by a silent patch that has rolled out to address fullscreen and popup sandboxing issues with extensions using gesture APIs. A chromium forum engineer posted the changed code which directed me in how to fix it.
-> Open chrome://flags.
-> Search for 'Touch events API' and set it to 'Enabled'
-> Search for 'User Activation V2' and set it to 'Enabled'
-> Click the restart chrome prompt.
If you are interested, the patch code that fixed (but broke) extension gestures API: https://chromium.googlesource.com/chromium/src/+/6b20212bdffccd581703de1f229921151ea4750b/extensions/renderer/bindings/api_request_handler.cc#264
Source: https://community.softwaregrp.com/t5/Unified-Functional-Testing-User/UFT-14-03-Build-3501-not-recognizing-Google-Chrome-71-0-3578-98/m-p/1681220