@bucky24/jsbehave 0.10.3 → 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.
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bucky24/jsbehave",
3
- "version": "0.10.3",
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
@@ -136,9 +136,9 @@ function getText(string, allowRegex) {
136
136
  return string;
137
137
  }
138
138
 
139
- function typeKeys([ string, selector ]) {
139
+ async function typeKeys([ string, selector ]) {
140
140
  const sel = getSelector(selector);
141
- const element = driver().findElement(sel);
141
+ const element = await driver().findElement(sel);
142
142
 
143
143
  string = getText(string);
144
144
  return element.sendKeys(string);
@@ -428,6 +428,16 @@ async function takeScreenshot(test) {
428
428
  return fullPath;
429
429
  }
430
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
+
431
441
  const startTestRegex = "\\[test (.+)\\]";
432
442
  const startActionRegex = "\\[action (.+)\\]";
433
443
 
@@ -467,6 +477,7 @@ const operations = {
467
477
  "run action (.+)": doRunAction,
468
478
  [startActionRegex]: startBlock,
469
479
  "\\[endaction\\]": endBlock,
480
+ "switch to window (.+)": windowSwitch,
470
481
  };
471
482
 
472
483
  async function handleLines(lines) {