adamgruber / mochawesome

A Gorgeous HTML/CSS Reporter for Mocha.js

Home Page:https://gitter.im/mochawesome/general

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mochawesome not refreshing the tests

adrian-badulescu opened this issue · comments

Describe the bug
I have an issue in refreshing the html and json files from Mochawesome, the setup is with Selenium/NodeJs.
The test are not updated in mochawesome after I change the code in tests.js file - the entry point test file

packaje.json file:
"test": "mocha tests.js --reporter mochawesome && concurrently "http-server -a localhost -p 3000" "opener http://localhost:3000/mochawesome-report/mochawesome.html"" - start the tests with mocha, passing the tests to the mochawesome reporter, starting a web server on port 3000 and opening the generated html file with opener package in the default browser.

{
  "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 file

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() });
});

Code Reproduce
Link to repo where the issue can reliably be reproduced:

Expected behavior
html and json output files to be replaced everytime the test is run

Screenshots
one test pass and one fails as expected - in mocha
image
both test are passed from an old setup - in mochawesome
image

Environment (please complete the following information):

  • Windows 10
  • mochawesome version ^6.2.2
  • mocha (or other test library) version ^8.4.0
  • Node version v12.18.3
  • "concurrently": "^6.2.0"
  • "http-server": "^0.12.3"
  • "opener": "^1.5.2"
  • "selenium-webdriver": "^4.0.0-beta.1"

Additional context

Hi @adrian-badulescu ,

I have noticed that you run your tests only once right before service reports via HTTP.

mocha tests.js --reporter mochawesome && concurrently "http-server ...

If you want to re-run the tests when you have change the tests, you could try to use nodemon.

npx nodemon -e .js -x 'mocha tests.js --reporter mochawesome' || concurrently  ...