Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Selenium - Starting a Browser Instance | Browser Automation with Selenium
Introduction to QA Automation Testing
course content

Зміст курсу

Introduction to QA Automation Testing

Introduction to QA Automation Testing

1. Introduction to Automation Testing
2. Using a Test Automation Framework
3. Browser Automation with Selenium
4. Intro to Intermediate Automation Testing

bookSelenium - Starting a Browser Instance

Since we aim to automate a browser, naturally the first step is to be able to create a new browser window. In this chapter we will learn how to create a new browser window along with some basic configurations.

Summary

To create a new browser window, first we need to import the Builder class from selenium-webdriver module:

Once it is imported, we need to import the relevant module based on our choice of browser. For-example, if we want to automate chrome, we need to import the chrome module from the selenium-webdriver folder:

Following are the imports for other browsers:

Once we're done with the required imports, we can move on to writing the code for creating the browser window. It is important to note that almost all of the functions and methods provided by Selenium are asynchronous in nature, hence, when we are executing Selenium code, we need to enclose it in an asynchronous function.

We can create an inline asynchronous function using the following syntax:

JavaScript allows us to execute the function directly without storing it anywhere, using the following syntax:

Inside this function, we can add the following two lines of code, where path/to/webdriver.exe represents the path to the webdriver which you downloaded for your choice of browser (for-example: chromedriver.exe):

Note that, for using the path module, we need to import that as well:

We can use the addArguments method of browserName.Options() class to define configurations for the browser before launch. For-example, the following code sets Chrome's language to English-UK and disables the "Default Search Engine Selection Screen".

Finally, for creating the browser window, we can use the Builder class:

The forBrowser method specifies which browser we are aiming to automate. The setChromeService method accepts a ServiceBuilder object, which contains the path to the webdriver.

setChromeOptions is a method for configuring chrome, and it accepts the options object. There are similar methods for other browsers as well, for-example, setEdgeOptions, setIeOptions, setSafariOptions, etc.

The build method initializes the window, and returns a reference which can be used for controlling what goes on inside the browser window.

Which object is used for creating a browser instance ?

Which object is used for creating a browser instance ?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2
some-alt