pw-element-interactions 0.0.1 → 0.0.2

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 CHANGED
@@ -7,6 +7,7 @@ A robust set of Playwright steps for readable interaction and assertions.
7
7
  `pw-element-interactions` pairs perfectly with `pw-element-repository` to achieve a fully decoupled test automation architecture. By separating **Element Acquisition** from **Element Interaction**, your test scripts become highly readable, easily maintainable, and completely free of raw locators.
8
8
 
9
9
  ### ✨ The Unified Steps API
10
+
10
11
  With the introduction of the `Steps` class, you can now combine your element repository and interactions into a single, flattened Facade. This eliminates repetitive locator fetching and transforms your tests into clean, plain-English steps.
11
12
 
12
13
  ---
@@ -15,7 +16,7 @@ With the introduction of the `Steps` class, you can now combine your element rep
15
16
 
16
17
  Install the package via your preferred package manager:
17
18
 
18
- ``` bash
19
+ ```bash
19
20
  npm i pw-element-interactions
20
21
  ```
21
22
 
@@ -36,11 +37,11 @@ This package requires `@playwright/test` to be installed in your project. If you
36
37
 
37
38
  ## 💻 Usage: The `Steps` API (Recommended)
38
39
 
39
- Initialize the `Steps` class by passing the current Playwright `page` object and your `ElementRepository` instance.
40
+ Initialize the `Steps` class by passing the current Playwright `page` object and your `ElementRepository` instance.
40
41
 
41
42
  ### Example Scenario
42
43
 
43
- ``` ts
44
+ ```ts
44
45
  import { test } from '@playwright/test';
45
46
  import { ElementRepository } from 'pw-element-repository';
46
47
  import { Steps } from 'pw-element-interactions';
@@ -75,34 +76,40 @@ test('Add random product and verify image gallery', async ({ page }) => {
75
76
 
76
77
  The `Steps` class automatically handles fetching the Playwright `Locator` using your `pageName` and `elementName` keys from the repository.
77
78
 
78
- ### 🧭 Navigation Steps
79
- * **`MapsTo(url)`**: Navigates the browser to the specified URL.
79
+ ### 🧭 Navigation
80
+
81
+ * **`MapsTo(url: string)`**: Navigates the browser to the specified absolute or relative URL.
80
82
  * **`refresh()`**: Reloads the current page.
81
83
 
82
- ### 🖱️ Interaction Steps
83
- * **`click(pageName, elementName)`**: Standard click. Automatically waits for actionability.
84
- * **`clickRandom(pageName, elementName)`**: Resolves a list of elements and clicks a random one.
85
- * **`clickIfPresent(pageName, elementName)`**: Safely clicks an element only if it is visible. Prevents failures on optional UI elements like cookie banners.
86
- * **`fill(pageName, elementName, text)`**: Clears the input and types the provided text.
87
- * **`uploadFile(pageName, elementName, filePath)`**: Uploads a local file to a specific `<input type="file">`.
88
- * **`selectDropdown(pageName, elementName, options?)`**: Interacts with `<select>` elements. Returns the selected value. Accepts:
89
- * `{ type: 'random' }` *(Default)* - Selects a random, non-disabled option with a valid value.
90
- * `{ type: 'value', value: 'string' }` - Selects by exact value.
91
- * `{ type: 'index', index: 1 }` - Selects by index.
92
-
93
- ### ✅ Verification Steps
94
- * **`verifyPresence(pageName, elementName)`**: Asserts the element is visible in the DOM.
95
- * **`verifyAbsence(pageName, elementName)`**: Asserts the element is hidden or detached.
96
- * **`verifyText(pageName, elementName, expectedText)`**: Asserts exact text match.
97
- * **`verifyImages(pageName, elementName, scroll?)`**: Robust image verification. Scrolls into view, checks visibility, asserts `src`, checks `naturalWidth > 0`, and evaluates the native `HTMLImageElement.decode()` promise.
98
- * **`verifyUrlContains(text)`**: Asserts the active browser URL contains a specific substring.
84
+ ### 🖱️ Interaction
85
+
86
+ * **`click(pageName: string, elementName: string)`**: Retrieves an element from the repository and performs a standard click. Automatically waits for actionability.
87
+ * **`clickRandom(pageName: string, elementName: string)`**: Retrieves a random element from a resolved list of locators and clicks it. Useful for clicking random items in a list or grid.
88
+ * **`clickIfPresent(pageName: string, elementName: string)`**: Retrieves an element and clicks it only if it is visible. Prevents test failures on optional UI elements like cookie banners or promotional pop-ups.
89
+ * **`fill(pageName: string, elementName: string, text: string)`**: Retrieves an input field and fills it with the provided text, replacing any existing value.
90
+ * **`uploadFile(pageName: string, elementName: string, filePath: string)`**: Retrieves an `<input type="file">` and uploads the file from the provided local `filePath`.
91
+ * **`selectDropdown(pageName: string, elementName: string, options?: DropdownSelectOptions)`**: Interacts with `<select>` dropdown elements. Returns the exact `value` attribute of the selected option. Accepts:
92
+ * `{ type: 'random' }` *(Default)* - Selects a random, non-disabled option with a valid value.
93
+ * `{ type: 'value', value: 'string' }` - Selects by exact value.
94
+ * `{ type: 'index', index: 1 }` - Selects by index.
95
+
96
+
97
+
98
+ ### Verification
99
+
100
+ * **`verifyPresence(pageName: string, elementName: string)`**: Asserts that a specified element is attached to the DOM and is visible.
101
+ * **`verifyAbsence(pageName: string, elementName: string)`**: Asserts that a specified element is hidden or completely detached from the DOM.
102
+ * **`verifyText(pageName: string, elementName: string, expectedText: string)`**: Asserts that the specified element exactly matches the expected text.
103
+ * **`verifyImages(pageName: string, elementName: string, scroll?: boolean)`**: Performs a rigorous verification of one or more images. Asserts visibility, checks for a valid `src` attribute, ensures `naturalWidth > 0`, and evaluates the native browser `decode()` promise. Smoothly scrolls into view by default (`scroll: true`).
104
+ * **`verifyUrlContains(text: string)`**: Asserts that the active browser URL contains the expected substring.
99
105
 
100
106
  ---
101
107
 
102
108
  ## 🧱 Advanced Usage: Raw Interactions API
103
109
 
104
110
  If you need to bypass the repository or interact with custom locators dynamically generated in your tests, you can use the underlying `ElementInteractions` class directly.
105
- ``` ts
111
+
112
+ ```ts
106
113
  import { ElementInteractions } from 'pw-element-interactions';
107
114
 
108
115
  // Initialize
@@ -113,4 +120,5 @@ const customLocator = page.locator('button.dynamic-class');
113
120
  await interactions.interact.clickWithoutScrolling(customLocator);
114
121
  await interactions.verify.state(customLocator, 'enabled');
115
122
  ```
116
- *Note: All core interaction (`interact`), verification (`verify`), and navigation (`Maps`) methods are available when using `ElementInteractions` directly.*
123
+
124
+ *Note: All core interaction (`interact`), verification (`verify`), and navigation (`Maps`) methods are also available when using `ElementInteractions` directly.*
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { ElementInteractions } from './ElementInteractions';
2
+ export { Steps } from '../src/steps/CommonSteps';
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ElementInteractions = void 0;
3
+ exports.Steps = exports.ElementInteractions = void 0;
4
4
  var ElementInteractions_1 = require("./ElementInteractions");
5
5
  Object.defineProperty(exports, "ElementInteractions", { enumerable: true, get: function () { return ElementInteractions_1.ElementInteractions; } });
6
+ var CommonSteps_1 = require("../src/steps/CommonSteps");
7
+ Object.defineProperty(exports, "Steps", { enumerable: true, get: function () { return CommonSteps_1.Steps; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pw-element-interactions",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A robust, readable interaction and assertion Facade for Playwright. Abstract away boilerplate into semantic, English-like methods, making your test automation framework cleaner, easier to maintain, and accessible to non-developers.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -43,4 +43,4 @@
43
43
  },
44
44
  "author": "Umut Ay Bora",
45
45
  "license": "MIT"
46
- }
46
+ }