Adarsh Kumar GM
Adarsh Kumar GM

Reputation: 174

WebDriverIO - Strange behaviour while running on Google Chrome

I have been working with wdio using JavaScript and Cucumber for our project.

Seems like chrome options doesn't seem to have any effect. Chrome browser doesn't start maximised.

goog:chromeOptions': {
 args: ['--start-maximized']
}

Some where on this site, I saw a person mentioning of using "disable-gpu" to the options, I have tried this as well and there is no effect.

When the script runs, on the browser, the strange behaviour is, it performs each operation by pinching the screen. I was wondering, maybe it is due to incompatibility and hence updated every npm package to the latest version, but it still behaves the same way.

Versions used -

WebDriver Version: 6.3.5
Chrome Driver Version: 84.0.1
Google Chrome Version: 84.0.4147.105

package.json dependencies -

"devDependencies": {
    "@wdio/cli": "^6.3.6",
    "@wdio/cucumber-framework": "^6.3.0",
    "@wdio/local-runner": "^6.3.6",
    "chromedriver": "^84.0.1",
    "cucumber-html-reporter": "^5.2.0",
    "eslint": "^7.2.0",
    "eslint-config-standard": "^14.1.1",
    "eslint-plugin-import": "^2.21.2",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.1",
    "wdio-cucumber-framework": "^2.2.8",
    "wdio-cucumber-reporter": "0.0.2",
    "wdio-cucumberjs-json-reporter": "^2.0.2",
    "wdio-firefox-profile-service": "^0.1.3",
    "wdio-selenium-standalone-service": "0.0.12",
    "wdio-viewport-size": "^1.0.1",
    "webdriver-manager": "^12.1.7",
    "webdriverio": "^6.3.5"
  },
  "dependencies": {
    "@wdio/sync": "^6.3.6",
    "axios": "^0.19.2",
    "chai": "^4.2.0",
    "chance": "^1.1.6",
    "cucumber": "^6.0.5",
    "cucumber-pretty": "^6.0.0",
    "fs-extra": "^9.0.1",
    "knex": "^0.21.1",
    "lodash": "^4.17.15",
    "moment": "^2.26.0",
    "multiple-cucumber-html-reporter": "^1.18.0",
    "postgres": "^1.0.2",
    "ramda": "^0.27.0",
    "rimraf": "^3.0.2",
    "underscore": "^1.10.2",
    "wdio": "^4.0.0",
  }

wdio.conf.js file -


const cucumberJSON = require('wdio-cucumberjs-json-reporter')
const multipleCucumberHtmlReporter = require('multiple-cucumber-html-reporter')
const moment = require('moment')
const { removeSync } = require('fs-extra')
exports.config = {
  runner: 'local',
  specs: [
    './features/E2E/E2E.feature'
  ],
  exclude: [
  ],
  maxInstances: 10,
  services: ['selenium-standalone'],
  capabilities: [{
    maxInstances: 5,
    browserName: 'chrome',
    'goog:chromeOptions': {
      args: ['--start-maximized']
    },
    'cjson:metadata': {
    // For a browser
      browser: {
        name: 'chrome',
        version: '58'
      },
      device: 'HP Elite',
      platform: {
        name: 'windows',
        version: '10'
      }
    }
  }],
  logLevel: 'debug',
  bail: 0,
  waitforTimeout: 10000,
  connectionRetryTimeout: 120000,
  connectionRetryCount: 3,
  services: ['selenium-standalone'],
  framework: 'cucumber',
  reporters: ['cucumberjs-json'],
  cucumberOpts: {
    require: ['./stepDefinitions/given.js', './stepDefinitions/when.js', './stepDefinitions/then.js'],
    backtrace: true,
    requireModule: [],
    dryRun: false,
    failFast: false,
    format: ['pretty'],
    snippets: true,
    source: true,
    profile: [],
    strict: true,
    tagExpression: '@E2E',
    timeout: 60000,
    ignoreUndefinedDefinitions: false
  },
  onPrepare () {
    removeSync('.tmp/')
    console.log('Starting cucumber tests')
  },

  async afterStep () {
    await browser.takeScreenshot().then((val) => {
      cucumberJSON.default.attach(val, 'image/png')
    }).catch((err) => {
      console.log('Error in capturing screenshots', err)
    })
  },

  onComplete () {
    multipleCucumberHtmlReporter.generate({
      openReportInBrowser: true,
      reportName: 'Project Report',
      screenshotPath: './reports/screenshots/',
      displayDuration: true,
      saveCollectedJSON: false,
      jsonDir: '.tmp/json/',
      reportPath: './reports/',
      customData: {
        title: 'Project Data',
        data: [
          { label: 'Project', value: 'Project Value'},
          { label: 'Release', value: '1.0' },
          { label: 'Execution Start Date', value: moment().format('dddd, MMMM Do YYYY') }
        ]
      }
    })
  }
}

Can anyone please help. I have tried a lot ways, but results always remains the same. Maybe I am doing something wrong here. Please guide.

Upvotes: 1

Views: 1627

Answers (1)

Adarsh Kumar GM
Adarsh Kumar GM

Reputation: 174

I think I figured out, why it doesn't work. I have followed the below steps to resolve. Hope it helps someone out there facing same issue.

  1. Performed npx wdio config
  2. Answered the required questions
  3. When it comes to installing services, I chose chromdriver instead of selenium-standalone
  4. Installed all the required packages which includes - (Guess you can install these separately as well, I just chose this route to perform)
chromedriver
wdio-chromedriver-service
  1. Replaced my old config with new one and it started working again. It even started the browser in maximised mode.

Result of the run -

Starting cucumber tests
Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.      
ChromeDriver was started successfully.

I really do not know why it should behave like this strangely, since Selenium-standalone does contain the chromeDriver. If anyone knows the answer to this, Please add, would be great to learn!

Upvotes: 0

Related Questions