0

我在从 Mochawesome 刷新 html 和 json 文件时遇到问题 设置是使用 Selenium/NodeJs

欢迎任何想法!

packaje.json 文件: 解释行(“test”:“mocha tests.js --reporter mochawesome && concurrently”http-server -a localhost -p 3000““opener http://localhost:3000/mochawesome-report/mochawesome. html"") - 使用 mocha 启动测试,将测试传递给 mochawesome 报告器,在端口 3000 上启动 Web 服务器,并在默认浏览器中使用 opener 包打开生成的 html 文件。

{
  "name": "selenium_test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "mocha tests.js --reporter mochawesome && concurrently \"http-server -a localhost -p 3000\" \"opener http://localhost:3000/mochawesome-report/mochawesome.html\""
  },
  "author": "Adrian Badulescu",
  "license": "MIT",
  "dependencies": {
    "chai": "^4.3.4",
    "concurrently": "^6.2.0",
    "http-server": "^0.12.3",
    "mocha": "^8.4.0",
    "mochawesome": "^6.2.2",
    "opener": "^1.5.2",
    "selenium-webdriver": "^4.0.0-beta.1"
  }
}

tests.js 文件: 我有 2 个测试,一个通过,一个失败 - 在 CLI 中我可以看到预期的测试结果是正确的

摩卡 CLI 结果

const { Builder, By, Key, until, Options, Actions, } = require('selenium-webdriver');
const assert = require('chai').assert;
const { guidEmail, randomString, randomNo, randomFloor, randomAlphaNumeric, T, sleep, randomBuildingLevels, randomResistanceStructure, randomConstructionYear, randomRange, generateCNP, randomCounty, randomDate, randomExpiringCIDate, tomorrowDateRomanianFormat, randomArrayItem, constants } = require('./utils');
const { randomItemJob, randomItemCounty, randomItemActivityDomain, randomActivityDomain } = require('./randomClasses');
const chrome = require('selenium-webdriver/chrome');
const { configLogin, randomStruct, randomCurrencyArray, randomPaymentFreqArray, floors, randomLevels, counties } = require('./constants');

describe('Just some random tests suite', function () {
  // const { siaMock_Link, siaMockEmailAddress, siaMockUsername, siaMock_ST_Password, siaMock_UAT_Password, ST_Link, UAT_Link } = new constants();
  const { siaMock_Link, siaMockEmailAddress, siaMockUsername, siaMock_ST_Password, siaMock_UAT_Password, ST_Link, UAT_Link } = new configLogin();
  var randomEmail = guidEmail()
  // instance random Occupation/Job
  const { pageJob, itemJob } = new randomItemJob();
  // instance random randomItemActivityDomain
  const { itemActivityDomain } = new randomActivityDomain();
  // instance tomorrow date
  const { tomorrow } = new tomorrowDateRomanianFormat();
  this.timeout(45000)
  before(async function () {

    driver = await new Builder().forBrowser('chrome').build();
  });

  it('Test if password exists', async function () {
    await driver.get(`${siaMock_Link}`);
    await driver.findElement(By.id('username')).sendKeys(`${siaMockUsername}`);    
    let pass = await driver.findElement(By.id('password'))
    await sleep(500)
    await assert.exists(pass);
    await pass.sendKeys(`${siaMock_ST_Password}`)
  });



  it('This test should fail', async function () {
    await false.should.be.true
  });



  after(async function () { await driver.quit(); process.exit() });
});

但是 mochawesome 并不令人耳目一新,而是向我展示了一个不变的旧结果

令人敬畏的结果

4

0 回答 0