Explore WebdriverIO Config Files – WDIO 102

What are WDIO Script Configurations

In our first article, we installed a few main dependencies you need to run and execute our WebDriverIO project. We even executed the dummy test file WebDriverIO created for us. WDIO created a template from a boilerplate project, so many configurations were already done for us. Now let’s explore what those configurations are.

wdio.conf.ts File

Many things happen in the background when you execute the NPM RUN WDIO command in your project files. WDIO explores our spec files, finds the suitable driver and execution environment, runs Selenium-based automation with proper timeouts, etc. All those parameters are defined in the wdio.conf.ts file. If you use javascript language, that file will have a js extension.

So let’s check what we have in that file.

Feature Files Configuration

specs: [
       './features/**/*.feature'
   ],
   // Patterns to exclude.
   exclude: [
       // 'path/to/excluded/files'
   ],

First, we define the spec files’ location under our projects; as you might divide your spec files into categories, we don’t want to specify the whole folder, so we wildcard it. and define the extension of our files. So now, any files with feature extension under the parent folder ‘feature’ will be executed as a test.

If you want to exclude some files, you can use the second option and disable some feature files to be executed.

Driver Capabilities

capabilities: [{

    maxInstances: 5,
    browserName: 'chrome',
    acceptInsecureCerts: true
}],

Here we set our Selenium capabilities like

  • Which Browser will be triggered for the tests
  • How many instances can be executed parallelly
  • If we accept insecure websites etc

If you have experience with Java/Selenium setup, those configurations are always done at the code level. WebDriverIO allows you to configure all those in a configuration file outside the code files.

TimeOut Configurations

baseUrl: 'https://google.com',
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
   

You can change all time-out configurations in that file too. You might define your base URL, selenium command timeout, or browser/Cloud provide timeouts.

As you can see, this configuration uses Chrome as a default browser. During my first WebDriverIO project initialization, I did not install GeckoDriver. So I need to install and change a very small config on my project.

How to Install Gecko or other Drivers

npm install wdio-geckodriver-service --save-dev

The above command will install Gecko driver, but you have more options like Appium, WinApp, SauceLabs, etc. You might want to visit that page to understand how you install the rest of the drivers.

After adding gecko driver, all we need to do is change the services object in wdio.conf.ts

Previous Settings for my local:

services: ['chromedriver','appium'],

Final Settings:

services: ['chromedriver','appium', 'geckodriver'],

Then you need to change capabilities to firefox instead of chrome like below.

capabilities: [{
  
       maxInstances: 5,
       browserName: 'firefox',
       acceptInsecureCerts: true
   }]

If you execute the NPM RUN WDIO command, new tests will be executed in the Firefox browser.

In the next article, we’ll execute our scripts in GitHub Actions…

Keep us following!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.