@oracle/oraclejet-selenium-driver 18.0.10
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.
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { KeyType, ClickOptions, TestDriver, TestElement } from '@oracle/oraclejet-testing/UNSAFE_driver';
|
|
2
|
+
import { WebDriver } from 'selenium-webdriver';
|
|
3
|
+
export declare class SeleniumDriver implements TestDriver {
|
|
4
|
+
private driver;
|
|
5
|
+
private platform;
|
|
6
|
+
constructor(driver: WebDriver);
|
|
7
|
+
executeScript<T>(script: string | (() => T), ...args: any): Promise<T>;
|
|
8
|
+
findElement(query: string): Promise<TestElement>;
|
|
9
|
+
findElements(query: string): Promise<TestElement[]>;
|
|
10
|
+
sendKeys(element: TestElement, ...text: (string | KeyType)[]): Promise<void>;
|
|
11
|
+
click(element: TestElement, options?: ClickOptions): Promise<void>;
|
|
12
|
+
private ensurePlatform;
|
|
13
|
+
/**
|
|
14
|
+
* Get the platform-specific key value for the key, if available.
|
|
15
|
+
* @param key The key value
|
|
16
|
+
* @returns A platform-specific value for the key, or the original key if none exists
|
|
17
|
+
*/
|
|
18
|
+
private getPlatformKey;
|
|
19
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SeleniumDriver = void 0;
|
|
4
|
+
const UNSAFE_driver_1 = require("@oracle/oraclejet-testing/UNSAFE_driver");
|
|
5
|
+
const selenium_webdriver_1 = require("selenium-webdriver");
|
|
6
|
+
const modifierKeys = {
|
|
7
|
+
SHIFT: selenium_webdriver_1.Key.SHIFT,
|
|
8
|
+
CONTROL: selenium_webdriver_1.Key.CONTROL,
|
|
9
|
+
CONTROL_COMMAND: selenium_webdriver_1.Key.CONTROL,
|
|
10
|
+
ALT: selenium_webdriver_1.Key.ALT
|
|
11
|
+
};
|
|
12
|
+
const keyMap = {
|
|
13
|
+
...modifierKeys,
|
|
14
|
+
BACKSPACE: selenium_webdriver_1.Key.BACK_SPACE,
|
|
15
|
+
TAB: selenium_webdriver_1.Key.TAB,
|
|
16
|
+
ENTER: selenium_webdriver_1.Key.ENTER,
|
|
17
|
+
ESCAPE: selenium_webdriver_1.Key.ESCAPE,
|
|
18
|
+
PAGE_UP: selenium_webdriver_1.Key.PAGE_UP,
|
|
19
|
+
PAGE_DOWN: selenium_webdriver_1.Key.PAGE_DOWN,
|
|
20
|
+
END: selenium_webdriver_1.Key.END,
|
|
21
|
+
HOME: selenium_webdriver_1.Key.HOME,
|
|
22
|
+
ARROW_LEFT: selenium_webdriver_1.Key.ARROW_LEFT,
|
|
23
|
+
ARROW_UP: selenium_webdriver_1.Key.ARROW_UP,
|
|
24
|
+
ARROW_RIGHT: selenium_webdriver_1.Key.ARROW_RIGHT,
|
|
25
|
+
ARROW_DOWN: selenium_webdriver_1.Key.ARROW_DOWN,
|
|
26
|
+
DELETE: selenium_webdriver_1.Key.DELETE,
|
|
27
|
+
F1: selenium_webdriver_1.Key.F1,
|
|
28
|
+
F2: selenium_webdriver_1.Key.F2,
|
|
29
|
+
F3: selenium_webdriver_1.Key.F3,
|
|
30
|
+
F4: selenium_webdriver_1.Key.F4,
|
|
31
|
+
F5: selenium_webdriver_1.Key.F5,
|
|
32
|
+
F6: selenium_webdriver_1.Key.F6,
|
|
33
|
+
F7: selenium_webdriver_1.Key.F7,
|
|
34
|
+
F8: selenium_webdriver_1.Key.F8,
|
|
35
|
+
F9: selenium_webdriver_1.Key.F9,
|
|
36
|
+
F10: selenium_webdriver_1.Key.F10,
|
|
37
|
+
F11: selenium_webdriver_1.Key.F11,
|
|
38
|
+
F12: selenium_webdriver_1.Key.F12
|
|
39
|
+
};
|
|
40
|
+
class SeleniumDriver {
|
|
41
|
+
constructor(driver) {
|
|
42
|
+
this.platform = '';
|
|
43
|
+
this.driver = driver;
|
|
44
|
+
}
|
|
45
|
+
executeScript(script, ...args) {
|
|
46
|
+
return this.driver.executeScript(script, ...args);
|
|
47
|
+
}
|
|
48
|
+
findElement(query) {
|
|
49
|
+
return this.driver.findElement(selenium_webdriver_1.By.css(query)).then(wrapElement);
|
|
50
|
+
}
|
|
51
|
+
findElements(query) {
|
|
52
|
+
return this.driver.findElements(selenium_webdriver_1.By.css(query)).then((els) => els.map(wrapElement));
|
|
53
|
+
}
|
|
54
|
+
async sendKeys(element, ...text) {
|
|
55
|
+
await this.ensurePlatform();
|
|
56
|
+
return element.el.sendKeys(...text.map(this.getPlatformKey.bind(this)));
|
|
57
|
+
}
|
|
58
|
+
async click(element, options = {}) {
|
|
59
|
+
await this.ensurePlatform();
|
|
60
|
+
const modifiers = options.modifiers || [];
|
|
61
|
+
const actions = this.driver.actions();
|
|
62
|
+
modifiers.map(this.getPlatformKey.bind(this)).forEach((m) => actions.keyDown(m));
|
|
63
|
+
await actions.click(element.el).perform();
|
|
64
|
+
return actions.clear();
|
|
65
|
+
}
|
|
66
|
+
async ensurePlatform() {
|
|
67
|
+
if (!this.platform) {
|
|
68
|
+
this.platform = (await this.driver.getCapabilities()).getPlatform() || 'unknown';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the platform-specific key value for the key, if available.
|
|
73
|
+
* @param key The key value
|
|
74
|
+
* @returns A platform-specific value for the key, or the original key if none exists
|
|
75
|
+
*/
|
|
76
|
+
getPlatformKey(key) {
|
|
77
|
+
if (typeof key === 'object') {
|
|
78
|
+
return UNSAFE_driver_1.Keys['CONTROL_COMMAND'] === key
|
|
79
|
+
? this.platform === 'mac'
|
|
80
|
+
? selenium_webdriver_1.Key.COMMAND
|
|
81
|
+
: selenium_webdriver_1.Key.CONTROL
|
|
82
|
+
: keyMap[key.key];
|
|
83
|
+
}
|
|
84
|
+
return key;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.SeleniumDriver = SeleniumDriver;
|
|
88
|
+
function wrapElement(element) {
|
|
89
|
+
return new ElementWrapper(element);
|
|
90
|
+
}
|
|
91
|
+
class ElementWrapper {
|
|
92
|
+
constructor(element) {
|
|
93
|
+
this.el = element;
|
|
94
|
+
}
|
|
95
|
+
findElement(query) {
|
|
96
|
+
return this.el.findElement(selenium_webdriver_1.By.css(query)).then(wrapElement);
|
|
97
|
+
}
|
|
98
|
+
findElements(query) {
|
|
99
|
+
return this.el.findElements(selenium_webdriver_1.By.css(query)).then((els) => els.map(wrapElement));
|
|
100
|
+
}
|
|
101
|
+
getAttribute(attrName) {
|
|
102
|
+
return this.el.getAttribute(attrName);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SeleniumDriver } from './SeleniumDriver';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SeleniumDriver = void 0;
|
|
4
|
+
var SeleniumDriver_1 = require("./SeleniumDriver");
|
|
5
|
+
Object.defineProperty(exports, "SeleniumDriver", { enumerable: true, get: function () { return SeleniumDriver_1.SeleniumDriver; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oracle/oraclejet-selenium-driver",
|
|
3
|
+
"packageManager": "yarn@3.5.0",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@oracle/oraclejet-testing": "18.0.10"
|
|
6
|
+
},
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@jest/globals": "29.6.2",
|
|
9
|
+
"@oracle/oraclejet-internal-test-utils": "workspace:*",
|
|
10
|
+
"@oracle/oraclejet-internal-ws-build": "workspace:^",
|
|
11
|
+
"@oracle/oraclejet-webdriver": "workspace:*",
|
|
12
|
+
"copyfiles": "2.4.1",
|
|
13
|
+
"http-server": "~0.12.3",
|
|
14
|
+
"jest": "29.6.2",
|
|
15
|
+
"rimraf": "3.0.2",
|
|
16
|
+
"ts-jest": "29.1.0",
|
|
17
|
+
"typescript": "5.7.2"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "yarn clean; tsc --outDir dist/UNSAFE_SeleniumDriver && yarn copy-files",
|
|
21
|
+
"clean": "rimraf dist",
|
|
22
|
+
"copy-files": "mergeJson package.json src/package-overrides.json dist/package.json",
|
|
23
|
+
"test": "node test/jest-http-launcher.js --httpRoot=src --port=${WD_SERVER_PORT:-6008} --config=test/jest.config.js",
|
|
24
|
+
"test-ci-browser": "yarn test --headless"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"selenium-webdriver": ">=3.6.0"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
"./*": "./*/index.js"
|
|
31
|
+
},
|
|
32
|
+
"typesVersions": {
|
|
33
|
+
"*": {
|
|
34
|
+
"*": [
|
|
35
|
+
"./*/index.d.ts"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"version": "18.0.10"
|
|
40
|
+
}
|