WebDriverIO: Run tests in Virtual Machine's browser

WebDriverIO: Run tests in Virtual Machine's browser

Running tests in the CI-CD pipeline is a common strategy used by most companies. But while working on one such scenario, I had to automate a test case for a tool that was hosted/only accessible via Virtual Machine. This was challenging as the VM used Win 10 and the tests needed to be performed in it. So while working on it there were not many articles/resources available to work with. For tests, I used the Chrome browser for testing.

So after several hours of R&D, I was able to make it work. Below I'll mention all the steps and challenges I faced and how to work around them.

Packages and their respective versions on my machine :

  • Nodejs - v14.
  • WebdriverIO - v7.
  • Java - jdk1.8.
  • IE - 11.
  • Base Machine OS - Win 10.

Pre-requisites :

  1. Download and Install Virtual Box [make sure you have more than 25 GB space for the ova/ovf image].
  2. Download Win 10 virtual box image.
  3. Import the ova/ ovf image as an appliance.
  4. After the import is complete, install the following packages :
  5. Java (JDK). 5.Download :
  6. Selenium Standalone Server %[selenium.dev/downloads/].
  7. As we are working in VM, I'll keep the Selenium Standalone Server [.exe] file in my desktop/SeleniumServer folder.
  8. Extract and copy the SeleniumStandaloneServer.exe to the desktop/SeleniumServer folder.
  9. After all the steps have been completed, ShutDown the VM.

Network Configurations

  • First, we'll have to configure the Host-Only Network.

    • Go to File Menu of Virtual Box > Host Network Manager.
    • Click on Create Host only Network Adapter.
    • Select Adapter > Configure Adapter Manually.
    • Add the following :
      • IP : 192.168.56.1
      • NetMask : 255.255.255.0
    • Select the checkbox Enable under DHCP server.
    • Click Ok.
  • Second, we'll have to add Network Adapter to the VM.

    • To Add Network Adapter Go to File > Preferences > Network > Click on Add on NAT network.
    • Leave Adapter 1 as it is.
    • Go to the Adapter 2 tab.
    • Select Enable Network Adapter Checkbox.
    • Select Host Only Adapter from Attached to.
    • Click on Ok.
    • Start the VM.
    • Inside the VM :

      • Go to Network Sharing, Click on Change Adapter Options.
      • On the new Ethernet Adapter right click and select properties.
      • Go to IPv4 settings > properties.
      • Add :

        • IP : 192.168.56.2
        • Netmask : 255.255.255.0
        • Default Gateway: 192.168.56.1
        • Preferred DNS Server: 192.168.56.1
      • Save and Close.

      • Disable Windows Firewalls.
      • Restart VM.

The Above steps mainly dealt with setting up the environment for our testing. In the next section, we'll focus on working on our test cases.

WebdriverIO: In this section, we will create a webdriverio framework from scratch. Steps :

  • Create a folder vmtest (location can be up to you).
  • Open cmd prompt [or bash terminal].
  • Traverse to the folder vmtest.
  • Initialize the folder as a node project by executing the following cmd in the terminal :
    • npm init -y
  • Install the dependencies :
    • npm i -D webdriverio
    • npm i @wdio/cli.
  • After the dependencies have been installed, its time to create test runner
    • npx wdio config { After this cmd is executed it will ask us some configuration-related questions. Please refer to the image below} test-runner-1.gif

Once finished with all the configuration there will be a file created in your workspace called wdio.conf.js.

Since webdriverio v6 some settings have been changed so inside the capabilities section in wdio. conf.js :

  • After browserName : 'chrome' add hostname : 192.168.56.2, port: 4444
    • Remove the hostname and port mentioned below runner: 'local'.<
  • In the base Url property add baseUrl:'http://demo.guru99.com/test/newtours/'

capabilities: [{
     maxInstances: 5,
     browserName: 'internet explorer',
     hostname: '192.168.56.2',
     port: 4444,
    }],
services: ['selenium-standalone'],

In case you want to test in Chrome browser


capabilities: [{
     maxInstances: 5,
     browserName: 'chrome',
     hostname: '192.168.56.2',
     port: 4444,
    }],
services: ['chromedriver'],
  • Create a test case.

  • Running the tests :

    • Run the IESelenium.bat file in the VM. { this will start the selenium standalone server and IEDriver }
    • For Chrome > just run the tests

    • From the base machine run the webdriverIO test.

  • Check the VM if the browser is launched or not.