Configuration File And Handling Different Test Automation Scenarios In WebDriverIO

In this article we can look at the configurations we can set in order to run our test/spec files with respect to those configurations.

We will also discuss a few additional Test automation scenarios in WebDriverIO.

As you know in WebDriverIO the wdio.conf.js contains all the configurations for the tests. We can call it a test/spec runner file as well.

Let's deep dive into each of those.


Where the tests should be run we can run tests in local, different services(browser stack,saucelabs), and selenium cloud.

If you use a selenium standalone/private selenium server then provide the below configuration.

  • portname
  • host
  • protocol

If you are using any third-party cloud services(browserstack and saucelabs), then provide the username, apikey, region and headless


headless: true/false

If headless is true then all the spec/test files will run on headless mode. The browser will not open while the tests runs inside the saucelabs/browserstack.

If headless is false then all the spec/test files will run on headed mode. The browser will get opened and actions will be performed inside the browser.


Specify which spec/test file to run when we run the command.

npx wdio run wdio.conf.js

exclude: [

If the user does not want to run any particular spec/test files those files path can be mentioned in this exclude array object.


Capabilities enables user to instruct the WebDriver regarding the environment to be used while running the tests. Users can execute tests on desired devices, browsers, and operating systems available on a Cloud/Grid or third-party cloud vendors(browserstack, saucelabs)

    browserName: 'Chrome',
    bstack: options ': {
    projectName: testbrowserstack
    osVersion: '10.0',
    deviceName: 'iphone 10',
    buildName: buildtesting,
    geoLocation: 'US',
    networkLogs: 'true',


How many workers/Instances are needed to run the tests?


Used to control the logs that are displayed in the console while the test run.

For example: if user sets loglevel:error then while running the tests only error logs will get displayed in the console.

The values for loglevel are,

  • trace
  • debug 
  • info
  • warn
  • error
  • silent


Used to store the logs for the tests which run. Accepts directory name as value.


If you want to run the tests until a specific number of tests fails.

Eg: you have 10 tests in a suite if bail value is 3, out of the 10 tests that runs if 3 tests fail out of 10 then the entire suite will stop running and displayed as failure


Provide the application URL which we are going to test.


Default wait time for all the waitfor commands in WebDriverIO.


Which test framework you are going to use to write the tests - Mocha, jasmine or cucumber


How many times a spec file should rerun when the spec file fails.


Delay in seconds between the spec file retry attempts


Which type of reporting you are going to configure in order to view the tests results.


Hooks are preconditions and postconditions for the tests which you are running.

There are many hooks we can configure in the config file. The most commonly used hooks are

  • before() Runs once before all it blocks gets executed
  • after(), Runs once after all it blocks gets executed
  • beforeEach(), Runs each time before it block gets executed
  • afterEach().Runs each time after it block gets executed

Additional Test automation scenarios


We can take screenshot in WebDriverIO using savescreenshot function.


browser.saveScreenshot('path of the file.png');

It stores the screenshot image in the relative path of the project.

Handling windows

We can handle windows in webdriverIO using  getwindowhandle and getWindowhandles function

const parentwindowid=getwindowhandle->returns a unique id of the window

getWindowhandles-->retuns a list of unique id of windows.

To switch to child window we can make use of function switchTowindow and pass the childwindowid as an argument


Handing frames

We can handle frames in webdriver IO using the below iframelocator methods

  • Using frame id
  • using name
  • using frame index

We need to use switchToframe(iframelocator) performs the operation inside the frame and to move outside of the frame use the below function

switchToframe(null) -> which will move the focus to the default window


type text into textarea or input field



Clears the value from the textarea or input field



Check whether the webelement is displayed or not on the webpage. The function returns boolean value true/false, if it is true then the element is present if false then the element is not displayed.

let val=$('#testid').isDisplayed()


Check whether the webelement is in enabled state or disabled state on the webpage. The function returns boolean value true/false, if it is true then the element is enabled if false then the element is disabled.

let val=$('#testid').isEnabled()


Check whether the checkbox/radio button, dropdown options are selected or not. The function returns boolean value true/false, if it is true then the element is selected if false then the element is not selected..

let val=$('#testid').isSelected()


Check whether the webelement exists in the webpage. The function returns boolean value true/false, if it is true then the element exists if false then the element does not exists.

let val=$('#testid').isExisting()


Returns the tagname for the webelement.

let tag=$("#test").getTagName()


Returns the attribute value. The function takes the attribute property of the element as an argument and return the attribute value.

const input = $('#inputid')
const attr = input.getAttribute('placeholder')


Returns the CSS property value. The function takes the CSS property of the element as an argument and return the CSS attribute value.

const fontfamily = $('#test).getCSSProperty('font-family')


In this article, I have explained the different configurations that can be set in configurations and some additional automation scenarios which can be helpful while developing test automation scripts using WebDriverIO.

Thank you

Happy learning.......