Hướng dẫn node js generate html report - nút js tạo báo cáo html

Một phóng viên cho WebDriver.io tạo ra báo cáo HTML.Dựa trên WDIO-Spec-Repecer xuất sắc

Cách dễ nhất là giữ wdio-html-format-reporter như một sự phụ thuộc vào gói của bạn.json:

{

  "devDependencies": {

    "wdio-html-format-reporter": "~0.2.7"

  }

}

Mã sau đây hiển thị cấu hình Runner kiểm tra WDIO mặc định.Chỉ cần thêm 'HTML-Format' làm phóng viên khác vào mảng:

module.exports = {

  reporters: ['spec', 'html-format'],

  reporterOptions: {

    htmlFormat: {

      outputDir: './reports/'

    },

  },

  screenshotPath: `./screenShots`,     

};

const assert = require['chai'].assert

const fs = require['fs-extra']

const dateFormat = require['dateFormat']

describe['some example tests for a readme.md demo', [] => {

  describe['should be a passing test', [] => {

    it['check the package still exists on npm', [] => {

      browser.url["//www.npmjs.com/package/wdio-html-format-reporter"]

      const expectedTitle = 'wdio-html-format-reporter'

      assert.equal[browser.element['.package-name'].getText[], expectedTitle, `The page title doesn't equal ${expectedTitle}`]

    }]

    it['should have an installation section', [] => {

      assert.isOk[browser.element['#user-content-installation'].isVisible[]]

    }]

    it['should display an imbedded screenshot that I can zoom in on', [] => {

      browser.saveScreenshot[`${browser.options.screenshotPath}/screenshot-example.png`]

    }]

    it['should display some output I want to log on the report', [] => {

      process.send[{

        event: 'runner:logit',

        output: 'Do. Or do not. There is no try'

      }]

    }]

  }]

  describe['should have a failing test', [] => {

    it['should have an configuration section', [] => {

      assert.isOk[browser.element['#user-content-configuration'].isVisible[]]

    }]

    it['keywords should include "html"', [] => {

      assert.match[browser.element['//h3[text[]="Keywords"]/following-sibling::p[contains[@class, "list-of-links"]]'].getText[], /html/, '"html" is not one of the keywords']

    }]

    it['keywords should include "spec"', [] => {

      assert.match[browser.element['//h3[text[]="Keywords"]/following-sibling::p[contains[@class, "list-of-links"]]'].getText[], /spec/, '"spec" is not one of the keywords']

    }]

    it['keywords should include "wdio"', [] => {

      assert.match[browser.element['//h3[text[]="Keywords"]/following-sibling::p[contains[@class, "list-of-links"]]'].getText[], /wdio/, '"wdio" is not one of the keywords']

    }]

  }]

}]

describe['Full page screenshot', [] => {

  it['should open wateraid.org', [] => {

    browser.url['//www.wateraid.org/']

  }]

  it['should take full page screenshot using wdio-screenshot', [] => {

    process.send[{

      event: 'runner:logit',

      output: 'great plugin for fullscreen screenshots: //www.npmjs.com/package/wdio-screenshot'

    }]

    const timestamp = dateFormat[new Date[], "yyyymmddHHMMss"];

    const filepath = `${browser.options.screenshotPath}/${browser.session[].sessionId}/${timestamp}`

    browser.saveDocumentScreenshot[`${filepath}.png`];

    process.send[{

      event: 'screenshot:fullpage',

      filename: `${filepath}.png`

    }]

  }]

}]

Bài Viết Liên Quan

Chủ Đề