@agnos-ui/base-po 0.6.0-next.1 → 0.6.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/base.po.d.ts ADDED
@@ -0,0 +1,117 @@
1
+ import type { Page, Locator } from '@playwright/test';
2
+ /**
3
+ * Base class to be extended for page objects.
4
+ * The purpose of this architecture is to standardize the way locators are created in the page object, to be able to target precisely the dom elements you want to interact with.
5
+ *
6
+ * The constructor takes two parameters:
7
+ *
8
+ * - `container: Page | Locator` is the container locator from which other locators are built
9
+ * - `index: number | null = null` is the nth index component found in the container locator
10
+ *
11
+ * Page objects must usually override the `getComponentSelector()` method to return the html selector of the component
12
+ *
13
+ * @example
14
+ *
15
+ * ```html
16
+ * <!-- page.html -->
17
+ * <div class="component1">
18
+ * <div class="component2">
19
+ * <button>Click me</button>
20
+ * </div>
21
+ * <div class="component2">
22
+ * <button>Click me</button>
23
+ * </div>
24
+ * </div>
25
+ * ```
26
+ *
27
+ * ```typescript
28
+ * // component1.po.ts
29
+ * export Component1Page extends BasePo {
30
+ * getComponentSelector(): string {
31
+ * return 'div.component1';
32
+ * }
33
+ * }
34
+ *
35
+ * // component2.po.ts
36
+ * export Component2Page extends BasePo {
37
+ * getComponentSelector(): string {
38
+ * return 'div.component2';
39
+ * }
40
+ *
41
+ * // Button locator in component2
42
+ * get locatorButton() {
43
+ * return this.locatorRoot.locator('button');
44
+ * }
45
+ * }
46
+ *
47
+ * // test.spec.ts
48
+ * test('should click', ({page}) => {
49
+ *
50
+ * // will manage the component1 section
51
+ * const component1Po = new Component1Page(page);
52
+ *
53
+ * // click on the button of the first component2 of component1
54
+ * const firstComponent2Po = new Component2Page(component1Po.locatorRoot);
55
+ * await firstComponent2Po.locatorButton.click();
56
+ *
57
+ * // click on the button of the second component2 of component1
58
+ * const secondComponent2Po = new Component2Page(component1Po.locatorRoot, 1);
59
+ * await secondComponent2Po.locatorButton.click();
60
+ *
61
+ * });
62
+ *
63
+ * ```
64
+ *
65
+ */
66
+ export declare class BasePO {
67
+ #private;
68
+ /**
69
+ * Playwright page object from which the page object has been created.
70
+ * It can be convenient for situation where you can't work (internally) with the locatorRoot
71
+ */
72
+ protected _page: Page;
73
+ /**
74
+ *
75
+ * @param container - Container locator (page if there is no container) where the component is located
76
+ * @param index - If you have multiple components **inside the container**, you must provide the index to select the component to work with. You can omit this parameter if you have a single component.
77
+ */
78
+ constructor(container: Page | Locator, index?: number | null);
79
+ /**
80
+ * The root locator of your page object.
81
+ * It can be used to be chain with internal locators.
82
+ *
83
+ * It is built with the provided `container` from the constructor, the `getComponentSelector` (one of them must be provided, at least) and the optional `index` parameter from the contructor.
84
+ *
85
+ * @example
86
+ *
87
+ * ```typescript
88
+ *
89
+ * // Button locator in this component
90
+ * get locatorButton() {
91
+ * return this.locatorRoot().locator('button').nth(0);
92
+ * }
93
+ * ```
94
+ */
95
+ get locatorRoot(): Locator;
96
+ /**
97
+ * Returns the root selector for the component
98
+ * This method must be usually overriden to return the css selector of your component
99
+ *
100
+ * @example
101
+ *
102
+ * ```typescript
103
+ * getComponentSelector(): string {
104
+ * return 'app-component';
105
+ * }
106
+ * ```
107
+ * Will target the html component:
108
+ * ```html
109
+ * <app-component>...</app-component>
110
+ * ```
111
+ */
112
+ getComponentSelector(): string;
113
+ /**
114
+ * Wait for the locatorRoot to be displayed in the page
115
+ */
116
+ waitLoaded(): Promise<void>;
117
+ }
package/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var f=Object.defineProperty;var g=o=>{throw TypeError(o)};var m=(o,t,e)=>t in o?f(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var p=(o,t,e)=>m(o,typeof t!="symbol"?t+"":t,e),d=(o,t,e)=>t.has(o)||g("Cannot "+e);var s=(o,t,e)=>(d(o,t,"read from private field"),e?e.call(o):t.get(o)),c=(o,t,e)=>t.has(o)?g("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(o):t.set(o,e),n=(o,t,e,i)=>(d(o,t,"write to private field"),i?i.call(o,e):t.set(o,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function h(o){return"waitFor"in o}var r,a,l;class R{constructor(t,e=null){c(this,r);c(this,a);c(this,l);p(this,"_page");n(this,r,t),n(this,a,e),this._page=h(t)?t.page():t}get locatorRoot(){let t=s(this,l);if(!t){const e=this.getComponentSelector();let i=s(this,r);if(e){i=i.locator(e);const u=s(this,a);u!==null&&(i=i.nth(u))}t=h(i)?i:i.locator("html"),n(this,l,t)}return t}getComponentSelector(){return""}async waitLoaded(){h(this.locatorRoot)&&await this.locatorRoot.waitFor()}}r=new WeakMap,a=new WeakMap,l=new WeakMap;exports.BasePO=R;
package/index.js ADDED
@@ -0,0 +1,88 @@
1
+ var f = Object.defineProperty;
2
+ var u = (o) => {
3
+ throw TypeError(o);
4
+ };
5
+ var m = (o, t, e) => t in o ? f(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
6
+ var g = (o, t, e) => m(o, typeof t != "symbol" ? t + "" : t, e), R = (o, t, e) => t.has(o) || u("Cannot " + e);
7
+ var l = (o, t, e) => (R(o, t, "read from private field"), e ? e.call(o) : t.get(o)), s = (o, t, e) => t.has(o) ? u("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(o) : t.set(o, e), n = (o, t, e, i) => (R(o, t, "write to private field"), i ? i.call(o, e) : t.set(o, e), e);
8
+ function h(o) {
9
+ return "waitFor" in o;
10
+ }
11
+ var r, a, c;
12
+ class w {
13
+ /**
14
+ *
15
+ * @param container - Container locator (page if there is no container) where the component is located
16
+ * @param index - If you have multiple components **inside the container**, you must provide the index to select the component to work with. You can omit this parameter if you have a single component.
17
+ */
18
+ constructor(t, e = null) {
19
+ s(this, r);
20
+ s(this, a);
21
+ s(this, c);
22
+ /**
23
+ * Playwright page object from which the page object has been created.
24
+ * It can be convenient for situation where you can't work (internally) with the locatorRoot
25
+ */
26
+ g(this, "_page");
27
+ n(this, r, t), n(this, a, e), this._page = h(t) ? t.page() : t;
28
+ }
29
+ /**
30
+ * The root locator of your page object.
31
+ * It can be used to be chain with internal locators.
32
+ *
33
+ * It is built with the provided `container` from the constructor, the `getComponentSelector` (one of them must be provided, at least) and the optional `index` parameter from the contructor.
34
+ *
35
+ * @example
36
+ *
37
+ * ```typescript
38
+ *
39
+ * // Button locator in this component
40
+ * get locatorButton() {
41
+ * return this.locatorRoot().locator('button').nth(0);
42
+ * }
43
+ * ```
44
+ */
45
+ get locatorRoot() {
46
+ let t = l(this, c);
47
+ if (!t) {
48
+ const e = this.getComponentSelector();
49
+ let i = l(this, r);
50
+ if (e) {
51
+ i = i.locator(e);
52
+ const p = l(this, a);
53
+ p !== null && (i = i.nth(p));
54
+ }
55
+ t = h(i) ? i : i.locator("html"), n(this, c, t);
56
+ }
57
+ return t;
58
+ }
59
+ /**
60
+ * Returns the root selector for the component
61
+ * This method must be usually overriden to return the css selector of your component
62
+ *
63
+ * @example
64
+ *
65
+ * ```typescript
66
+ * getComponentSelector(): string {
67
+ * return 'app-component';
68
+ * }
69
+ * ```
70
+ * Will target the html component:
71
+ * ```html
72
+ * <app-component>...</app-component>
73
+ * ```
74
+ */
75
+ getComponentSelector() {
76
+ return "";
77
+ }
78
+ /**
79
+ * Wait for the locatorRoot to be displayed in the page
80
+ */
81
+ async waitLoaded() {
82
+ h(this.locatorRoot) && await this.locatorRoot.waitFor();
83
+ }
84
+ }
85
+ r = new WeakMap(), a = new WeakMap(), c = new WeakMap();
86
+ export {
87
+ w as BasePO
88
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agnos-ui/base-po",
3
3
  "description": "Base class to build page objects for end-to-end tests with Playwright.",
4
- "version": "0.6.0-next.1",
4
+ "version": "0.6.0",
5
5
  "keywords": [
6
6
  "e2e",
7
7
  "page-object",
@@ -9,50 +9,9 @@
9
9
  "testing"
10
10
  ],
11
11
  "type": "module",
12
- "main": "./dist/index.cjs",
13
- "module": "./dist/index.js",
14
- "types": "./dist/index.d.ts",
15
- "scripts": {
16
- "build": "wireit"
17
- },
18
- "wireit": {
19
- "build:src": {
20
- "command": "vite build && tsc -p tsconfig.build.json",
21
- "files": [
22
- "lib/**",
23
- "tsconfig.build.json",
24
- "../tsconfig.json",
25
- "vite.config.ts"
26
- ],
27
- "output": [
28
- "dist/**",
29
- "!dist/package.json",
30
- "!dist/README.md"
31
- ]
32
- },
33
- "build:pkg": {
34
- "command": "node ../scripts/buildPackageJson.js . dist",
35
- "dependencies": [
36
- "build:src"
37
- ],
38
- "files": [
39
- "../scripts/buildPackageJson.js",
40
- "../package.json",
41
- "package.json",
42
- "README.md"
43
- ],
44
- "output": [
45
- "dist/README.md",
46
- "dist/package.json"
47
- ]
48
- },
49
- "build": {
50
- "dependencies": [
51
- "build:src",
52
- "build:pkg"
53
- ]
54
- }
55
- },
12
+ "main": "./index.cjs",
13
+ "module": "./index.js",
14
+ "types": "./index.d.ts",
56
15
  "peerDependencies": {
57
16
  "@playwright/test": "^1.49.0"
58
17
  },
@@ -62,5 +21,6 @@
62
21
  "type": "git",
63
22
  "url": "git+https://github.com/AmadeusITGroup/AgnosUI.git",
64
23
  "directory": "base-po"
65
- }
66
- }
24
+ },
25
+ "homepage": "https://www.agnosui.dev/latest/"
26
+ }
package/lib/base.po.ts DELETED
@@ -1,159 +0,0 @@
1
- import type {Page, Locator} from '@playwright/test';
2
-
3
- function isLocator(locator: Page | Locator): locator is Locator {
4
- return 'waitFor' in locator;
5
- }
6
-
7
- /**
8
- * Base class to be extended for page objects.
9
- * The purpose of this architecture is to standardize the way locators are created in the page object, to be able to target precisely the dom elements you want to interact with.
10
- *
11
- * The constructor takes two parameters:
12
- *
13
- * - `container: Page | Locator` is the container locator from which other locators are built
14
- * - `index: number | null = null` is the nth index component found in the container locator
15
- *
16
- * Page objects must usually override the `getComponentSelector()` method to return the html selector of the component
17
- *
18
- * @example
19
- *
20
- * ```html
21
- * <!-- page.html -->
22
- * <div class="component1">
23
- * <div class="component2">
24
- * <button>Click me</button>
25
- * </div>
26
- * <div class="component2">
27
- * <button>Click me</button>
28
- * </div>
29
- * </div>
30
- * ```
31
- *
32
- * ```typescript
33
- * // component1.po.ts
34
- * export Component1Page extends BasePo {
35
- * getComponentSelector(): string {
36
- * return 'div.component1';
37
- * }
38
- * }
39
- *
40
- * // component2.po.ts
41
- * export Component2Page extends BasePo {
42
- * getComponentSelector(): string {
43
- * return 'div.component2';
44
- * }
45
- *
46
- * // Button locator in component2
47
- * get locatorButton() {
48
- * return this.locatorRoot.locator('button');
49
- * }
50
- * }
51
- *
52
- * // test.spec.ts
53
- * test('should click', ({page}) => {
54
- *
55
- * // will manage the component1 section
56
- * const component1Po = new Component1Page(page);
57
- *
58
- * // click on the button of the first component2 of component1
59
- * const firstComponent2Po = new Component2Page(component1Po.locatorRoot);
60
- * await firstComponent2Po.locatorButton.click();
61
- *
62
- * // click on the button of the second component2 of component1
63
- * const secondComponent2Po = new Component2Page(component1Po.locatorRoot, 1);
64
- * await secondComponent2Po.locatorButton.click();
65
- *
66
- * });
67
- *
68
- * ```
69
- *
70
- */
71
- export class BasePO {
72
- readonly #container: Page | Locator;
73
- readonly #index: number | null;
74
- #locatorRoot: Locator | undefined;
75
-
76
- /**
77
- * Playwright page object from which the page object has been created.
78
- * It can be convenient for situation where you can't work (internally) with the locatorRoot
79
- */
80
- protected _page: Page;
81
-
82
- /**
83
- *
84
- * @param container - Container locator (page if there is no container) where the component is located
85
- * @param index - If you have multiple components **inside the container**, you must provide the index to select the component to work with. You can omit this parameter if you have a single component.
86
- */
87
- constructor(container: Page | Locator, index: number | null = null) {
88
- this.#container = container;
89
- this.#index = index;
90
- this._page = isLocator(container) ? container.page() : container;
91
- }
92
-
93
- /**
94
- * The root locator of your page object.
95
- * It can be used to be chain with internal locators.
96
- *
97
- * It is built with the provided `container` from the constructor, the `getComponentSelector` (one of them must be provided, at least) and the optional `index` parameter from the contructor.
98
- *
99
- * @example
100
- *
101
- * ```typescript
102
- *
103
- * // Button locator in this component
104
- * get locatorButton() {
105
- * return this.locatorRoot().locator('button').nth(0);
106
- * }
107
- * ```
108
- */
109
- get locatorRoot(): Locator {
110
- let locatorRoot = this.#locatorRoot;
111
- if (!locatorRoot) {
112
- const componentSelector = this.getComponentSelector();
113
- let tmpLocatorRoot = this.#container;
114
-
115
- if (componentSelector) {
116
- tmpLocatorRoot = tmpLocatorRoot.locator(componentSelector);
117
-
118
- // Use the nth engine : https://playwright.dev/docs/selectors#n-th-element-selector
119
- const index = this.#index;
120
- if (index !== null) {
121
- tmpLocatorRoot = tmpLocatorRoot.nth(index);
122
- }
123
- }
124
-
125
- locatorRoot = isLocator(tmpLocatorRoot) ? tmpLocatorRoot : tmpLocatorRoot.locator('html');
126
- this.#locatorRoot = locatorRoot;
127
- }
128
- return locatorRoot;
129
- }
130
-
131
- /**
132
- * Returns the root selector for the component
133
- * This method must be usually overriden to return the css selector of your component
134
- *
135
- * @example
136
- *
137
- * ```typescript
138
- * getComponentSelector(): string {
139
- * return 'app-component';
140
- * }
141
- * ```
142
- * Will target the html component:
143
- * ```html
144
- * <app-component>...</app-component>
145
- * ```
146
- */
147
- getComponentSelector(): string {
148
- return '';
149
- }
150
-
151
- /**
152
- * Wait for the locatorRoot to be displayed in the page
153
- */
154
- async waitLoaded() {
155
- if (isLocator(this.locatorRoot)) {
156
- await this.locatorRoot.waitFor();
157
- }
158
- }
159
- }
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "../tsconfig.json",
3
- "compilerOptions": {
4
- "noEmit": false,
5
- "emitDeclarationOnly": true,
6
- "outDir": "dist",
7
- "declaration": true
8
- },
9
- "include": ["lib"]
10
- }
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "../tsconfig.json",
3
- "include": ["lib"],
4
- "files": ["vite.config.ts"]
5
- }
package/vite.config.ts DELETED
@@ -1,17 +0,0 @@
1
- import {peerDependencies} from './package.json';
2
- import {defineConfig} from 'vite';
3
-
4
- // https://vitejs.dev/config/
5
- export default defineConfig({
6
- build: {
7
- lib: {
8
- entry: 'lib/index',
9
- fileName: 'index',
10
- formats: ['es', 'cjs'],
11
- },
12
- rollupOptions: {
13
- external: [...Object.keys(peerDependencies)],
14
- },
15
- emptyOutDir: true,
16
- },
17
- });
File without changes