@atomic-testing/playwright 0.2.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 ADDED
@@ -0,0 +1 @@
1
+ # @atomic-testing/playwright
@@ -0,0 +1,19 @@
1
+ import { IClickOption, IInteractor, LocatorChain, Optional } from '@atomic-testing/core';
2
+ import { IEnterTextOption } from '@atomic-testing/core/src/types';
3
+ import { Page } from '@playwright/test';
4
+ export declare class PlaywrightInteractor implements IInteractor {
5
+ readonly page: Page;
6
+ constructor(page: Page);
7
+ selectOptionValue(locator: LocatorChain, values: string[]): Promise<void>;
8
+ getInputValue(locator: LocatorChain): Promise<Optional<string>>;
9
+ getSelectValues(locator: LocatorChain): Promise<Optional<readonly string[]>>;
10
+ enterText(locator: LocatorChain, text: string, option?: Partial<IEnterTextOption> | undefined): Promise<void>;
11
+ click(locator: LocatorChain, option?: IClickOption): Promise<void>;
12
+ getAttribute(locator: LocatorChain, name: string, isMultiple: true): Promise<readonly string[]>;
13
+ getAttribute(locator: LocatorChain, name: string, isMultiple: false): Promise<Optional<string>>;
14
+ getAttribute(locator: LocatorChain, name: string): Promise<Optional<string>>;
15
+ getText(locator: LocatorChain): Promise<Optional<string>>;
16
+ exists(locator: LocatorChain): Promise<boolean>;
17
+ isChecked(locator: LocatorChain): Promise<boolean>;
18
+ clone(): IInteractor;
19
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PlaywrightInteractor = void 0;
13
+ const core_1 = require("@atomic-testing/core");
14
+ class PlaywrightInteractor {
15
+ constructor(page) {
16
+ this.page = page;
17
+ }
18
+ selectOptionValue(locator, values) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const cssLocator = core_1.locatorUtil.toCssSelector(locator);
21
+ yield this.page.locator(cssLocator).selectOption(values);
22
+ });
23
+ }
24
+ getInputValue(locator) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const cssLocator = core_1.locatorUtil.toCssSelector(locator);
27
+ return this.page.locator(cssLocator).inputValue();
28
+ });
29
+ }
30
+ getSelectValues(locator) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const optionLocator = {
33
+ type: core_1.LocatorType.Css,
34
+ selector: 'option:checked',
35
+ };
36
+ const selectedOptionLocator = core_1.locatorUtil.append(locator, optionLocator);
37
+ const cssLocator = core_1.locatorUtil.toCssSelector(selectedOptionLocator);
38
+ const allOptions = yield this.page.locator(cssLocator).all();
39
+ const values = [];
40
+ for (const option of allOptions) {
41
+ const value = yield option.getAttribute('value');
42
+ if (value != null) {
43
+ values.push(value);
44
+ }
45
+ }
46
+ return values;
47
+ });
48
+ }
49
+ enterText(locator, text, option) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const cssLocator = core_1.locatorUtil.toCssSelector(locator);
52
+ yield this.page.locator(cssLocator).type(text);
53
+ });
54
+ }
55
+ click(locator, option) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const cssLocator = core_1.locatorUtil.toCssSelector(locator);
58
+ yield this.page.locator(cssLocator).click();
59
+ });
60
+ }
61
+ getAttribute(locator, name, isMultiple) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const cssLocator = core_1.locatorUtil.toCssSelector(locator);
64
+ const elLocator = this.page.locator(cssLocator);
65
+ if (isMultiple) {
66
+ const locators = yield elLocator.all();
67
+ const values = [];
68
+ for (const locator of locators) {
69
+ const value = yield locator.getAttribute(name);
70
+ if (value != null) {
71
+ values.push(value);
72
+ }
73
+ }
74
+ return values;
75
+ }
76
+ const value = yield elLocator.getAttribute(name);
77
+ return value !== null && value !== void 0 ? value : undefined;
78
+ });
79
+ }
80
+ getText(locator) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ const cssLocator = core_1.locatorUtil.toCssSelector(locator);
83
+ const text = yield this.page.locator(cssLocator).textContent();
84
+ return text !== null && text !== void 0 ? text : undefined;
85
+ });
86
+ }
87
+ exists(locator) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ const cssLocator = core_1.locatorUtil.toCssSelector(locator);
90
+ const count = yield this.page.locator(cssLocator).count();
91
+ return count > 0;
92
+ });
93
+ }
94
+ isChecked(locator) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ const cssLocator = core_1.locatorUtil.toCssSelector(locator);
97
+ const checked = yield this.page.locator(cssLocator).isChecked();
98
+ return checked;
99
+ });
100
+ }
101
+ clone() {
102
+ return new PlaywrightInteractor(this.page);
103
+ }
104
+ }
105
+ exports.PlaywrightInteractor = PlaywrightInteractor;
106
+ //# sourceMappingURL=PlaywrightInteractor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlaywrightInteractor.js","sourceRoot":"","sources":["../src/PlaywrightInteractor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAQ8B;AAI9B,MAAa,oBAAoB;IAC/B,YAA4B,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;IAAG,CAAC;IACpC,iBAAiB,CAAC,OAAqB,EAAE,MAAgB;;YAC7D,MAAM,UAAU,GAAG,kBAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACtD,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC3D,CAAC;KAAA;IAEK,aAAa,CAAC,OAAqB;;YACvC,MAAM,UAAU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AE,CAAC;YAC1D,OAAO,KAAK,GAAG,CAAC,CAAC;QACnB,CAAC;KAAA;IAEK,SAAS,CAAC,OAAqB;;YACnC,MAAM,UAAU,GAAG,kBAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACtD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,SAAS,EAAE,CAAC;YAChE,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;IAED,KAAK;QACH,OAAO,IAAI,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;CACF;AAtFD,oDAsFC"}
@@ -0,0 +1,3 @@
1
+ import { ScenePart, TestEngine } from '@atomic-testing/core';
2
+ import { Page } from '@playwright/test';
3
+ export declare function createTestEngine<T extends ScenePart>(page: Page, partDefinitions: T): TestEngine<T>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTestEngine = void 0;
4
+ const core_1 = require("@atomic-testing/core");
5
+ const PlaywrightInteractor_1 = require("./PlaywrightInteractor");
6
+ function createTestEngine(page, partDefinitions) {
7
+ const engine = new core_1.TestEngine([], new PlaywrightInteractor_1.PlaywrightInteractor(page), {
8
+ perform: core_1.defaultStep,
9
+ parts: partDefinitions,
10
+ });
11
+ return engine;
12
+ }
13
+ exports.createTestEngine = createTestEngine;
14
+ //# sourceMappingURL=createTestEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTestEngine.js","sourceRoot":"","sources":["../src/createTestEngine.ts"],"names":[],"mappings":";;;AAAA,+CAA0E;AAG1E,iEAA8D;AAE9D,SAAgB,gBAAgB,CAAsB,IAAU,EAAE,eAAkB;IAClF,MAAM,MAAM,GAAG,IAAI,iBAAU,CAAC,EAAE,EAAE,IAAI,2CAAoB,CAAC,IAAI,CAAC,EAAE;QAChE,OAAO,EAAE,kBAAW;QACpB,KAAK,EAAE,eAAe;KACvB,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAPD,4CAOC"}
@@ -0,0 +1,2 @@
1
+ export { createTestEngine } from './createTestEngine';
2
+ export { PlaywrightInteractor } from './PlaywrightInteractor';
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlaywrightInteractor = exports.createTestEngine = void 0;
4
+ var createTestEngine_1 = require("./createTestEngine");
5
+ Object.defineProperty(exports, "createTestEngine", { enumerable: true, get: function () { return createTestEngine_1.createTestEngine; } });
6
+ var PlaywrightInteractor_1 = require("./PlaywrightInteractor");
7
+ Object.defineProperty(exports, "PlaywrightInteractor", { enumerable: true, get: function () { return PlaywrightInteractor_1.PlaywrightInteractor; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@atomic-testing/playwright",
3
+ "version": "0.2.0",
4
+ "description": "TestZilla Playwright Adapter",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist",
8
+ "src"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "postbuild": "node ../../scripts/postBuild.js"
13
+ },
14
+ "author": "Tianzhen Lin <tangent@usa.net>",
15
+ "keywords": [],
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/tangentlin/testzilla.git"
20
+ },
21
+ "dependencies": {
22
+ "@atomic-testing/core": "workspace:*"
23
+ },
24
+ "devDependencies": {
25
+ "@playwright/test": "^1.31.2",
26
+ "@types/node": "^16.0.0",
27
+ "jest": "^29.2.0",
28
+ "ts-jest": "^29.0.0",
29
+ "ts-node": "^10.9.0",
30
+ "typescript": "^4.9.0"
31
+ },
32
+ "peerDependencies": {
33
+ "@playwright/test": ">=1.30.2"
34
+ }
35
+ }
@@ -0,0 +1,99 @@
1
+ import {
2
+ IClickOption,
3
+ IInteractor,
4
+ LocatorChain,
5
+ LocatorType,
6
+ locatorUtil,
7
+ Optional,
8
+ PartLocatorType,
9
+ } from '@atomic-testing/core';
10
+ import { IEnterTextOption } from '@atomic-testing/core/src/types';
11
+ import { Page } from '@playwright/test';
12
+
13
+ export class PlaywrightInteractor implements IInteractor {
14
+ constructor(public readonly page: Page) {}
15
+ async selectOptionValue(locator: LocatorChain, values: string[]): Promise<void> {
16
+ const cssLocator = locatorUtil.toCssSelector(locator);
17
+ await this.page.locator(cssLocator).selectOption(values);
18
+ }
19
+
20
+ async getInputValue(locator: LocatorChain): Promise<Optional<string>> {
21
+ const cssLocator = locatorUtil.toCssSelector(locator);
22
+ return this.page.locator(cssLocator).inputValue();
23
+ }
24
+
25
+ async getSelectValues(locator: LocatorChain): Promise<Optional<readonly string[]>> {
26
+ const optionLocator: PartLocatorType = {
27
+ type: LocatorType.Css,
28
+ selector: 'option:checked',
29
+ };
30
+ const selectedOptionLocator = locatorUtil.append(locator, optionLocator);
31
+ const cssLocator = locatorUtil.toCssSelector(selectedOptionLocator);
32
+ const allOptions = await this.page.locator(cssLocator).all();
33
+ const values: string[] = [];
34
+ for (const option of allOptions) {
35
+ const value = await option.getAttribute('value');
36
+ if (value != null) {
37
+ values.push(value);
38
+ }
39
+ }
40
+ return values;
41
+ }
42
+
43
+ async enterText(locator: LocatorChain, text: string, option?: Partial<IEnterTextOption> | undefined): Promise<void> {
44
+ const cssLocator = locatorUtil.toCssSelector(locator);
45
+ await this.page.locator(cssLocator).type(text);
46
+ }
47
+
48
+ async click(locator: LocatorChain, option?: IClickOption): Promise<void> {
49
+ const cssLocator = locatorUtil.toCssSelector(locator);
50
+ await this.page.locator(cssLocator).click();
51
+ }
52
+
53
+ async getAttribute(locator: LocatorChain, name: string, isMultiple: true): Promise<readonly string[]>;
54
+ async getAttribute(locator: LocatorChain, name: string, isMultiple: false): Promise<Optional<string>>;
55
+ async getAttribute(locator: LocatorChain, name: string): Promise<Optional<string>>;
56
+ async getAttribute(
57
+ locator: LocatorChain,
58
+ name: string,
59
+ isMultiple?: boolean,
60
+ ): Promise<Optional<string> | readonly string[]> {
61
+ const cssLocator = locatorUtil.toCssSelector(locator);
62
+ const elLocator = this.page.locator(cssLocator);
63
+ if (isMultiple) {
64
+ const locators = await elLocator.all();
65
+ const values: string[] = [];
66
+ for (const locator of locators) {
67
+ const value = await locator.getAttribute(name);
68
+ if (value != null) {
69
+ values.push(value);
70
+ }
71
+ }
72
+ return values;
73
+ }
74
+ const value = await elLocator.getAttribute(name);
75
+ return value ?? undefined;
76
+ }
77
+
78
+ async getText(locator: LocatorChain): Promise<Optional<string>> {
79
+ const cssLocator = locatorUtil.toCssSelector(locator);
80
+ const text = await this.page.locator(cssLocator).textContent();
81
+ return text ?? undefined;
82
+ }
83
+
84
+ async exists(locator: LocatorChain): Promise<boolean> {
85
+ const cssLocator = locatorUtil.toCssSelector(locator);
86
+ const count = await this.page.locator(cssLocator).count();
87
+ return count > 0;
88
+ }
89
+
90
+ async isChecked(locator: LocatorChain): Promise<boolean> {
91
+ const cssLocator = locatorUtil.toCssSelector(locator);
92
+ const checked = await this.page.locator(cssLocator).isChecked();
93
+ return checked;
94
+ }
95
+
96
+ clone(): IInteractor {
97
+ return new PlaywrightInteractor(this.page);
98
+ }
99
+ }
@@ -0,0 +1,13 @@
1
+ import { defaultStep, ScenePart, TestEngine } from '@atomic-testing/core';
2
+ import { Page } from '@playwright/test';
3
+
4
+ import { PlaywrightInteractor } from './PlaywrightInteractor';
5
+
6
+ export function createTestEngine<T extends ScenePart>(page: Page, partDefinitions: T): TestEngine<T> {
7
+ const engine = new TestEngine([], new PlaywrightInteractor(page), {
8
+ perform: defaultStep,
9
+ parts: partDefinitions,
10
+ });
11
+
12
+ return engine;
13
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { createTestEngine } from './createTestEngine';
2
+ export { PlaywrightInteractor } from './PlaywrightInteractor';