1 | <!DOCTYPE html>
|
2 | <html lang="en">
|
3 | <head>
|
4 | <meta charset="utf-8">
|
5 | <title>JSDoc: Source: Reporter.js</title>
|
6 |
|
7 | <script src="scripts/prettify/prettify.js"> </script>
|
8 | <script src="scripts/prettify/lang-css.js"> </script>
|
9 | |
10 |
|
11 |
|
12 | <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
13 | <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
14 | </head>
|
15 |
|
16 | <body>
|
17 |
|
18 | <div id="main">
|
19 |
|
20 | <h1 class="page-title">Source: Reporter.js</h1>
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | <section>
|
28 | <article>
|
29 | <pre class="prettyprint source linenums"><code>/**
|
30 | * Created by 212556710 on 4/28/16.
|
31 | */
|
32 | module.exports = function JsonOutputHook() {
|
33 | var Cucumber = require('cucumber');
|
34 | var logger = require('./Logger.js');
|
35 | var Promise = require('bluebird');
|
36 | //var RallyHelper = require('./RallyHelper.js');
|
37 | var JsonFormatter = Cucumber.Listener.JsonFormatter();
|
38 | var json_rally = '';
|
39 | var cucumber_json = '';
|
40 | var fs = require('fs');
|
41 | var dir = './Reports/json_report';
|
42 | if (!fs.existsSync(dir)) {
|
43 | fs.mkdirSync(dir);
|
44 | }
|
45 | var special_char_tf = false;//add special char check
|
46 | var special_char_tc = false;
|
47 | var special_char_step = false;
|
48 | var wroteFile = false;
|
49 | var eof = false;
|
50 | var imageCount = 0;
|
51 | this.registerListener(JsonFormatter);
|
52 | JsonFormatter.log = function (jsonold, callback) {
|
53 |
|
54 | // Loops through the provided array to check if the test case has arguements
|
55 | var checkarray = function (array, str_to_check) {
|
56 | var num_times = 0;
|
57 | for (var temp = 0; temp < array.length; temp++) {
|
58 | if (array[temp] == str_to_check) {
|
59 | num_times++;
|
60 | has_arg = true;
|
61 | }
|
62 | if (temp == array.length - 1)
|
63 | return (num_times);
|
64 | }
|
65 | }
|
66 |
|
67 | var RallyJson = JSON.parse(jsonold);
|
68 | var has_arg = false;
|
69 | var duplicate_arg = false;
|
70 |
|
71 | // For loop to go through all the feature files
|
72 | for (var feature = 0; feature < RallyJson.length; feature++) {
|
73 |
|
74 | var feature_name = RallyJson[feature].name;
|
75 | var args = [];
|
76 | // var re = /\(|\)/;
|
77 | // var TFchars = re.test(feature_name);
|
78 |
|
79 | // if (TFchars) {
|
80 | // special_char_tf = true;
|
81 | // console.log('Error in Feature Name');
|
82 | // logger.info('Error in Feature Name');
|
83 | // break;
|
84 | // }
|
85 | // else {
|
86 | // special_char_tf = false;
|
87 | // }
|
88 | for (var scenario = 0; scenario < RallyJson[feature].elements.length; scenario++) {
|
89 | var scenario_name = RallyJson[feature].elements[scenario].name;
|
90 | // var TCspecial_chars = /\(|\)/;
|
91 | // var check_chars = TCspecial_chars.test(scenario_name);
|
92 | // if (check_chars) {
|
93 | // special_char_tc = true;
|
94 | // console.log('Error in Scenario Name');
|
95 | // logger.info('Error in Scenario Name');
|
96 | // break;
|
97 | // } else {
|
98 | // special_char_tc = false;
|
99 | // }
|
100 |
|
101 | // This variable is going to hold the array of user stories
|
102 | var arrUserStory = "";
|
103 | var testCaseNumber = "";
|
104 | var testcaseName = "";
|
105 |
|
106 | //read user story from env file
|
107 | if (process.env.user_story != undefined && process.env.user_story != "") {
|
108 | arrUserStory = process.env.user_story;
|
109 | arrUserStory = arrUserStory.match(/US[0-9]+/g);
|
110 | }
|
111 |
|
112 | //read user story from feature file
|
113 | var checkUserStory = scenario_name.split(":");
|
114 | if (process.env.overwrite_US == "false" || process.env.overwrite_US == undefined) {
|
115 |
|
116 | if (checkUserStory.length == 2) {
|
117 | if (checkUserStory[0].match(/US[0-9]+/g)) {
|
118 | arrUserStory = checkUserStory[0];
|
119 | arrUserStory = arrUserStory.match(/US[0-9]+/g);
|
120 | }
|
121 | else {
|
122 | testCaseNumber = checkUserStory[0];
|
123 | }
|
124 | testcaseName = checkUserStory[1]
|
125 | }
|
126 | // Checking to see if TC number is defined here. Then grabs the right index for the split array to get the user story
|
127 | else if (checkUserStory.length == 3) {
|
128 | if (checkUserStory[0].match(/US[0-9]+/)) {
|
129 | arrUserStory = checkUserStory[0];
|
130 | testCaseNumber = checkUserStory[1]
|
131 | }
|
132 | else {
|
133 | testCaseNumber = checkUserStory[0]
|
134 | arrUserStory = checkUserStory[1];
|
135 | }
|
136 | arrUserStory = arrUserStory.match(/US[0-9]+/g);
|
137 | testcaseName = checkUserStory[2]
|
138 | }
|
139 | else {
|
140 | testcaseName = checkUserStory[0]
|
141 | }
|
142 | }
|
143 |
|
144 | // If env overwrite US is set to true but we still need to get the test case number if there is one
|
145 | else {
|
146 | if (checkUserStory.length == 2) {
|
147 | if (!checkUserStory[0].match(/US[0-9]+/g)) {
|
148 | testCaseNumber = checkUserStory[0];
|
149 | }
|
150 | testcaseName = checkUserStory[1]
|
151 | }
|
152 | // Checking to see if TC number is defined here. Then grabs the right index for the split array to get the user story
|
153 | else if (checkUserStory.length == 3) {
|
154 | if (checkUserStory[0].match(/US[0-9]+/)) {
|
155 | testCaseNumber = checkUserStory[1]
|
156 | }
|
157 | else {
|
158 | testCaseNumber = checkUserStory[0]
|
159 | }
|
160 | testcaseName = checkUserStory[2]
|
161 | }
|
162 | else {
|
163 | testcaseName = checkUserStory[0]
|
164 | }
|
165 | }
|
166 |
|
167 |
|
168 | // This is to replace the scenario name with the correct userstory whether it got it from the env or feature file
|
169 |
|
170 | if (arrUserStory != "")
|
171 | var userStoryString = arrUserStory.join(",");
|
172 |
|
173 | if (testCaseNumber != "") {
|
174 | if (userStoryString == undefined && testCaseNumber != undefined) {
|
175 | userStoryString = testCaseNumber;
|
176 | }
|
177 | else {
|
178 | userStoryString += ":" + testCaseNumber;
|
179 | }
|
180 | }
|
181 |
|
182 | if (checkUserStory.length > 1 && (process.env.overwrite_US == "false" || process.env.overwrite_US == undefined)) {
|
183 | RallyJson[feature].elements[scenario].name = userStoryString + ":" + testcaseName;;
|
184 | } else if (userStoryString != "" && userStoryString!=undefined) {
|
185 | RallyJson[feature].elements[scenario].name = userStoryString+":"+testcaseName;
|
186 | }
|
187 | else {
|
188 | RallyJson[feature].elements[scenario].name = checkUserStory[0];
|
189 | }
|
190 | //if there are multiple user story.
|
191 | if (arrUserStory != null && arrUserStory.length > 1) {
|
192 | var name = RallyJson[feature].elements[scenario].name;
|
193 | RallyJson[feature].elements[scenario].name = checkUserStory[0].replace(/(,(\s*)?US[0-9]+)+/g, "") + ":" + checkUserStory[1] + "_US_1";
|
194 | scenario_name = RallyJson[feature].elements[scenario].name;
|
195 | for (var i = 1; i < arrUserStory.length; i++) {
|
196 | var temp_element = JSON.parse(JSON.stringify(RallyJson[feature].elements[scenario]));
|
197 | var temp_element_userstory = temp_element.name.split(":")[0].replace(/US[0-9]+/g, arrUserStory[i])
|
198 | temp_element.name = temp_element_userstory + ":" + temp_element.name.split(":")[1].substring(0, temp_element.name.split(":")[1].length - 2) + "_" + (i + 1);
|
199 | RallyJson[feature].elements.push(temp_element);
|
200 | }
|
201 | }
|
202 |
|
203 |
|
204 | for (var step = 0; step < RallyJson[feature].elements[scenario].steps.length; step++) {
|
205 | if (RallyJson[feature].elements[scenario].steps[step].name != undefined) {
|
206 | var name = RallyJson[feature].elements[scenario].steps[step].name;
|
207 | // var stepSPChar = /\(|\)/;
|
208 | // var check_StepChars = stepSPChar.test(name);
|
209 | // if (check_StepChars) {
|
210 | // special_char_step = true;
|
211 | // console.log('Error in step declaration');
|
212 | // logger.info('Error in step declaration');
|
213 | // break;
|
214 | // } else {
|
215 | // special_char_step = false;
|
216 | // }
|
217 | var reg_exp = new RegExp('\".+?\"');
|
218 | var arg = reg_exp.exec(name);
|
219 | if (arg != undefined) {
|
220 | has_arg = true;
|
221 | if (args.length > 0) {
|
222 | var retrned = checkarray(args, arg[0]);
|
223 | if (retrned > 0) {
|
224 | duplicate_arg = true;
|
225 | RallyJson[feature].elements[scenario].name = scenario_name + ' ' + arg[0] + ' ' + retrned;
|
226 | RallyJson[feature].elements[scenario].name = RallyJson[feature].elements[scenario].name.split('"').join('');
|
227 |
|
228 | } else {
|
229 | RallyJson[feature].elements[scenario].name = scenario_name + ' ' + arg[0];
|
230 | RallyJson[feature].elements[scenario].name = RallyJson[feature].elements[scenario].name.split('"').join('');
|
231 |
|
232 | }
|
233 | }
|
234 | args.push(arg[0]);
|
235 | } else if (step == RallyJson[feature].elements[scenario].steps.length - 2) {
|
236 | has_arg = false;
|
237 | break;
|
238 | }
|
239 | } else if (step == RallyJson[feature].elements[scenario].steps.length - 2) {
|
240 | has_arg = false;
|
241 | break;
|
242 | }
|
243 | }
|
244 | if (special_char_step)
|
245 | break;
|
246 | if ((scenario == RallyJson[feature].elements.length - 1) && (feature == RallyJson.length - 1)) {
|
247 | json_rally = JSON.stringify(RallyJson, null, "\t");
|
248 | cucumber_json = jsonold;
|
249 | }
|
250 | }
|
251 | if (special_char_tc || special_char_step || wroteFile) {
|
252 | break;
|
253 | }
|
254 | }
|
255 | };
|
256 |
|
257 | this.After(function (scenario, callback) {
|
258 | console.log('after scenario');
|
259 | if (scenario.isFailed()) {
|
260 | Logger.info("Results: Failed");
|
261 | browser.takeScreenshot().then(function (png) {
|
262 | imageCount += 1;
|
263 | var decodedImage = new Buffer(png, "base64").toString("binary");
|
264 | fs.writeFile("Reports/image" + imageCount + ".png", decodedImage, 'binary', function (err) {
|
265 | scenario.attach(decodedImage, "image/png");
|
266 | console.log("Attached");
|
267 | callback()
|
268 | })
|
269 | });
|
270 | } else {
|
271 | Logger.info("Results: Passed");
|
272 | callback();
|
273 | }
|
274 | });
|
275 |
|
276 | this.registerHandler('BeforeScenario', function (event, callback) {
|
277 | var scenario = event.getPayloadItem('scenario');
|
278 | Logger.info("|--------------------------------------------------------|");
|
279 | Logger.info("Test " + scenario.getName() + " has started");
|
280 | Logger.info("|--------------------------------------------------------|\r\n");
|
281 | callback();
|
282 | });
|
283 |
|
284 | this.registerHandler('AfterScenario', function (event, callback) {
|
285 | var scenario = event.getPayloadItem('scenario');
|
286 | Logger.info("|--------------------------------------------------------|");
|
287 | Logger.info("Test " + scenario.getName() + " has ended");
|
288 | Logger.info("|--------------------------------------------------------|\r\n\r\n");
|
289 | callback();
|
290 | });
|
291 |
|
292 | this.registerHandler('AfterFeatures', function (features, callback) {
|
293 | if (json_rally == '') {
|
294 | //spin for loop until json rally finished
|
295 | var date = new Date();
|
296 | while (new Date() - date < 1500) {
|
297 | //spin for 1.5 sec
|
298 | }
|
299 | }
|
300 | fs.writeFile('Reports/json_report/rally.json', json_rally, function (err) {
|
301 | if (err) console.log(err);
|
302 | else {
|
303 | //fs.writeFile('Reports/json_report/cucumber.json', cucumber_json, function (err) {
|
304 | // if (err) console.log(err);
|
305 | var Rally = require('./Rally.js');
|
306 | if ((!special_char_tf) && (!special_char_tc) && (!special_char_step)) {
|
307 | Rally.RallyWebAPI('../../../Reports/json_report/rally.json', function () {
|
308 | wroteFile = true;
|
309 | callback();
|
310 | });
|
311 | } else {
|
312 | console.log('The following characters are not supported in postToRally:' +
|
313 | ' "(" and ")" - please check your feature file');
|
314 | logger.info('The following characters are not supported in postToRally:' +
|
315 | ' "(" and ")" - please check your feature file');
|
316 | callback();
|
317 | }
|
318 | //});
|
319 | }
|
320 | });
|
321 | });
|
322 | };</code></pre>
|
323 | </article>
|
324 | </section>
|
325 |
|
326 |
|
327 |
|
328 |
|
329 | </div>
|
330 |
|
331 | <nav>
|
332 | <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="HighChart.html">HighChart</a></li><li><a href="PxDataTable.html">PxDataTable</a></li><li><a href="RestHelper.html">RestHelper</a></li><li><a href="TestHelper.html">TestHelper</a></li></ul><h3>Global</h3><ul><li><a href="global.html#acceptAlert">acceptAlert</a></li><li><a href="global.html#alertIsPresent">alertIsPresent</a></li><li><a href="global.html#assertEqual">assertEqual</a></li><li><a href="global.html#assertInclude">assertInclude</a></li><li><a href="global.html#assertTrue">assertTrue</a></li><li><a href="global.html#clearFilter">clearFilter</a></li><li><a href="global.html#compareData">compareData</a></li><li><a href="global.html#createTestcase">createTestcase</a></li><li><a href="global.html#createTestcaseResult">createTestcaseResult</a></li><li><a href="global.html#createTestPlan">createTestPlan</a></li><li><a href="global.html#dismissAlert">dismissAlert</a></li><li><a href="global.html#dragAndDrop">dragAndDrop</a></li><li><a href="global.html#dragAndDrop2">dragAndDrop2</a></li><li><a href="global.html#elementToBeClickable">elementToBeClickable</a></li><li><a href="global.html#elementToBeSelected">elementToBeSelected</a></li><li><a href="global.html#executeDeleteRequest">executeDeleteRequest</a></li><li><a href="global.html#executeGetRequest">executeGetRequest</a></li><li><a href="global.html#executePatchRequest">executePatchRequest</a></li><li><a href="global.html#executePostRequest">executePostRequest</a></li><li><a href="global.html#executePutRequest">executePutRequest</a></li><li><a href="global.html#geSSOLogin">geSSOLogin</a></li><li><a href="global.html#getAccessToken">getAccessToken</a></li><li><a href="global.html#getAttribute">getAttribute</a></li><li><a href="global.html#getAxisLabels">getAxisLabels</a></li><li><a href="global.html#getAxisText">getAxisText</a></li><li><a href="global.html#getAxisTextByIndex">getAxisTextByIndex</a></li><li><a href="global.html#getBMChartData">getBMChartData</a></li><li><a href="global.html#getCellElement">getCellElement</a></li><li><a href="global.html#getCellElements">getCellElements</a></li><li><a href="global.html#getCellElementText">getCellElementText</a></li><li><a href="global.html#getCellHtml">getCellHtml</a></li><li><a href="global.html#getCellText">getCellText</a></li><li><a href="global.html#getChartData">getChartData</a></li><li><a href="global.html#getColumnCount">getColumnCount</a></li><li><a href="global.html#getColumnElementValues">getColumnElementValues</a></li><li><a href="global.html#getColumnHeaderElements">getColumnHeaderElements</a></li><li><a href="global.html#getColumnHtmlValues">getColumnHtmlValues</a></li><li><a href="global.html#getColumnindex">getColumnindex</a></li><li><a href="global.html#getColumnNames">getColumnNames</a></li><li><a href="global.html#getColumnTextValues">getColumnTextValues</a></li><li><a href="global.html#getContainer">getContainer</a></li><li><a href="global.html#getCssValue">getCssValue</a></li><li><a href="global.html#getCurrentPage">getCurrentPage</a></li><li><a href="global.html#getElementManager">getElementManager</a></li><li><a href="global.html#getFilter">getFilter</a></li><li><a href="global.html#getLegendsFromSection">getLegendsFromSection</a></li><li><a href="global.html#getObjectRef">getObjectRef</a></li><li><a href="global.html#getOOChartData">getOOChartData</a></li><li><a href="global.html#getRandomString">getRandomString</a></li><li><a href="global.html#getRowCount">getRowCount</a></li><li><a href="global.html#getRowElementValues">getRowElementValues</a></li><li><a href="global.html#getRowHtmlValues">getRowHtmlValues</a></li><li><a href="global.html#getRowPerPageValue">getRowPerPageValue</a></li><li><a href="global.html#getRowTextValues">getRowTextValues</a></li><li><a href="global.html#getSVG">getSVG</a></li><li><a href="global.html#getText">getText</a></li><li><a href="global.html#getTooltipInfo">getTooltipInfo</a></li><li><a href="global.html#getUSTSRef">getUSTSRef</a></li><li><a href="global.html#getXaxisLabels">getXaxisLabels</a></li><li><a href="global.html#getXaxisText">getXaxisText</a></li><li><a href="global.html#getYaxisLabels">getYaxisLabels</a></li><li><a href="global.html#getYaxisText">getYaxisText</a></li><li><a href="global.html#goToNextPage">goToNextPage</a></li><li><a href="global.html#goToPage">goToPage</a></li><li><a href="global.html#goToPreviousPage">goToPreviousPage</a></li><li><a href="global.html#iFrameSwitch">iFrameSwitch</a></li><li><a href="global.html#initialize">initialize</a></li><li><a href="global.html#isChartDisplayed">isChartDisplayed</a></li><li><a href="global.html#isElementNotPresent">isElementNotPresent</a></li><li><a href="global.html#isElementPresent">isElementPresent</a></li><li><a href="global.html#isElementVisible">isElementVisible</a></li><li><a href="global.html#name">name</a></li><li><a href="global.html#noTestCaseFound">noTestCaseFound</a></li><li><a href="global.html#noTestFolderFound">noTestFolderFound</a></li><li><a href="global.html#onPageLoad">onPageLoad</a></li><li><a href="global.html#onPageStable">onPageStable</a></li><li><a href="global.html#postResults">postResults</a></li><li><a href="global.html#postTest">postTest</a></li><li><a href="global.html#scrollIntoView">scrollIntoView</a></li><li><a href="global.html#sendKeys">sendKeys</a></li><li><a href="global.html#setChartElements">setChartElements</a></li><li><a href="global.html#setContainer">setContainer</a></li><li><a href="global.html#setContianer">setContianer</a></li><li><a href="global.html#setElementManager">setElementManager</a></li><li><a href="global.html#setFilter">setFilter</a></li><li><a href="global.html#setRowPerPageValue">setRowPerPageValue</a></li><li><a href="global.html#setSVG">setSVG</a></li><li><a href="global.html#setup">setup</a></li><li><a href="global.html#skipAngularStability">skipAngularStability</a></li><li><a href="global.html#sortColumn">sortColumn</a></li><li><a href="global.html#teardown">teardown</a></li><li><a href="global.html#TestCaseFound">TestCaseFound</a></li><li><a href="global.html#TestCaseResult">TestCaseResult</a></li><li><a href="global.html#TestFolderFound">TestFolderFound</a></li><li><a href="global.html#textToBePresentInElement">textToBePresentInElement</a></li><li><a href="global.html#textToBePresentInElementValue">textToBePresentInElementValue</a></li><li><a href="global.html#titleContains">titleContains</a></li><li><a href="global.html#titleIs">titleIs</a></li><li><a href="global.html#updateTestCase">updateTestCase</a></li><li><a href="global.html#updateTestCaseResult">updateTestCaseResult</a></li><li><a href="global.html#updateTestSet">updateTestSet</a></li><li><a href="global.html#uploadFile">uploadFile</a></li><li><a href="global.html#UserPermissions">UserPermissions</a></li><li><a href="global.html#waitForAngular">waitForAngular</a></li><li><a href="global.html#waitForCondition">waitForCondition</a></li><li><a href="global.html#waitForElementToDisappear">waitForElementToDisappear</a></li><li><a href="global.html#waitForPromise">waitForPromise</a></li><li><a href="global.html#winston">winston</a></li></ul>
|
333 | </nav>
|
334 |
|
335 | <br class="clear">
|
336 |
|
337 | <footer>
|
338 | Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.1</a> on Mon Oct 30 2017 11:31:46 GMT-0700 (PDT)
|
339 | </footer>
|
340 |
|
341 | <script> prettyPrint(); </script>
|
342 | <script src="scripts/linenumber.js"> </script>
|
343 | </body>
|
344 | </html>
|