craftdriver 0.0.1
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/LICENSE +21 -0
- package/README.md +37 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions.d.ts +50 -0
- package/dist/lib/actions.d.ts.map +1 -0
- package/dist/lib/actions.js +71 -0
- package/dist/lib/actions.js.map +1 -0
- package/dist/lib/browser.d.ts +94 -0
- package/dist/lib/browser.d.ts.map +1 -0
- package/dist/lib/browser.js +133 -0
- package/dist/lib/browser.js.map +1 -0
- package/dist/lib/builder.d.ts +13 -0
- package/dist/lib/builder.d.ts.map +1 -0
- package/dist/lib/builder.js +31 -0
- package/dist/lib/builder.js.map +1 -0
- package/dist/lib/by.d.ts +45 -0
- package/dist/lib/by.d.ts.map +1 -0
- package/dist/lib/by.js +132 -0
- package/dist/lib/by.js.map +1 -0
- package/dist/lib/chrome.d.ts +6 -0
- package/dist/lib/chrome.d.ts.map +1 -0
- package/dist/lib/chrome.js +27 -0
- package/dist/lib/chrome.js.map +1 -0
- package/dist/lib/driver.d.ts +35 -0
- package/dist/lib/driver.d.ts.map +1 -0
- package/dist/lib/driver.js +347 -0
- package/dist/lib/driver.js.map +1 -0
- package/dist/lib/elementHandle.d.ts +17 -0
- package/dist/lib/elementHandle.d.ts.map +1 -0
- package/dist/lib/elementHandle.js +46 -0
- package/dist/lib/elementHandle.js.map +1 -0
- package/dist/lib/expect.d.ts +17 -0
- package/dist/lib/expect.d.ts.map +1 -0
- package/dist/lib/expect.js +56 -0
- package/dist/lib/expect.js.map +1 -0
- package/dist/lib/http.d.ts +7 -0
- package/dist/lib/http.d.ts.map +1 -0
- package/dist/lib/http.js +47 -0
- package/dist/lib/http.js.map +1 -0
- package/dist/lib/keyboard.d.ts +14 -0
- package/dist/lib/keyboard.d.ts.map +1 -0
- package/dist/lib/keyboard.js +31 -0
- package/dist/lib/keyboard.js.map +1 -0
- package/dist/lib/keys.d.ts +43 -0
- package/dist/lib/keys.d.ts.map +1 -0
- package/dist/lib/keys.js +146 -0
- package/dist/lib/keys.js.map +1 -0
- package/dist/lib/locator.d.ts +20 -0
- package/dist/lib/locator.d.ts.map +1 -0
- package/dist/lib/locator.js +57 -0
- package/dist/lib/locator.js.map +1 -0
- package/dist/lib/mouse.d.ts +34 -0
- package/dist/lib/mouse.d.ts.map +1 -0
- package/dist/lib/mouse.js +108 -0
- package/dist/lib/mouse.js.map +1 -0
- package/dist/lib/service.d.ts +26 -0
- package/dist/lib/service.d.ts.map +1 -0
- package/dist/lib/service.js +86 -0
- package/dist/lib/service.js.map +1 -0
- package/dist/lib/types.d.ts +23 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/wait.d.ts +25 -0
- package/dist/lib/wait.d.ts.map +1 -0
- package/dist/lib/wait.js +92 -0
- package/dist/lib/wait.js.map +1 -0
- package/dist/lib/webelement.d.ts +20 -0
- package/dist/lib/webelement.d.ts.map +1 -0
- package/dist/lib/webelement.js +64 -0
- package/dist/lib/webelement.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { until } from './wait.js';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import { expectSelector } from './expect.js';
|
|
4
|
+
import { getKeyValue } from './keys.js';
|
|
5
|
+
export class ElementHandle {
|
|
6
|
+
driver;
|
|
7
|
+
by;
|
|
8
|
+
constructor(driver, by) {
|
|
9
|
+
this.driver = driver;
|
|
10
|
+
this.by = by;
|
|
11
|
+
}
|
|
12
|
+
async click() {
|
|
13
|
+
const el = await this.driver.wait(until.elementIsVisible(this.by), { timeout: 5000 });
|
|
14
|
+
await el.click();
|
|
15
|
+
}
|
|
16
|
+
async type(text, options) {
|
|
17
|
+
const el = await this.driver.wait(until.elementIsVisible(this.by), {
|
|
18
|
+
timeout: options?.timeout ?? 5000,
|
|
19
|
+
});
|
|
20
|
+
await el.click();
|
|
21
|
+
await el.sendKeys(text);
|
|
22
|
+
}
|
|
23
|
+
async press(key) {
|
|
24
|
+
// assumes element is focused after click/type; ensure focus by clicking first
|
|
25
|
+
const el = await this.driver.wait(until.elementIsVisible(this.by), { timeout: 5000 });
|
|
26
|
+
await el.click();
|
|
27
|
+
const code = getKeyValue(key);
|
|
28
|
+
await this.driver.keyPressCode(code, 1);
|
|
29
|
+
}
|
|
30
|
+
async screenshot(path) {
|
|
31
|
+
const el = await this.driver.wait(until.elementIsVisible(this.by), { timeout: 5000 });
|
|
32
|
+
const b64 = await el.screenshotBase64();
|
|
33
|
+
const buf = Buffer.from(b64, 'base64');
|
|
34
|
+
if (path)
|
|
35
|
+
await fs.writeFile(path, buf);
|
|
36
|
+
return buf;
|
|
37
|
+
}
|
|
38
|
+
async text() {
|
|
39
|
+
const el = await this.driver.findElement(this.by);
|
|
40
|
+
return await el.getText();
|
|
41
|
+
}
|
|
42
|
+
expect() {
|
|
43
|
+
return expectSelector(this.driver, this.by);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=elementHandle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementHandle.js","sourceRoot":"","sources":["../../src/lib/elementHandle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAiB,MAAM,WAAW,CAAC;AAEvD,MAAM,OAAO,aAAa;IAEd;IACA;IAFV,YACU,MAAc,EACd,EAAM;QADN,WAAM,GAAN,MAAM,CAAQ;QACd,OAAE,GAAF,EAAE,CAAI;IACb,CAAC;IAEJ,KAAK,CAAC,KAAK;QACT,MAAM,EAAE,GAAG,MA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AAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACvC,IAAI,IAAI;YAAE,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACxC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClD,OAAO,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;IAC5B,CAAC;IAED,MAAM;QACJ,OAAO,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { By } from './by.js';
|
|
2
|
+
import type { Driver } from './driver.js';
|
|
3
|
+
export interface ExpectApi {
|
|
4
|
+
toHaveText(text: string | RegExp, opts?: {
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
toBeVisible(opts?: {
|
|
8
|
+
timeout?: number;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
not: {
|
|
11
|
+
toBeVisible(opts?: {
|
|
12
|
+
timeout?: number;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function expectSelector(driver: Driver, by: By): ExpectApi;
|
|
17
|
+
//# sourceMappingURL=expect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/lib/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,MAAM,WAAW,SAAS;IACxB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E,WAAW,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,GAAG,EAAE;QACH,WAAW,CAAC,IAAI,CAAC,EAAE;YAAE,OAAO,CAAC,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACzD,CAAC;CACH;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,SAAS,CAuDhE"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { until } from './wait.js';
|
|
2
|
+
export function expectSelector(driver, by) {
|
|
3
|
+
function fail(message) {
|
|
4
|
+
throw new Error(message);
|
|
5
|
+
}
|
|
6
|
+
const toHaveText = async function toHaveText(expected, opts) {
|
|
7
|
+
const timeout = opts?.timeout ?? 5000;
|
|
8
|
+
const deadline = Date.now() + timeout;
|
|
9
|
+
let last = '';
|
|
10
|
+
while (Date.now() < deadline) {
|
|
11
|
+
try {
|
|
12
|
+
await driver.wait(until.elementExists(by), { timeout: Math.min(250, timeout) });
|
|
13
|
+
const found = await driver.findElement(by);
|
|
14
|
+
const text = (await found.getText())?.trim?.() ?? '';
|
|
15
|
+
last = text;
|
|
16
|
+
if (expected instanceof RegExp) {
|
|
17
|
+
if (expected.test(text))
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
else if (text === expected) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// retry
|
|
26
|
+
}
|
|
27
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
28
|
+
}
|
|
29
|
+
const exp = expected instanceof RegExp ? `/${expected.source}/` : `"${expected}"`;
|
|
30
|
+
fail(`Expected element ${by.using}(${by.value}) to have text ${exp} but got "${last}"`);
|
|
31
|
+
};
|
|
32
|
+
const toBeVisible = async function toBeVisible(opts) {
|
|
33
|
+
const timeout = opts?.timeout ?? 5000;
|
|
34
|
+
try {
|
|
35
|
+
await driver.wait(until.elementIsVisible(by), { timeout });
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
fail(`Expected element ${by.using}(${by.value}) to be visible within ${timeout}ms`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const toBeNotVisible = async function toBeNotVisible(opts) {
|
|
42
|
+
const timeout = opts?.timeout ?? 5000;
|
|
43
|
+
try {
|
|
44
|
+
await driver.wait(until.elementIsNotVisible(by), { timeout });
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
fail(`Expected element ${by.using}(${by.value}) to become hidden within ${timeout}ms`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
toHaveText,
|
|
52
|
+
toBeVisible,
|
|
53
|
+
not: { toBeVisible: toBeNotVisible },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=expect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/lib/expect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAUlC,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,EAAM;IACnD,SAAS,IAAI,CAAC,OAAe;QAC3B,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,UAAU,GAAG,KAAK,UAAU,UAAU,CAC1C,QAAyB,EACzB,IAA2B;QAE3B,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,IAAI,IAAI,CAAC;QACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;QACtC,IAAI,IAAI,GAAG,EAAE,CAAC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AM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7D,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,oBAAoB,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,0BAA0B,OAAO,IAAI,CAAC,CAAC;QACtF,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,KAAK,UAAU,cAAc,CAAC,IAA2B;QAC9E,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,IAAI,IAAI,CAAC;QACtC,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAChE,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,oBAAoB,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,6BAA6B,OAAO,IAAI,CAAC,CAAC;QACzF,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,UAAU;QACV,WAAW;QACX,GAAG,EAAE,EAAE,WAAW,EAAE,cAAc,EAAE;KACrC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CommandResponse, RequestOptions, WebDriverEndpoint } from './types.js';
|
|
2
|
+
export declare class HttpClient {
|
|
3
|
+
private endpoint;
|
|
4
|
+
constructor(endpoint: WebDriverEndpoint);
|
|
5
|
+
send<T = unknown>({ method, path, body }: RequestOptions): Promise<CommandResponse<T>>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAErF,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,iBAAiB;IAEzC,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;CAqC7F"}
|
package/dist/lib/http.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import https from 'https';
|
|
3
|
+
import { URL } from 'url';
|
|
4
|
+
export class HttpClient {
|
|
5
|
+
endpoint;
|
|
6
|
+
constructor(endpoint) {
|
|
7
|
+
this.endpoint = endpoint;
|
|
8
|
+
}
|
|
9
|
+
async send({ method, path, body }) {
|
|
10
|
+
const base = `${this.endpoint.protocol}://${this.endpoint.hostname}:${this.endpoint.port}${this.endpoint.path ?? ''}`;
|
|
11
|
+
const url = new URL(path, base);
|
|
12
|
+
const isHttps = url.protocol === 'https:';
|
|
13
|
+
const payload = body ? JSON.stringify(body) : undefined;
|
|
14
|
+
const options = {
|
|
15
|
+
method,
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
18
|
+
Accept: 'application/json',
|
|
19
|
+
...(payload ? { 'Content-Length': Buffer.byteLength(payload) } : {}),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const transport = isHttps ? https : http;
|
|
23
|
+
return await new Promise((resolve, reject) => {
|
|
24
|
+
const req = transport.request(url, options, (res) => {
|
|
25
|
+
const chunks = [];
|
|
26
|
+
res.on('data', (c) => chunks.push(Buffer.from(c)));
|
|
27
|
+
res.on('end', () => {
|
|
28
|
+
const text = Buffer.concat(chunks).toString('utf8');
|
|
29
|
+
if (!text)
|
|
30
|
+
return resolve({ value: undefined });
|
|
31
|
+
try {
|
|
32
|
+
const json = JSON.parse(text);
|
|
33
|
+
resolve(json);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
reject(new Error(`Invalid JSON response: ${text}`));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
req.on('error', reject);
|
|
41
|
+
if (payload)
|
|
42
|
+
req.write(payload);
|
|
43
|
+
req.end();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1B,MAAM,OAAO,UAAU;IACD;IAApB,YAAoB,QAA2B;QAA3B,aAAQ,GAAR,QAAQ,CAAmB;IAAG,CAAC;IAEnD,KAAK,CAAC,IAAI,CAAc,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAkB;QAC5D,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;QACtH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChC,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;QAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAExD,MAAM,OAAO,GAAwB;YACnC,MAAM;YACN,OAAO,EAAE;gBACP,cAAc,EAAE,iCAAiC;gBACjD,MAAM,EAAE,kBAAkB;gBAC1B,GAAG,CAAC,OAAO,CAAC,CAAC,CAA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CAAC;YAChC,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Driver } from './driver.js';
|
|
2
|
+
import { type KeyValue } from './keys.js';
|
|
3
|
+
export declare class KeyboardController {
|
|
4
|
+
private driver;
|
|
5
|
+
constructor(driver: Driver);
|
|
6
|
+
type(text: string): Promise<void>;
|
|
7
|
+
press(key: KeyValue, opts?: {
|
|
8
|
+
repeat?: number;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
down(key: KeyValue): Promise<void>;
|
|
11
|
+
up(key: KeyValue): Promise<void>;
|
|
12
|
+
chord(...keys: KeyValue[]): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/lib/keyboard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEvD,qBAAa,kBAAkB;IACjB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE5B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjC,KAAK,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/D,IAAI,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlC,EAAE,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhC,KAAK,CAAC,GAAG,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAKhD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getKeyValue } from './keys.js';
|
|
2
|
+
export class KeyboardController {
|
|
3
|
+
driver;
|
|
4
|
+
constructor(driver) {
|
|
5
|
+
this.driver = driver;
|
|
6
|
+
}
|
|
7
|
+
async type(text) {
|
|
8
|
+
await this.driver.typeText(text);
|
|
9
|
+
}
|
|
10
|
+
async press(key, opts) {
|
|
11
|
+
const value = getKeyValue(key);
|
|
12
|
+
await this.driver.keyPressCode(value, Math.max(1, opts?.repeat ?? 1));
|
|
13
|
+
}
|
|
14
|
+
async down(key) {
|
|
15
|
+
const value = getKeyValue(key);
|
|
16
|
+
await this.driver.keyDownCode(value);
|
|
17
|
+
}
|
|
18
|
+
async up(key) {
|
|
19
|
+
const value = getKeyValue(key);
|
|
20
|
+
await this.driver.keyUpCode(value);
|
|
21
|
+
}
|
|
22
|
+
// Press multiple keys together (e.g., Ctrl + A): downs in order, ups in reverse.
|
|
23
|
+
async chord(...keys) {
|
|
24
|
+
const codes = keys.map((k) => getKeyValue(k));
|
|
25
|
+
for (const c of codes)
|
|
26
|
+
await this.driver.keyDownCode(c);
|
|
27
|
+
for (const c of codes.slice().reverse())
|
|
28
|
+
await this.driver.keyUpCode(c);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=keyboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.js","sourceRoot":"","sources":["../../src/lib/keyboard.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAiB,MAAM,WAAW,CAAC;AAEvD,MAAM,OAAO,kBAAkB;IACT;IAApB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAEtC,KAAK,CAAC,IAAI,CAAC,IAAY;QACrB,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAa,EAAE,IAA0B;QACnD,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAa;QACtB,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,EAAE,CAAC,GAAa;QACpB,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,iFAAiF;IACjF,KAAK,CAAC,KAAK,CAAC,GAAG,IAAgB;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9C,KAAK,MAAM,CAAC,IAAI,KAAK;YAAE,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACxD,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE;YAAE,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC1E,CAAC;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const WebDriverKeyCodes: Record<string, string>;
|
|
2
|
+
export type KeyValue = keyof typeof Key | string;
|
|
3
|
+
export declare const Key: {
|
|
4
|
+
readonly Null: string;
|
|
5
|
+
readonly Cancel: string;
|
|
6
|
+
readonly Help: string;
|
|
7
|
+
readonly Backspace: string;
|
|
8
|
+
readonly Tab: string;
|
|
9
|
+
readonly Clear: string;
|
|
10
|
+
readonly Return: string;
|
|
11
|
+
readonly Enter: string;
|
|
12
|
+
readonly Shift: string;
|
|
13
|
+
readonly Control: string;
|
|
14
|
+
readonly Alt: string;
|
|
15
|
+
readonly Pause: string;
|
|
16
|
+
readonly Escape: string;
|
|
17
|
+
readonly Space: string;
|
|
18
|
+
readonly PageUp: string;
|
|
19
|
+
readonly PageDown: string;
|
|
20
|
+
readonly End: string;
|
|
21
|
+
readonly Home: string;
|
|
22
|
+
readonly ArrowLeft: string;
|
|
23
|
+
readonly ArrowUp: string;
|
|
24
|
+
readonly ArrowRight: string;
|
|
25
|
+
readonly ArrowDown: string;
|
|
26
|
+
readonly Insert: string;
|
|
27
|
+
readonly Delete: string;
|
|
28
|
+
readonly F1: string;
|
|
29
|
+
readonly F2: string;
|
|
30
|
+
readonly F3: string;
|
|
31
|
+
readonly F4: string;
|
|
32
|
+
readonly F5: string;
|
|
33
|
+
readonly F6: string;
|
|
34
|
+
readonly F7: string;
|
|
35
|
+
readonly F8: string;
|
|
36
|
+
readonly F9: string;
|
|
37
|
+
readonly F10: string;
|
|
38
|
+
readonly F11: string;
|
|
39
|
+
readonly F12: string;
|
|
40
|
+
readonly Meta: string;
|
|
41
|
+
};
|
|
42
|
+
export declare function getKeyValue(input: KeyValue): string;
|
|
43
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/lib/keys.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAgEpD,CAAC;AAkCF,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,GAAG,GAAG,MAAM,CAAC;AAGjD,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCN,CAAC;AAGX,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAMnD"}
|
package/dist/lib/keys.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// WebDriver virtual key codes (PUA) per W3C WebDriver spec
|
|
2
|
+
// Reference values are public spec constants; mapping implemented independently.
|
|
3
|
+
export const WebDriverKeyCodes = {
|
|
4
|
+
null: '\uE000',
|
|
5
|
+
cancel: '\uE001',
|
|
6
|
+
help: '\uE002',
|
|
7
|
+
backspace: '\uE003',
|
|
8
|
+
tab: '\uE004',
|
|
9
|
+
clear: '\uE005',
|
|
10
|
+
return: '\uE006',
|
|
11
|
+
enter: '\uE007',
|
|
12
|
+
shift: '\uE008',
|
|
13
|
+
control: '\uE009',
|
|
14
|
+
alt: '\uE00A',
|
|
15
|
+
pause: '\uE00B',
|
|
16
|
+
escape: '\uE00C',
|
|
17
|
+
space: '\uE00D',
|
|
18
|
+
pageup: '\uE00E',
|
|
19
|
+
pagedown: '\uE00F',
|
|
20
|
+
end: '\uE010',
|
|
21
|
+
home: '\uE011',
|
|
22
|
+
arrowleft: '\uE012',
|
|
23
|
+
left: '\uE012',
|
|
24
|
+
arrowup: '\uE013',
|
|
25
|
+
up: '\uE013',
|
|
26
|
+
arrowright: '\uE014',
|
|
27
|
+
right: '\uE014',
|
|
28
|
+
arrowdown: '\uE015',
|
|
29
|
+
down: '\uE015',
|
|
30
|
+
insert: '\uE016',
|
|
31
|
+
delete: '\uE017',
|
|
32
|
+
semicolon: '\uE018',
|
|
33
|
+
equals: '\uE019',
|
|
34
|
+
numpad0: '\uE01A',
|
|
35
|
+
numpad1: '\uE01B',
|
|
36
|
+
numpad2: '\uE01C',
|
|
37
|
+
numpad3: '\uE01D',
|
|
38
|
+
numpad4: '\uE01E',
|
|
39
|
+
numpad5: '\uE01F',
|
|
40
|
+
numpad6: '\uE020',
|
|
41
|
+
numpad7: '\uE021',
|
|
42
|
+
numpad8: '\uE022',
|
|
43
|
+
numpad9: '\uE023',
|
|
44
|
+
multiply: '\uE024',
|
|
45
|
+
add: '\uE025',
|
|
46
|
+
separator: '\uE026',
|
|
47
|
+
subtract: '\uE027',
|
|
48
|
+
decimal: '\uE028',
|
|
49
|
+
divide: '\uE029',
|
|
50
|
+
f1: '\uE031',
|
|
51
|
+
f2: '\uE032',
|
|
52
|
+
f3: '\uE033',
|
|
53
|
+
f4: '\uE034',
|
|
54
|
+
f5: '\uE035',
|
|
55
|
+
f6: '\uE036',
|
|
56
|
+
f7: '\uE037',
|
|
57
|
+
f8: '\uE038',
|
|
58
|
+
f9: '\uE039',
|
|
59
|
+
f10: '\uE03A',
|
|
60
|
+
f11: '\uE03B',
|
|
61
|
+
f12: '\uE03C',
|
|
62
|
+
command: '\uE03D',
|
|
63
|
+
meta: '\uE03D',
|
|
64
|
+
};
|
|
65
|
+
// Aliases mapping for common test-friendly names to canonical keys
|
|
66
|
+
const Aliases = {
|
|
67
|
+
esc: 'escape',
|
|
68
|
+
escape: 'escape',
|
|
69
|
+
enter: 'enter',
|
|
70
|
+
return: 'return',
|
|
71
|
+
space: 'space',
|
|
72
|
+
' ': 'space',
|
|
73
|
+
arrowleft: 'arrowleft',
|
|
74
|
+
left: 'arrowleft',
|
|
75
|
+
arrowup: 'arrowup',
|
|
76
|
+
up: 'arrowup',
|
|
77
|
+
arrowright: 'arrowright',
|
|
78
|
+
right: 'arrowright',
|
|
79
|
+
arrowdown: 'arrowdown',
|
|
80
|
+
down: 'arrowdown',
|
|
81
|
+
pageup: 'pageup',
|
|
82
|
+
pagedown: 'pagedown',
|
|
83
|
+
backspace: 'backspace',
|
|
84
|
+
delete: 'delete',
|
|
85
|
+
shift: 'shift',
|
|
86
|
+
control: 'control',
|
|
87
|
+
ctrl: 'control',
|
|
88
|
+
alt: 'alt',
|
|
89
|
+
meta: 'meta',
|
|
90
|
+
command: 'command',
|
|
91
|
+
};
|
|
92
|
+
function normalizeName(name) {
|
|
93
|
+
return name.replace(/[_\-\s]/g, '').toLowerCase();
|
|
94
|
+
}
|
|
95
|
+
// Public Key enum-like for consumer code: Key.Enter, Key.Escape, etc.
|
|
96
|
+
export const Key = {
|
|
97
|
+
Null: WebDriverKeyCodes.null,
|
|
98
|
+
Cancel: WebDriverKeyCodes.cancel,
|
|
99
|
+
Help: WebDriverKeyCodes.help,
|
|
100
|
+
Backspace: WebDriverKeyCodes.backspace,
|
|
101
|
+
Tab: WebDriverKeyCodes.tab,
|
|
102
|
+
Clear: WebDriverKeyCodes.clear,
|
|
103
|
+
Return: WebDriverKeyCodes.return,
|
|
104
|
+
Enter: WebDriverKeyCodes.enter,
|
|
105
|
+
Shift: WebDriverKeyCodes.shift,
|
|
106
|
+
Control: WebDriverKeyCodes.control,
|
|
107
|
+
Alt: WebDriverKeyCodes.alt,
|
|
108
|
+
Pause: WebDriverKeyCodes.pause,
|
|
109
|
+
Escape: WebDriverKeyCodes.escape,
|
|
110
|
+
Space: WebDriverKeyCodes.space,
|
|
111
|
+
PageUp: WebDriverKeyCodes.pageup,
|
|
112
|
+
PageDown: WebDriverKeyCodes.pagedown,
|
|
113
|
+
End: WebDriverKeyCodes.end,
|
|
114
|
+
Home: WebDriverKeyCodes.home,
|
|
115
|
+
ArrowLeft: WebDriverKeyCodes.arrowleft,
|
|
116
|
+
ArrowUp: WebDriverKeyCodes.arrowup,
|
|
117
|
+
ArrowRight: WebDriverKeyCodes.arrowright,
|
|
118
|
+
ArrowDown: WebDriverKeyCodes.arrowdown,
|
|
119
|
+
Insert: WebDriverKeyCodes.insert,
|
|
120
|
+
Delete: WebDriverKeyCodes.delete,
|
|
121
|
+
F1: WebDriverKeyCodes.f1,
|
|
122
|
+
F2: WebDriverKeyCodes.f2,
|
|
123
|
+
F3: WebDriverKeyCodes.f3,
|
|
124
|
+
F4: WebDriverKeyCodes.f4,
|
|
125
|
+
F5: WebDriverKeyCodes.f5,
|
|
126
|
+
F6: WebDriverKeyCodes.f6,
|
|
127
|
+
F7: WebDriverKeyCodes.f7,
|
|
128
|
+
F8: WebDriverKeyCodes.f8,
|
|
129
|
+
F9: WebDriverKeyCodes.f9,
|
|
130
|
+
F10: WebDriverKeyCodes.f10,
|
|
131
|
+
F11: WebDriverKeyCodes.f11,
|
|
132
|
+
F12: WebDriverKeyCodes.f12,
|
|
133
|
+
Meta: WebDriverKeyCodes.meta,
|
|
134
|
+
};
|
|
135
|
+
// Accept KeyValue and return the WebDriver key string to send.
|
|
136
|
+
export function getKeyValue(input) {
|
|
137
|
+
if (typeof input !== 'string')
|
|
138
|
+
return String(input);
|
|
139
|
+
if (!input)
|
|
140
|
+
return input;
|
|
141
|
+
if (input.length === 1)
|
|
142
|
+
return input; // single character typed as-is
|
|
143
|
+
const canonical = Aliases[normalizeName(input)] ?? normalizeName(input);
|
|
144
|
+
return WebDriverKeyCodes[canonical] ?? input;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/lib/keys.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,iFAAiF;AAEjF,MAAM,CAAC,MAAM,iBAAiB,GAA2B;IACvD,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,QAAQ;IACnB,GAAG,EAAE,QAAQ;IACb,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,QAAQ;IACjB,GAAG,EAAE,QAAQ;IACb,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,QAAQ;IAClB,GAAG,EAAE,QAAQ;IACb,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,QAAQ;IACnB,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,QAAQ;IACjB,EAAE,EAAE,QAAQ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1
|
+
import { By } from './by.js';
|
|
2
|
+
import type { Driver } from './driver.js';
|
|
3
|
+
export interface ActionOptions {
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class Locator {
|
|
7
|
+
private driver;
|
|
8
|
+
private by;
|
|
9
|
+
constructor(driver: Driver, by: By);
|
|
10
|
+
locator(selector: string | By): Locator;
|
|
11
|
+
click(options?: ActionOptions): Promise<void>;
|
|
12
|
+
fill(text: string, options?: ActionOptions): Promise<void>;
|
|
13
|
+
textContent(options?: ActionOptions): Promise<string>;
|
|
14
|
+
isVisible(options?: ActionOptions): Promise<boolean>;
|
|
15
|
+
waitFor(options: {
|
|
16
|
+
state: 'attached' | 'detached' | 'visible' | 'hidden';
|
|
17
|
+
timeout?: number;
|
|
18
|
+
}): Promise<any>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=locator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locator.d.ts","sourceRoot":"","sources":["../../src/lib/locator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,OAAO;IAEhB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,EAAE;gBADF,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,EAAE;IAGhB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,GAAG,OAAO;IAKjC,KAAK,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ9D,WAAW,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAOzD,SAAS,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;IAW9D,OAAO,CAAC,OAAO,EAAE;QACf,KAAK,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;QACtD,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,GAAG,CAAC;CASjB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { By } from './by.js';
|
|
2
|
+
import { until } from './wait.js';
|
|
3
|
+
export class Locator {
|
|
4
|
+
driver;
|
|
5
|
+
by;
|
|
6
|
+
constructor(driver, by) {
|
|
7
|
+
this.driver = driver;
|
|
8
|
+
this.by = by;
|
|
9
|
+
}
|
|
10
|
+
locator(selector) {
|
|
11
|
+
const next = typeof selector === 'string' ? By.css(selector) : selector;
|
|
12
|
+
return new Locator(this.driver, next);
|
|
13
|
+
}
|
|
14
|
+
async click(options = {}) {
|
|
15
|
+
const el = await this.driver.wait(until.elementIsVisible(this.by), {
|
|
16
|
+
timeout: options.timeout ?? 5000,
|
|
17
|
+
});
|
|
18
|
+
await el.click();
|
|
19
|
+
}
|
|
20
|
+
async fill(text, options = {}) {
|
|
21
|
+
const el = await this.driver.wait(until.elementIsVisible(this.by), {
|
|
22
|
+
timeout: options.timeout ?? 5000,
|
|
23
|
+
});
|
|
24
|
+
await el.click();
|
|
25
|
+
await el.sendKeys(text);
|
|
26
|
+
}
|
|
27
|
+
async textContent(options = {}) {
|
|
28
|
+
const el = await this.driver.wait(until.elementExists(this.by), {
|
|
29
|
+
timeout: options.timeout ?? 5000,
|
|
30
|
+
});
|
|
31
|
+
return (await el.getText()) ?? '';
|
|
32
|
+
}
|
|
33
|
+
async isVisible(options = {}) {
|
|
34
|
+
try {
|
|
35
|
+
const el = await this.driver.wait(until.elementExists(this.by), {
|
|
36
|
+
timeout: options.timeout ?? 5000,
|
|
37
|
+
});
|
|
38
|
+
return await el.isDisplayed();
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
waitFor(options) {
|
|
45
|
+
const { state, timeout } = options;
|
|
46
|
+
if (state === 'attached')
|
|
47
|
+
return this.driver.wait(until.elementExists(this.by), { timeout });
|
|
48
|
+
if (state === 'detached')
|
|
49
|
+
return this.driver.wait(until.elementNotExists(this.by), { timeout });
|
|
50
|
+
if (state === 'visible')
|
|
51
|
+
return this.driver.wait(until.elementIsVisible(this.by), { timeout });
|
|
52
|
+
if (state === 'hidden')
|
|
53
|
+
return this.driver.wait(until.elementIsNotVisible(this.by), { timeout });
|
|
54
|
+
return Promise.reject(new Error(`Unknown state: ${state}`));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=locator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locator.js","sourceRoot":"","sources":["../../src/lib/locator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAMlC,MAAM,OAAO,OAAO;IAER;IACA;IAFV,YACU,MAAc,EACd,EAAM;QADN,WAAM,GAAN,MAAM,CAAQ;QACd,OAAE,GAAF,EAAE,CAAI;IACb,CAAC;IAEJ,OAAO,CAAC,QAAqB;QAC3B,MAAM,IAAI,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACxE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,UAAyB,EAAE;QACrC,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC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EAAE,GAAG,OAAO,CAAC;QACnC,IAAI,KAAK,KAAK,UAAU;YAAE,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7F,IAAI,KAAK,KAAK,UAAU;YAAE,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAChG,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/F,IAAI,KAAK,KAAK,QAAQ;YACpB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC3E,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,kBAAkB,KAAK,EAAE,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Driver } from './driver.js';
|
|
2
|
+
import { By } from './by.js';
|
|
3
|
+
import { Key } from './keys.js';
|
|
4
|
+
export type MouseButton = 'left' | 'middle' | 'right';
|
|
5
|
+
export type Point = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
};
|
|
9
|
+
export type Target = string | By | Point;
|
|
10
|
+
export declare class MouseController {
|
|
11
|
+
private driver;
|
|
12
|
+
constructor(driver: Driver);
|
|
13
|
+
private resolveElement;
|
|
14
|
+
move(target: Target, options?: {
|
|
15
|
+
durationMs?: number;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
down(button?: MouseButton): Promise<void>;
|
|
18
|
+
up(button?: MouseButton): Promise<void>;
|
|
19
|
+
click(target: Target, options?: {
|
|
20
|
+
button?: MouseButton;
|
|
21
|
+
clickCount?: number;
|
|
22
|
+
modifiers?: Array<keyof typeof Key>;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
dblclick(target: Target, options?: {
|
|
25
|
+
button?: MouseButton;
|
|
26
|
+
modifiers?: Array<keyof typeof Key>;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
dragAndDrop(from: Target, to: Target, options?: {
|
|
29
|
+
durationMs?: number;
|
|
30
|
+
modifiers?: Array<keyof typeof Key>;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
wheel(deltaX: number, deltaY: number, target?: Target): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=mouse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mouse.d.ts","sourceRoot":"","sources":["../../src/lib/mouse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGhC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AACtD,MAAM,MAAM,KAAK,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC7C,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,EAAE,GAAG,KAAK,CAAC;AAQzC,qBAAa,eAAe;IACd,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;YAEpB,cAAc;IAOtB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CA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