0

在此处输入图像描述

从上图中可以看出,当我们开始运行 nightwatch 时,在控制台中我们可以看到浏览器名称、版本以及操作系统名称和版本。

有没有办法获得版本价值并在代码中使用,就像我们过去获得平台一样

process.platform=win32 or darwin
4

1 回答 1

0

我从https://github.com/nightwatchjs/nightwatch/issues/2445得到了答案。

module.exports = {
  'Demo test GitHub': function (browser) {
    console.log(browser); // this will output all the details
    browser
      .url('http://www.google.com')   // visit the url
  }
};
因此浏览器对象提供以下详细信息:

NightwatchAPI {
  capabilities:
   { acceptInsecureCerts: false,
     acceptSslCerts: false,
     applicationCacheEnabled: false,
     browserConnectionEnabled: false,
     browserName: 'chrome',
     chrome:
      { chromedriverVersion:
         '83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416})',
        userDataDir:
         '/var/folders/5l/mgjzx80j4pb1trj_zlqrn7cc0000gp/T/.com.google.Chrome.WEyC7u' },
     cssSelectorsEnabled: true,
     databaseEnabled: false,
     'goog:chromeOptions': { debuggerAddress: 'localhost:51082' },
     handlesAlerts: true,
     hasTouchScreen: false,
     javascriptEnabled: true,
     locationContextEnabled: true,
     mobileEmulationEnabled: false,
     nativeEvents: true,
     networkConnectionEnabled: false,
     pageLoadStrategy: 'normal',
     platform: 'Mac OS X',
     proxy: {},
     rotatable: false,
     setWindowRect: true,
     strictFileInteractability: false,
     takesHeapSnapshot: true,
     takesScreenshot: true,
     timeouts: { implicit: 0, pageLoad: 300000, script: 30000 },
     unexpectedAlertBehaviour: 'ignore',
     version: '83.0.4103.116',
     webStorageEnabled: true,
     'webauthn:virtualAuthenticators': true,
     'webdriver.remote.sessionid': '034ce20513343a06554a87cb14d45ce9' },
  currentTest: [Getter],
  desiredCapabilities: null,
  sessionId: '034ce20513343a06554a87cb14d45ce9',
  .
  .
  .
  

因此,如果我们想要浏览器名称、版本、操作系统名称等信息,请使用以下内容:

console.log(browser.capabilities.platform) //prints... Mac OS X
console.log(browser.capabilities.browserName) //prints.. chrome
console.log(browser.capabilities.version) //prints... 83.0.4103.116
于 2020-07-07T09:03:40.410 回答