selenium-ide icon indicating copy to clipboard operation
selenium-ide copied to clipboard

'selenium-side-runner --output-format=junit' doesn´t work

Open github-developer-01 opened this issue 4 years ago • 10 comments

🐛 Bug Report

--output-format=junit throws an error.

To Reproduce

selenium-side-runner --output-directory=results --output-format=junit testfile.side

Expected behavior

A junit result should be generated in results directory.

Project file reproducing this issue (highly encouraged)

test.zip

Issues without a reproduction project are likely to stall.

Environment

OS: Windows 10 Selenium IDE Version: 3.17.0 Selenium SIDE Runner Version: 3.17.0

Node version: v16.10.0 Only required if using selenium-side-runner

Browser: Chrome 94.0.4606.61 (64-bit) -->

Error:

X:\Program Files\nodejs\node_modules\npm\lib\npm.js:163
      throw new TypeError('callback must be a function if provided')
            ^
TypeError: callback must be a function if provided
    at Object.load (X:\Program Files\nodejs\node_modules\npm\lib\npm.js:163:13)
    at X:\Users\User\Documents\GitHub\simple-keyboard\node_modules\selenium-side-runner\dist\npm.js:23:9
    at new Promise (<anonymous>)
    at install (X:\Users\User\Documents\GitHub\simple-keyboard\node_modules\selenium-side-runner\dist\npm.js:22:10)
    at Object.<anonymous> (X:\Users\User\Documents\GitHub\simple-keyboard\node_modules\selenium-side-runner\dist\npm.js:42:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)

github-developer-01 avatar Sep 27 '21 06:09 github-developer-01

+1 I am also experiencing this

nbeal avatar Oct 15 '21 18:10 nbeal

@nbeal @github-developer-01

I was able to get around this issue by installing npm@latest-6, version 7 seems to be incompatible with the selenium-side-runner.

hyperalexgood avatar Nov 01 '21 02:11 hyperalexgood

@github-developer-01 @nbeal @hyperalexgood - Hey all. So, I am not so good at the side-runner. Is this a capability of the side-runner? It seems outside of its expected use case, which is really just about running ide tests and doing transpiling to jest transparently. Have you folks tried using the side-utils package to do code export to your selected language? I use a manual script like this (some variables are missing to cut out implementation details):

const sideUtils = require("@seleniumhq/side-utils");
const fs = require("fs").promises;
const path = require("path");

const projectProcessor = sideUtils.project;

/**
 * I don't honestly know what this function does, but all of the example Selenium
 * code used it, so here it is.
 * @function normalizeProject
 * @memberof e2e.test-exporter
 */
function normalizeProject(project) {
  let _project = { ...project };
  _project.suites.forEach(suite => {
    projectProcessor.normalizeTestsInSuite({ suite, tests: _project.tests });
  });
  return _project;
}

/**
 * This just takes a project and transpiles it to a list of tests in our end language.
 * It pretty much just wraps the Selenium IDE stuff and just adds a bit of convenience
 * sugar for file reading and writing
 * @function buildProject
 * @memberof e2e.test-exporter
 */
module.exports = async (name, language) => {
  const emitters = require(`<path to your export format>`);
  const extension = emitters.opts.fileExtension;
  const emitSuite = emitters.emit.suite;
  const sideProjectPath = path.join(<path to your project>, `${name}.side`);
  const sideProjectText = await fs.readFile(sideProjectPath);
  const project = normalizeProject(JSON.parse(sideProjectText));
  return await Promise.all(
    project.suites.map(async suite => await writeTests(project, suite, project.tests))
  );
  /**
   * Takes a project, suite, and any amount of tests in that suite and
   * makes it all match up and writes it to a file
   * @memberof e2e.test-exporter
   * @param {*} project
   * @param {*} suite
   * @param {*} tests
   */
  async function writeSuite(project, suite, tests) {
    const results = await emitSuite({
      baseUrl: project.url,
      suite,
      tests,
    });
    let fileName = suite.name
    return await fs.writeFile(
      path.join(featuresPath, `${fileName}${extension}`),
      results.body
    );
  }
};

Honestly, this does seem a bit too complex to expect others to implement. If I'm going to touch this, I'm going to add export utility scripts directly into the side-utils package. I don't believe this should be part of the side-runner, which isn't meant to act as a general case transpiler, but is instead a turnkey wrapper for js bindings from the ide.

It shouldn't be bad, but I'll try and add to the docs here as well, and once this is out, I'll link the docs here so you have a turnkey supported way of doing this going forward.

toddtarsi avatar Nov 18 '21 14:11 toddtarsi

So, in short, this is what I'll do here:

  1. Add a convenience export script to side-utils that takes a read directory, a write directory, and an expected language.
  2. Document the export commands in the side-utils readme.
  3. Update you all here to use said package and command.

toddtarsi avatar Nov 18 '21 14:11 toddtarsi

@toddtarsi I may be dense here, but is what you stated above a solution to use npm v7 or v8 in combination with selenium side runner? I tried upgrading to node.js v 16 and npm v8, but it breaks side runner completely due to npm changing the way the modules are treated. For example, there is no execution file on the node_module folder. So far, side runner can only work with node.js v14 and npm v6.

cford-hub avatar Jan 10 '22 17:01 cford-hub

@cford-hub - It sounds like @hyperalexgood has a nice workaround to use npm@latest-6, which resolves this issue. Can you try using that? I don't actually use the selenium-side-runner package to transpile my tests (although I should).

toddtarsi avatar Jan 10 '22 18:01 toddtarsi

@toddtarsi Yep, that is what I am using currently. I was hoping there was a solution going forward. Nodejs v14 is only supporting security updates through April 2023 and backwards compatibility with node and npm isn't functional with side runner.

cford-hub avatar Jan 10 '22 18:01 cford-hub

@cford-hub - As we get closer to that, I can look at migration. One thing here is that I'm trying to get to selenium-ide v4 being ready to enter beta, which will be a pretty large rewrite that's been a few years coming. My goal is to get to that first, and then to get back to the little things. I know it will be well before April 2023 though, so no worries there.

toddtarsi avatar Jan 10 '22 18:01 toddtarsi

@toddtarsi Thank you!

cford-hub avatar Jan 10 '22 18:01 cford-hub

@toddtarsi @cford-hub does the workaround actually lead to an XML i.s.o. an output in json format? I am using npm 6.14.12 (comes along with node.js 12.22.1) , and not able to create an XML file as output. The command --output-directory --output-format=junit will still lead to a json file.

murat-sahin avatar Jan 31 '22 15:01 murat-sahin

Closing this, not much of a priority right now. In addition, a great workaround is documented here:

https://github.com/SeleniumHQ/selenium-ide/issues/1536

toddtarsi avatar Nov 14 '22 01:11 toddtarsi

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 14 '22 21:12 github-actions[bot]