【问题标题】:WebDriverIO - Strange behaviour while running on Google ChromeWebDriverIO - 在 Google Chrome 上运行时出现奇怪的行为
【发布时间】:2020-08-02 10:45:39
【问题描述】:

我一直在为我们的项目使用 JavaScript 和 Cucumber 与 wdio 合作。

似乎 chrome 选项似乎没有任何效果。 Chrome 浏览器未最大化启动。

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

在这个网站的某些地方,我看到有人提到在选项中使用“disable-gpu”,我也尝试过,但没有效果。

当脚本在浏览器上运行时,奇怪的行为是,它通过捏住屏幕来执行每个操作。我想知道,可能是由于不兼容,因此将每个 npm 包更新到最新版本,但它的行为仍然相同。

使用的版本 -

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

package.json 依赖项 -

"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 文件 -


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') }
        ]
      }
    })
  }
}

谁能帮忙。我尝试了很多方法,但结果总是一样。也许我在这里做错了什么。请指导。

【问题讨论】:

    标签: javascript selenium-chromedriver webdriver-io


    【解决方案1】:

    我想我明白了,为什么它不起作用。我已按照以下步骤解决。希望它可以帮助遇到同样问题的人。

    1. 执行npx wdio config
    2. 回答了必填问题
    3. 在安装服务时,我选择了chromdriver而不是selenium-standalone
    4. 安装了所有必需的包,包括 - (猜猜你也可以单独安装这些,我只是选择了这条路线来执行)
    chromedriver
    wdio-chromedriver-service
    
    1. 用新配置替换了我的旧配置,它又开始工作了。它甚至以最大化模式启动浏览器。

    运行结果 -

    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.
    

    我真的不知道为什么它会表现得如此奇怪,因为 Selenium-standalone 确实包含 chromeDriver。如果有人知道这个问题的答案,请补充,会很高兴学习!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-13
      • 2014-05-18
      • 1970-01-01
      • 2011-06-15
      • 2018-08-29
      • 2012-04-13
      • 1970-01-01
      • 2013-03-13
      相关资源
      最近更新 更多