Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

protractor-junit-xml-plugin

Package Overview
Dependencies
Maintainers
8
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protractor-junit-xml-plugin - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

137

index.js
'use strict'
const os = require('os'),
path = require('path'),
fs = require('fs'),
builder = require('xmlbuilder'),
parseStringSync = require('xml2js-parser').parseStringSync,
JUNITXMLPLUGIN = 'JUnitXrayPlugin: ';
path = require('path'),
fs = require('fs'),
builder = require('xmlbuilder'),
parseStringSync = require('xml2js-parser').parseStringSync;
let outputFile,
OUTDIR_FINAL,
xml,
suites,
testCount,
failCount,
currentCapabilities;
let JUnitXmlPlugin = function () {}
let JUNITXMLPLUGIN = 'JUnitXrayPlugin: ',
OUTDIR_FINAL,
currentBrowser,
outputFile,
pluginConfig,
xml,
suites,
testCount,
failCount,
currCapabilities;
let JUnitXmlPlugin = function () { }
let getBrowserId = async () => {
if (!currentCapabilities) {
currentCapabilities = await browser.getCapabilities();
if (!currCapabilities) {
currCapabilities = await currentBrowser.getCapabilities();
}
return currentCapabilities.get('webdriver.remote.sessionid');
return currCapabilities.get('webdriver.remote.sessionid');
}

@@ -28,4 +30,4 @@

let timestamp = (new Date()).toISOString().substr(0, 19);
let name = currentCapabilities.get('browserName') + ' ' + currentCapabilities.get('browserVersion');
suites[getBrowserId()] = xml.ele('testsuite', {
let name = currCapabilities.get('browserName') + ' ' + currCapabilities.get('browserVersion');
suites[await getBrowserId()] = xml.ele('testsuite', {
name: name, timestamp: timestamp, id: 0, hostname: os.hostname()

@@ -37,3 +39,3 @@ });

// let OUTDIR_FINAL = ''
if(uniqueFolder){
if (uniqueFolder) {
OUTDIR_FINAL = (givenDir || '_test-reports/e2e-test-results') + '/browser-based-results_' + givenTimestamp;

@@ -43,7 +45,7 @@ } else {

}
const FILE_NAME = currentCapabilities.get('browserName') + '-' + (givenFileName || 'test-results.xml')
const FILE_NAME = currCapabilities.get('browserName') + '-' + (givenFileName || 'test-results.xml')
if (!fs.existsSync(OUTDIR_FINAL)) {
console.info('CREATING DIR + ' + OUTDIR_FINAL);
fs.mkdir(OUTDIR_FINAL, { recursive: true }, function(){});
console.info(JUNITXMLPLUGIN + 'CREATING DIR + ' + OUTDIR_FINAL);
fs.mkdir(OUTDIR_FINAL, { recursive: true }, function () { });
}

@@ -89,3 +91,3 @@

addAttr(failure.$, failureFinal);
testcaseFinal.failure.push(failureFinal);

@@ -107,3 +109,3 @@ });

let tags = name.split(':', 3);
if (tags.length > 1) {

@@ -117,3 +119,3 @@ finalObj.xrayId = tags[1];

} else {
finalObj.name = name;
finalObj.name = name;
}

@@ -123,11 +125,33 @@

}
const addSapphireWebAppConfigProperties = async (envProperties) => {
let sapphireWebAppConfig = await currentBrowser.executeScript('return sapphireWebAppConfig');
console.debug('sapphireWebAppConfig: ' + JSON.stringify(sapphireWebAppConfig))
const requiredKeys = ['environment', 'appName', 'appVersion',
'isNewRelicEnabled', 'careOrchestratorVersion', 'careOrchestratorBuildNumber',
'careOrchestratorLastBuildDate', 'gatewayUrl']
requiredKeys.forEach((item) => (envProperties[item] = sapphireWebAppConfig[item]));
if(sapphireWebAppConfig.packagedDeps) {
envProperties.pr_care_orchestrator_version = sapphireWebAppConfig.packagedDeps['pr.care-orchestrator'];
}
// Get toggles and add them in metadata
const TOGGLE_PREFIX = 'TOGGLES_'
for(let toggle in sapphireWebAppConfig.TOGGLES) {
envProperties[TOGGLE_PREFIX + toggle] = sapphireWebAppConfig.TOGGLES[toggle];
}
}
JUnitXmlPlugin.prototype.onPrepare = async function () {
var pluginConfig = this.config;
if(pluginConfig.uniqueName && pluginConfig.appendToFile || pluginConfig.uniqueFolder && pluginConfig.appendToFile) {
if (browser) {
currentBrowser = browser;
}
if (!pluginConfig) {
pluginConfig = this.config;
}
if (pluginConfig.uniqueName && pluginConfig.appendToFile || pluginConfig.uniqueFolder && pluginConfig.appendToFile) {
throw new Error('You can not have a unique name or folder every time as well as appending results to the same file')
}
currentCapabilities = await browser.getCapabilities();
currCapabilities = await currentBrowser.getCapabilities();
//use uniqueName
if (pluginConfig.uniqueName === false){
if (pluginConfig.uniqueName === false) {
outputFile = resolveCompleteFileName(pluginConfig.fileName, pluginConfig.outdir, pluginConfig.uniqueFolder, pluginConfig.timeTillMinuteStamp);

@@ -142,3 +166,3 @@ } else {

if (fs.existsSync(outputFile) && pluginConfig.appendToFile) {
console.debug('Found existing outputFile and using it for ' + currentCapabilities.get('browserName'));
console.debug('Found existing outputFile and using it for ' + currCapabilities.get('browserName'));

@@ -156,3 +180,6 @@ xml = builder.create(getJsonInXmlBuilderExpectedFormat(outputFile));

JUnitXmlPlugin.prototype.postTest = async function (passed, result) {
let pluginConfig = this.config;
if (!pluginConfig) {
pluginConfig = this.config;
console.log('HAMAHAHA: ERROR HERE ')
}

@@ -162,3 +189,3 @@ let testInfo = findXrayIdAndName(result.name, pluginConfig.parseXrayId);

if (pluginConfig.xrayIdOnlyTests) {
if (!testInfo.xrayId) return;
if (!testInfo.xrayId) return;
console.debug('XRAY id tag: ' + testInfo.xrayId);

@@ -178,3 +205,3 @@ }

let spec = suites[getBrowserId()].ele('testcase', testcase);
let spec = suites[await getBrowserId()].ele('testcase', testcase);

@@ -188,8 +215,10 @@ if (!passed) {

JUnitXmlPlugin.prototype.teardown = async function () {
let pluginConfig = this.config;
let vcsVersion = ' ';
let summary = 'Protractor UI e2e tests against ' + browser.baseUrl;
// console.debug('summary: ' + summary);
if (pluginConfig.uniqueName === false){
if (!pluginConfig) {
pluginConfig = this.config;
}
let suite = suites[await getBrowserId()];
// resolving path and creating dir if it doesn't exist
if (pluginConfig.uniqueName === false) {
outputFile = resolveCompleteFileName(pluginConfig.fileName, pluginConfig.outdir, pluginConfig.uniqueFolder, pluginConfig.timeTillMinuteStamp);

@@ -200,18 +229,18 @@ } else {

if(pluginConfig.useSapphireVCSBuildNumber) {
vcsVersion = await browser.executeScript('return sapphireWebAppConfig.appVersion');
console.log('VCSVersion: ' + vcsVersion)
}
let metaDataContents = {
buildNumber: vcsVersion,
summary: summary
jiraProjectKey: pluginConfig.jiraProjectKey,
envProperties: {}
}
if (pluginConfig.captureSapphireWebAppContextVar) {
// add sapphireWebAppConfig app object properties
await addSapphireWebAppConfigProperties(metaDataContents.envProperties);
}
fs.writeFileSync(OUTDIR_FINAL + "/metadata.json", JSON.stringify(metaDataContents), function (err) {
if (err) {
console.warn('Cannot write metadata file\n\t' + err.message);
} else {
console.debug('Metadata file results written to metadata.json');
}});
let suite = suites[getBrowserId()];
if (err) {
console.warn('Cannot write metadata file\n\t' + err.message);
} else {
console.debug('Metadata file results written to metadata.json');
}
});

@@ -218,0 +247,0 @@ suite.att('tests', testCount);

{
"name": "protractor-junit-xml-plugin",
"version": "1.1.2",
"version": "1.2.0",
"description": "A Protracotor plugin. Report results in junit xml format including requirement ids if available.",

@@ -34,8 +34,10 @@ "main": "index.js",

"devDependencies": {
"chai": "^3.5.0",
"express": "^4.17.1",
"chai": "^3.5.0",
"jasmine-spec-reporter": "^4.2.1",
"mocha": "^3.2.0"
"mocha": "^3.2.0",
"rewire": "^4.0.1",
"sinon": "^8.0.4"
},
"contributors": []
}

@@ -48,15 +48,6 @@ # protractor-junit-xml-plugin

useSapphireVCSBuildNumber: If set to true, this value will look for the sapphire vcs build number from the application and use it in the metadata file
captureSapphireWebAppContextVar(Default is false): If set to true, it will look for a global object `sapphireWebAppConfig` in the app and capture the properties like appName, appVersion etc from it to a metadata file that this plugin will generate for each run(in addition to testresults xml file). The idea is to capture all the runtime info related to the test results.
```
The following are the configureable params
```
metadataFile.buildNumber: This is an optional value that can be set. If set it will create a Metadata.properties file in the test directory that will contain this and the summary value.
metadataFile.summary: This is an optional value that can be set. If buildNumber is set, this value is placed in the created Metadata.properties file.
```
## Usage

@@ -63,0 +54,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc