@bucky24/jsbehave 0.12.5 → 0.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +30 -9
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -41,15 +41,26 @@ const variables = {
|
|
|
41
41
|
"screenshotDirectory": ".",
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
let allTests = {};
|
|
45
|
+
let allActions = {};
|
|
46
|
+
let beforeAll = [];
|
|
47
|
+
let beforeEach = [];
|
|
48
|
+
let afterAll = [];
|
|
49
|
+
let afterEach = [];
|
|
50
50
|
let customSelectors = {};
|
|
51
51
|
let customOperations = {};
|
|
52
52
|
|
|
53
|
+
function reset() {
|
|
54
|
+
allTests = {};
|
|
55
|
+
allActions = {};
|
|
56
|
+
beforeAll = [];
|
|
57
|
+
beforeEach = [];
|
|
58
|
+
afterAll = [];
|
|
59
|
+
afterEach = [];
|
|
60
|
+
customSelectors = {};
|
|
61
|
+
customOperations = {};
|
|
62
|
+
}
|
|
63
|
+
|
|
53
64
|
function getVariable(name) {
|
|
54
65
|
if (name === 'clipboard') {
|
|
55
66
|
return clipboardy.readSync();
|
|
@@ -401,6 +412,7 @@ async function compareContent([ selector, text ]) {
|
|
|
401
412
|
|
|
402
413
|
function doSetVariable([ key, input ]) {
|
|
403
414
|
const finalInput = getText(input);
|
|
415
|
+
console.log(`Setting variable ${key} to ${finalInput}`);
|
|
404
416
|
setVariable(key, finalInput);
|
|
405
417
|
}
|
|
406
418
|
|
|
@@ -432,7 +444,12 @@ async function clickElementWithOffset([ selector, x, y ]) {
|
|
|
432
444
|
|
|
433
445
|
async function takeScreenshot(test) {
|
|
434
446
|
const activeBrowser = getVariable("jsbehave.active_driver");
|
|
435
|
-
const
|
|
447
|
+
const activeDriver = await driver();
|
|
448
|
+
if (!activeDriver) {
|
|
449
|
+
// don't throw, we get here when an error happens so we're already handling a problem
|
|
450
|
+
console.error(`Unable to take screenshot - driver does not exist`);
|
|
451
|
+
}
|
|
452
|
+
const image = activeDriver.takeScreenshot();
|
|
436
453
|
const useTest = test.replace(/ /g, "_");
|
|
437
454
|
let configPath = getVariable("screenshotDirectory");
|
|
438
455
|
const fileName = `test_${useTest}_failure_${activeBrowser}.png`;
|
|
@@ -516,7 +533,8 @@ const operations = {
|
|
|
516
533
|
};
|
|
517
534
|
|
|
518
535
|
async function handleLines(lines) {
|
|
519
|
-
for (let
|
|
536
|
+
for (let i=0;i<lines.length;i++) {
|
|
537
|
+
const line = lines[i];
|
|
520
538
|
if (line === "") {
|
|
521
539
|
continue;
|
|
522
540
|
}
|
|
@@ -554,7 +572,7 @@ async function handleLines(lines) {
|
|
|
554
572
|
const test = variables["jsbehave.activeBlock"];
|
|
555
573
|
if (test) {
|
|
556
574
|
console.log(`Test ${test} - FAILURE`);
|
|
557
|
-
console.log(`
|
|
575
|
+
console.log(`Failed on line ${i+1}: "${line}" for "${operation}"`);
|
|
558
576
|
console.log(error);
|
|
559
577
|
const screenshotOnFailure = getVariable("screenshotOnFailure") === 'true';
|
|
560
578
|
if (screenshotOnFailure) {
|
|
@@ -582,6 +600,9 @@ async function handleLines(lines) {
|
|
|
582
600
|
const contents = fs.readFileSync(fileName, "utf-8");
|
|
583
601
|
const lines = contents.split(EOL);
|
|
584
602
|
|
|
603
|
+
// reset the test framework
|
|
604
|
+
reset();
|
|
605
|
+
|
|
585
606
|
console.log(`Processing ${fileName}`);
|
|
586
607
|
|
|
587
608
|
// first pass, consolidate all the code into test blocks
|