@badisi/wdio-harness 4.2.2 → 4.3.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/README.md CHANGED
@@ -57,6 +57,7 @@ __Methods__
57
57
  __Example__
58
58
 
59
59
  ```ts
60
+ import '@angular/compiler'; // required since Angular v21
60
61
  import { MatDatepickerInputHarness } from '@angular/material/datepicker/testing';
61
62
  import { getHarness } from '@badisi/wdio-harness';
62
63
 
@@ -1,4 +1,4 @@
1
- import { ComponentHarness, ComponentHarnessConstructor, HarnessEnvironment } from '@angular/cdk/testing';
1
+ import { type ComponentHarness, type ComponentHarnessConstructor, HarnessEnvironment } from '@angular/cdk/testing';
2
2
  import { WebdriverIOTestElement } from './WebdriverIOTestElement.js';
3
3
  /**
4
4
  * A `HarnessEnvironment` implementation for WebdriverIO.
@@ -1,8 +1,7 @@
1
1
  import { HarnessEnvironment } from '@angular/cdk/testing';
2
2
  import logger from '@wdio/logger';
3
3
  import { WebdriverIOTestElement } from './WebdriverIOTestElement.js';
4
- import colors from '@colors/colors/safe.js';
5
- const { magenta, green } = colors;
4
+ import { green, magenta } from './utils';
6
5
  /** Registers the environment logger. */
7
6
  const log = logger('wdio-harness');
8
7
  /**
@@ -1,4 +1,4 @@
1
- import { ElementDimensions, EventData, ModifierKeys, TestElement, TestKey, TextOptions } from '@angular/cdk/testing';
1
+ import { type ElementDimensions, type EventData, type ModifierKeys, type TestElement, TestKey, type TextOptions } from '@angular/cdk/testing';
2
2
  /** Module augmentation to expose the host element as a public api */
3
3
  declare module '@angular/cdk/testing' {
4
4
  interface ComponentHarness {
@@ -62,6 +62,11 @@ export declare class WebdriverIOTestElement implements TestElement {
62
62
  sendKeys(modifiers: ModifierKeys, ...keys: (string | TestKey)[]): Promise<void>;
63
63
  /** Gets the text from the element. */
64
64
  text(options?: TextOptions): Promise<string>;
65
+ /**
66
+ * Sets the value of a `contenteditable` element.
67
+ * @param value Value to be set on the element.
68
+ */
69
+ setContenteditableValue(value: string): Promise<void>;
65
70
  /** Gets the value for the given attribute from the element. */
66
71
  getAttribute(name: string): Promise<string | null>;
67
72
  /** Checks whether the element has the given class. */
@@ -1,8 +1,7 @@
1
- import { TestKey, ComponentHarness } from '@angular/cdk/testing';
1
+ import { ComponentHarness, TestKey } from '@angular/cdk/testing';
2
2
  import { browser } from '@wdio/globals';
3
3
  import logger from '@wdio/logger';
4
- import colors from '@colors/colors/safe.js';
5
- const { magenta, green } = colors;
4
+ import { green, magenta } from './utils';
6
5
  var Button;
7
6
  (function (Button) {
8
7
  Button["LEFT"] = "left";
@@ -160,6 +159,19 @@ export class WebdriverIOTestElement {
160
159
  // We don't go through WebdriverIO's `getText`, because it excludes text from hidden elements.
161
160
  return browser.executeScript(`return (arguments[0].textContent ?? '').trim()`, [this.hostElement]);
162
161
  }
162
+ /**
163
+ * Sets the value of a `contenteditable` element.
164
+ * @param value Value to be set on the element.
165
+ */
166
+ async setContenteditableValue(value) {
167
+ const contenteditableAttr = await this.getAttribute('contenteditable');
168
+ if (contenteditableAttr !== '' &&
169
+ contenteditableAttr !== 'true' &&
170
+ contenteditableAttr !== 'plaintext-only') {
171
+ throw new Error('setContenteditableValue can only be called on a `contenteditable` element.');
172
+ }
173
+ return browser.executeScript('arguments[0].textContent = arguments[1];', [this.hostElement, value]);
174
+ }
163
175
  /** Gets the value for the given attribute from the element. */
164
176
  async getAttribute(name) {
165
177
  this.logAction('GET_ATTRIBUTE', name);
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ComponentHarness, HarnessQuery } from '@angular/cdk/testing';
1
+ import type { ComponentHarness, HarnessQuery } from '@angular/cdk/testing';
2
2
  import { WebdriverIOHarnessEnvironment } from './WebdriverIOHarnessEnvironment.js';
3
3
  /**
4
4
  * Searches for all instances of the component corresponding to the given harness type under the
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { browser, $ } from '@wdio/globals';
1
+ import { $, browser } from '@wdio/globals';
2
2
  import { WebdriverIOHarnessEnvironment } from './WebdriverIOHarnessEnvironment.js';
3
3
  /**
4
4
  * Searches for all instances of the component corresponding to the given harness type under the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@badisi/wdio-harness",
3
- "version": "4.2.2",
3
+ "version": "4.3.1",
4
4
  "description": "WebdriverIO support for Angular component test harnesses.",
5
5
  "homepage": "https://github.com/Badisi/wdio-harness",
6
6
  "license": "MIT",
@@ -39,11 +39,8 @@
39
39
  "node": "^16.14.0 || >=18.10.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@angular/cdk": ">= 13 < 21",
42
+ "@angular/cdk": ">= 13 < 22",
43
43
  "@wdio/logger": ">= 9 < 10",
44
44
  "webdriverio": ">= 9 < 10"
45
- },
46
- "dependencies": {
47
- "@colors/colors": "^1.6.0"
48
45
  }
49
46
  }
package/utils.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const magenta: (msg: string) => string;
2
+ declare const green: (msg: string) => string;
3
+ export { magenta, green };
package/utils.js ADDED
@@ -0,0 +1,4 @@
1
+ const colorize = (msg, color) => process.stdout.isTTY ? `${color}${msg}\x1b[0m` : msg;
2
+ const magenta = (msg) => colorize(msg, '\x1b[35m');
3
+ const green = (msg) => colorize(msg, '\x1b[32m');
4
+ export { magenta, green };