enter image description here

Dari gambar di atas dapat dilihat bahwa ketika kita mulai menjalankan nightwatch, di konsol kita dapat melihat nama browser, versi dan nama serta versi OS.

Apakah ada cara untuk mendapatkan nilai versi dan digunakan dalam kode seperti yang kami gunakan untuk mendapatkan platform sebagai

process.platform=win32 or darwin
0
Govind 6 Juli 2020, 12:04

1 menjawab

Jawaban Terbaik

Saya mendapat jawaban dari 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',
  .
  .
  .
  

Jadi jika kita menginginkan sesuatu seperti nama browser, versi, nama OS, dll gunakan di bawah ini:

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
0
Govind 7 Juli 2020, 09:03