1. headless launch option
  2. Accept and bypass privacy error
  3. disable info bar
  4. change height/width of window
  5. run code in incognito mode (private browsing)
  6. launch browser in mobile view

headless launch option

Let us google search “upgrade to selenium 4”

Click the first search result link https://www.selenium.dev/documentation/webdriver/troubleshooting/upgrade_to_selenium_4/ 

Notice below that the DesiredCapabilities is now kind of deprecated. It is replaced by browserOptions() classes like FirefoxOptions, ChromeOptions etc

Let us see how some of these options work. Launch https://rahulshettyacademy.com/ to find out the page title

In line#12 below, we are creating a reference ‘o’ of FirefoxOptions() and passing this reference as constructor argument in line#16 

We have invoked the headless in line#13.

When we run our code, the browser does not launch and the page title gets printed

The exact same thing can be achieved using ChromeOptions() as well, see below

Before we move ahead, let us comment

Accept and bypass privacy error

Launch https://expired.badssl.com/ 

Below certificate error is seen and to bypass this privacy error, we have to perform some manual steps

Let us try to run it through selenium and see if we can bypass the privacy error

Run, see below, we still get the privacy error 

To bypass the privacy error, we have to simply use the below option and set it to ‘true’ 

Now when we run, the error gets bypassed, see below

disable info bar

When an automation test launches a browser, there is an info bar that is visible, see below, “Chrome is being controlled by automated test software” 

We can disable this info bar by setting the option:

o.setExperimentalOption(“excludeSwitches”, Collections.singletonList(“enable-automation”));

Run, now we don’t see the info bar

change height/width of window

We can change the window dimensions by setting the highlighted option

Run, the window dimension changes

run code in incognito mode (private browsing)

The below setting can be used to open the chrome in incognito mode:

o.addArguments(“incognito”);

launch browser in mobile view

Let us say we want to launch website in iPhone-x mode.

We can do that by first creating a hashmap reference and then setting the reference as experimental option (see line#28)

Run, see below. The browser launches in iPhone mode and the website is displayed as if we are opening the website in iPhone

Below is source code snapshot

So, that’s how we can manipulate different behaviours of our browser.


Tags


You may also like

Groups attribute in TestNG 

Groups attribute in TestNG 

Priority attribute in TestNG 

Priority attribute in TestNG 
Leave a Reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}