@bucky24/jsbehave 0.10.1 → 0.11.0

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.
Files changed (3) hide show
  1. package/README.md +14 -3
  2. package/package.json +2 -2
  3. package/src/index.js +22 -3
package/README.md CHANGED
@@ -65,6 +65,8 @@ In order to use this, you must have the webdriver for your chosen browser access
65
65
 
66
66
  `run action <action name>` runs the given action
67
67
 
68
+ `switch to window <index>` switches context to the window handle at the index (useful for popups)
69
+
68
70
  ## Tests
69
71
 
70
72
  The operations `[test <name>]` and `[endtest]` indicate a test block.
@@ -73,13 +75,22 @@ The operations `[test <name>]` and `[endtest]` indicate a test block.
73
75
 
74
76
  Text that is wrapped in double quotes is treated as text
75
77
 
76
- Text that is "return" (without quotes) sends the enter key to the element
77
-
78
78
  Text that starts with a $ will load a variable of the same name
79
79
 
80
80
  Text that starts with a `/` may be considered a regex by some commands
81
81
 
82
- Text that is "uuid" (without quotes) generates a new uuid-v4
82
+ Special text elements:
83
+
84
+ These should be entered without quotes or any other text.
85
+
86
+ | Name | Description |
87
+ | ---- | ----------- |
88
+ | uuid | Generates a new uuid-v4 |
89
+ | return | Sends enter key |
90
+ | up | Sends up key |
91
+ | down | Sends down key |
92
+ | left | Sends left key |
93
+ | right | Sends right key |
83
94
 
84
95
  ## Variables
85
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bucky24/jsbehave",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "A module that allows BDD testing for browser based testing in Selenium.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -32,7 +32,7 @@
32
32
  "homepage": "https://github.com/Bucky24/jsbehave#readme",
33
33
  "dependencies": {
34
34
  "clipboardy": "^2.3.0",
35
- "selenium-webdriver": "^4.0.0-alpha.7",
35
+ "selenium-webdriver": "4.3.1",
36
36
  "uuid": "^8.3.2"
37
37
  }
38
38
  }
package/src/index.js CHANGED
@@ -110,6 +110,10 @@ function goToPage([ url ]) {
110
110
 
111
111
  const keyLookup = {
112
112
  "return": Key.RETURN,
113
+ "down": Key.DOWN,
114
+ "up": Key.UP,
115
+ "left": Key.LEFT,
116
+ "right": Key.RIGHT,
113
117
  };
114
118
 
115
119
  function getText(string, allowRegex) {
@@ -132,9 +136,9 @@ function getText(string, allowRegex) {
132
136
  return string;
133
137
  }
134
138
 
135
- function typeKeys([ string, selector ]) {
139
+ async function typeKeys([ string, selector ]) {
136
140
  const sel = getSelector(selector);
137
- const element = driver().findElement(sel);
141
+ const element = await driver().findElement(sel);
138
142
 
139
143
  string = getText(string);
140
144
  return element.sendKeys(string);
@@ -261,8 +265,10 @@ async function runAction(name, showTitle=false) {
261
265
  if (showTitle) {
262
266
  console.log("Running action '" + name + "'");
263
267
  }
268
+ const oldBlock = getVariable("jsbehave.activeBlock");
264
269
  const content = allActions[name];
265
270
  await handleLines(content);
271
+ variables["jsbehave.activeBlock"] = oldBlock;
266
272
  }
267
273
 
268
274
  async function runTestIfNotRun([ testName ]) {
@@ -278,7 +284,9 @@ async function runTestIfNotRun([ testName ]) {
278
284
 
279
285
 
280
286
  async function doRunTest([ testName ]) {
281
- return runTest(testName, true);
287
+ const oldTest = getVariable("jsbehave.activeBlock");
288
+ await runTest(testName, true);
289
+ variables["jsbehave.activeBlock"] = oldTest;
282
290
  }
283
291
 
284
292
  async function doRunAction([ actionName ]) {
@@ -420,6 +428,16 @@ async function takeScreenshot(test) {
420
428
  return fullPath;
421
429
  }
422
430
 
431
+ async function windowSwitch(index) {
432
+ index = parseInt(index, 10);
433
+ const handles = await driver().getAllWindowHandles();
434
+ if (handles.length < index) {
435
+ throw new Error(`Tried to switch to window ${index} but only have ${handles.length} windows`);
436
+ }
437
+ console.log('Switching window to window ' + index + ": " + handles[index]);
438
+ await driver().switchTo().window(handles[index]);
439
+ }
440
+
423
441
  const startTestRegex = "\\[test (.+)\\]";
424
442
  const startActionRegex = "\\[action (.+)\\]";
425
443
 
@@ -459,6 +477,7 @@ const operations = {
459
477
  "run action (.+)": doRunAction,
460
478
  [startActionRegex]: startBlock,
461
479
  "\\[endaction\\]": endBlock,
480
+ "switch to window (.+)": windowSwitch,
462
481
  };
463
482
 
464
483
  async function handleLines(lines) {