@oracle/oraclejet-testing 17.0.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.
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDriver = exports.setDriver = void 0;
4
+ let _driver;
5
+ /**
6
+ * Set the TestDriver instance to be used for testing. This method should be called by
7
+ * tests during setup, before calling any test adapter methods.
8
+ *
9
+ * @param driver The TestDriver instance
10
+ */
11
+ function setDriver(driver) {
12
+ _driver = driver;
13
+ }
14
+ exports.setDriver = setDriver;
15
+ /**
16
+ * Get the configured TestDriver instance to be used for testing. This method should
17
+ * only be called by test adapters to interact with the browser environment.
18
+ *
19
+ * @returns {TestDriver} The TestDriver instance
20
+ */
21
+ function getDriver() {
22
+ if (!_driver) {
23
+ throw Error('Driver has not been set. Call setDriver()');
24
+ }
25
+ return _driver;
26
+ }
27
+ exports.getDriver = getDriver;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getElement = exports.getByTestId = void 0;
4
+ const UNSAFE_driver_1 = require("../UNSAFE_driver");
5
+ /**
6
+ * Create a locator that targets an element by its testId
7
+ * @param testId
8
+ * @returns The ElementLocator for the given testId
9
+ */
10
+ function getByTestId(testId) {
11
+ return {
12
+ css: getTestIdQuery(testId)
13
+ };
14
+ }
15
+ exports.getByTestId = getByTestId;
16
+ function getTestIdQuery(testId) {
17
+ return `[data-testid=${testId}]`;
18
+ }
19
+ /**
20
+ * Perform an element search on the driver using the given ElementLocator
21
+ * @param locator
22
+ * @returns
23
+ */
24
+ async function getElement(locator) {
25
+ const matches = await (0, UNSAFE_driver_1.getDriver)().findElements(locator.css);
26
+ if (!matches.length) {
27
+ throw Error(`No matches found for "${locator.css}"`);
28
+ }
29
+ return matches[0];
30
+ }
31
+ exports.getElement = getElement;
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@oracle/oraclejet-testing",
3
+ "scripts": {
4
+ "build": "yarn clean; tsc --outDir dist --declarationDir dist/types && yarn copy-files",
5
+ "clean": "rimraf dist",
6
+ "copy-files": "mergeJson package.json src/package-overrides.json dist/package.json"
7
+ },
8
+ "devDependencies": {
9
+ "@oracle/oraclejet-internal-ws-build": "workspace:^",
10
+ "copyfiles": "2.4.1",
11
+ "rimraf": "3.0.2",
12
+ "typescript": "5.4.5"
13
+ },
14
+ "exports": {
15
+ "./*": "./*/index.js"
16
+ },
17
+ "typesVersions": {
18
+ "*": {
19
+ "*": [
20
+ "./types/*/index.d.ts"
21
+ ]
22
+ }
23
+ },
24
+ "dependencies": {},
25
+ "version": "17.0.0"
26
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A TestDriver implements the platform-specific commands needed for testing
3
+ * with adapters.
4
+ */
5
+ export interface TestDriver {
6
+ /**
7
+ * Click on the given TestElement
8
+ * @param element The TestElement on which to click
9
+ */
10
+ click(element: TestElement): Promise<void>;
11
+ /**
12
+ * Execute a script in the browser environment.
13
+ * @param script The script to execute
14
+ * @param args Any arguments to pass to the script. Access each argument through
15
+ * the <code>arguments</code> array.
16
+ */
17
+ executeScript<T>(script: string, ...args: any): Promise<T>;
18
+ /**
19
+ * Find an element in the browser environment that matches the given CSS query.
20
+ * This method should throw an exception if no matching elements are found.
21
+ * @param query The CSS query to use in locate the element
22
+ */
23
+ findElement(query: string): Promise<TestElement>;
24
+ /**
25
+ * Find elements in the browser environment matching the gven CSS query. If no
26
+ * matching elements are found, return a blank array.
27
+ * @param query The CSS query to use in locating the elements.
28
+ */
29
+ findElements(query: string): Promise<TestElement[]>;
30
+ /**
31
+ *
32
+ * @param element The element to receive the keystrokes
33
+ * @param text
34
+ */
35
+ sendKeys(element: TestElement, text: string): Promise<void>;
36
+ }
37
+ /**
38
+ * A TestElement represents the DOM element in the browser environment. This interface
39
+ * is used by test adapters to work with elements without being bound to a specific
40
+ * platform implementation.
41
+ */
42
+ export interface TestElement {
43
+ findElement(query: string): Promise<TestElement>;
44
+ findElements(query: string): Promise<TestElement[]>;
45
+ }
46
+ /**
47
+ * Set the TestDriver instance to be used for testing. This method should be called by
48
+ * tests during setup, before calling any test adapter methods.
49
+ *
50
+ * @param driver The TestDriver instance
51
+ */
52
+ export declare function setDriver(driver: TestDriver): void;
53
+ /**
54
+ * Get the configured TestDriver instance to be used for testing. This method should
55
+ * only be called by test adapters to interact with the browser environment.
56
+ *
57
+ * @returns {TestDriver} The TestDriver instance
58
+ */
59
+ export declare function getDriver(): TestDriver;
@@ -0,0 +1,19 @@
1
+ import { type TestElement } from '../UNSAFE_driver';
2
+ interface ElementLocator {
3
+ css: string;
4
+ }
5
+ export interface TestIdLocator extends ElementLocator {
6
+ }
7
+ /**
8
+ * Create a locator that targets an element by its testId
9
+ * @param testId
10
+ * @returns The ElementLocator for the given testId
11
+ */
12
+ export declare function getByTestId(testId: string): TestIdLocator;
13
+ /**
14
+ * Perform an element search on the driver using the given ElementLocator
15
+ * @param locator
16
+ * @returns
17
+ */
18
+ export declare function getElement(locator: ElementLocator): Promise<TestElement>;
19
+ export {};