@angular/cdk 21.0.0-next.8 → 21.0.0-rc.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.
Files changed (124) hide show
  1. package/_adev_assets/cdk_drag_drop.json +13 -12
  2. package/_adev_assets/cdk_testing.json +15 -25
  3. package/_adev_assets/cdk_testing_protractor.json +1 -1
  4. package/_adev_assets/cdk_testing_selenium_webdriver.json +1 -1
  5. package/_adev_assets/cdk_testing_testbed.json +1 -1
  6. package/fesm2022/_a11y-module-chunk.mjs +755 -869
  7. package/fesm2022/_a11y-module-chunk.mjs.map +1 -1
  8. package/fesm2022/_activedescendant-key-manager-chunk.mjs +8 -8
  9. package/fesm2022/_activedescendant-key-manager-chunk.mjs.map +1 -1
  10. package/fesm2022/_array-chunk.mjs +1 -1
  11. package/fesm2022/_array-chunk.mjs.map +1 -1
  12. package/fesm2022/_breakpoints-observer-chunk.mjs +149 -152
  13. package/fesm2022/_breakpoints-observer-chunk.mjs.map +1 -1
  14. package/fesm2022/_css-pixel-value-chunk.mjs +4 -5
  15. package/fesm2022/_css-pixel-value-chunk.mjs.map +1 -1
  16. package/fesm2022/_data-source-chunk.mjs +2 -8
  17. package/fesm2022/_data-source-chunk.mjs.map +1 -1
  18. package/fesm2022/_directionality-chunk.mjs +54 -54
  19. package/fesm2022/_directionality-chunk.mjs.map +1 -1
  20. package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs +25 -36
  21. package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs.map +1 -1
  22. package/fesm2022/_element-chunk.mjs +6 -17
  23. package/fesm2022/_element-chunk.mjs.map +1 -1
  24. package/fesm2022/_fake-event-detection-chunk.mjs +3 -17
  25. package/fesm2022/_fake-event-detection-chunk.mjs.map +1 -1
  26. package/fesm2022/_focus-key-manager-chunk.mjs +10 -14
  27. package/fesm2022/_focus-key-manager-chunk.mjs.map +1 -1
  28. package/fesm2022/_focus-monitor-chunk.mjs +376 -566
  29. package/fesm2022/_focus-monitor-chunk.mjs.map +1 -1
  30. package/fesm2022/_id-generator-chunk.mjs +36 -27
  31. package/fesm2022/_id-generator-chunk.mjs.map +1 -1
  32. package/fesm2022/_keycodes-chunk.mjs +9 -9
  33. package/fesm2022/_keycodes-chunk.mjs.map +1 -1
  34. package/fesm2022/_list-key-manager-chunk.mjs +248 -336
  35. package/fesm2022/_list-key-manager-chunk.mjs.map +1 -1
  36. package/fesm2022/_overlay-module-chunk.mjs +2534 -2948
  37. package/fesm2022/_overlay-module-chunk.mjs.map +1 -1
  38. package/fesm2022/_passive-listeners-chunk.mjs +10 -22
  39. package/fesm2022/_passive-listeners-chunk.mjs.map +1 -1
  40. package/fesm2022/_platform-chunk.mjs +42 -65
  41. package/fesm2022/_platform-chunk.mjs.map +1 -1
  42. package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs +78 -134
  43. package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs.map +1 -1
  44. package/fesm2022/_scrolling-chunk.mjs +44 -85
  45. package/fesm2022/_scrolling-chunk.mjs.map +1 -1
  46. package/fesm2022/_selection-model-chunk.mjs +138 -209
  47. package/fesm2022/_selection-model-chunk.mjs.map +1 -1
  48. package/fesm2022/_shadow-dom-chunk.mjs +21 -35
  49. package/fesm2022/_shadow-dom-chunk.mjs.map +1 -1
  50. package/fesm2022/_style-loader-chunk.mjs +50 -37
  51. package/fesm2022/_style-loader-chunk.mjs.map +1 -1
  52. package/fesm2022/_test-environment-chunk.mjs +2 -14
  53. package/fesm2022/_test-environment-chunk.mjs.map +1 -1
  54. package/fesm2022/_tree-key-manager-chunk.mjs +229 -308
  55. package/fesm2022/_tree-key-manager-chunk.mjs.map +1 -1
  56. package/fesm2022/_typeahead-chunk.mjs +52 -74
  57. package/fesm2022/_typeahead-chunk.mjs.map +1 -1
  58. package/fesm2022/_unique-selection-dispatcher-chunk.mjs +43 -40
  59. package/fesm2022/_unique-selection-dispatcher-chunk.mjs.map +1 -1
  60. package/fesm2022/a11y.mjs +351 -449
  61. package/fesm2022/a11y.mjs.map +1 -1
  62. package/fesm2022/accordion.mjs +254 -192
  63. package/fesm2022/accordion.mjs.map +1 -1
  64. package/fesm2022/bidi.mjs +121 -64
  65. package/fesm2022/bidi.mjs.map +1 -1
  66. package/fesm2022/cdk.mjs +1 -2
  67. package/fesm2022/cdk.mjs.map +1 -1
  68. package/fesm2022/clipboard.mjs +208 -186
  69. package/fesm2022/clipboard.mjs.map +1 -1
  70. package/fesm2022/coercion-private.mjs +4 -8
  71. package/fesm2022/coercion-private.mjs.map +1 -1
  72. package/fesm2022/coercion.mjs +11 -29
  73. package/fesm2022/coercion.mjs.map +1 -1
  74. package/fesm2022/dialog.mjs +660 -808
  75. package/fesm2022/dialog.mjs.map +1 -1
  76. package/fesm2022/drag-drop.mjs +3347 -4286
  77. package/fesm2022/drag-drop.mjs.map +1 -1
  78. package/fesm2022/keycodes.mjs +4 -8
  79. package/fesm2022/keycodes.mjs.map +1 -1
  80. package/fesm2022/layout.mjs +44 -26
  81. package/fesm2022/layout.mjs.map +1 -1
  82. package/fesm2022/listbox.mjs +841 -895
  83. package/fesm2022/listbox.mjs.map +1 -1
  84. package/fesm2022/menu.mjs +1942 -1858
  85. package/fesm2022/menu.mjs.map +1 -1
  86. package/fesm2022/observers-private.mjs +88 -106
  87. package/fesm2022/observers-private.mjs.map +1 -1
  88. package/fesm2022/observers.mjs +262 -184
  89. package/fesm2022/observers.mjs.map +1 -1
  90. package/fesm2022/overlay.mjs +72 -68
  91. package/fesm2022/overlay.mjs.map +1 -1
  92. package/fesm2022/platform.mjs +43 -54
  93. package/fesm2022/platform.mjs.map +1 -1
  94. package/fesm2022/portal.mjs +402 -560
  95. package/fesm2022/portal.mjs.map +1 -1
  96. package/fesm2022/private.mjs +38 -10
  97. package/fesm2022/private.mjs.map +1 -1
  98. package/fesm2022/scrolling.mjs +1323 -1400
  99. package/fesm2022/scrolling.mjs.map +1 -1
  100. package/fesm2022/stepper.mjs +758 -590
  101. package/fesm2022/stepper.mjs.map +1 -1
  102. package/fesm2022/table.mjs +2327 -2319
  103. package/fesm2022/table.mjs.map +1 -1
  104. package/fesm2022/testing-selenium-webdriver.mjs +252 -325
  105. package/fesm2022/testing-selenium-webdriver.mjs.map +1 -1
  106. package/fesm2022/testing-testbed.mjs +592 -709
  107. package/fesm2022/testing-testbed.mjs.map +1 -1
  108. package/fesm2022/testing.mjs +368 -889
  109. package/fesm2022/testing.mjs.map +1 -1
  110. package/fesm2022/text-field.mjs +459 -388
  111. package/fesm2022/text-field.mjs.map +1 -1
  112. package/fesm2022/tree.mjs +1483 -1731
  113. package/fesm2022/tree.mjs.map +1 -1
  114. package/overlay/_index.scss +28 -0
  115. package/overlay-prebuilt.css +1 -1
  116. package/package.json +1 -1
  117. package/schematics/ng-add/index.js +1 -1
  118. package/types/_harness-environment-chunk.d.ts +1 -2
  119. package/types/_overlay-module-chunk.d.ts +59 -7
  120. package/types/_portal-directives-chunk.d.ts +2 -18
  121. package/types/accordion.d.ts +3 -1
  122. package/types/dialog.d.ts +1 -1
  123. package/types/overlay.d.ts +6 -2
  124. package/types/portal.d.ts +1 -1
@@ -2,351 +2,278 @@ import * as webdriver from 'selenium-webdriver';
2
2
  import { TestKey, getNoKeysSpecifiedError, _getTextWithExcludedElements, HarnessEnvironment } from './testing.mjs';
3
3
  import 'rxjs';
4
4
 
5
- /**
6
- * Maps the `TestKey` constants to WebDriver's `webdriver.Key` constants.
7
- * See https://github.com/SeleniumHQ/selenium/blob/trunk/javascript/webdriver/key.js#L29
8
- */
9
5
  const seleniumWebDriverKeyMap = {
10
- [TestKey.BACKSPACE]: webdriver.Key.BACK_SPACE,
11
- [TestKey.TAB]: webdriver.Key.TAB,
12
- [TestKey.ENTER]: webdriver.Key.ENTER,
13
- [TestKey.SHIFT]: webdriver.Key.SHIFT,
14
- [TestKey.CONTROL]: webdriver.Key.CONTROL,
15
- [TestKey.ALT]: webdriver.Key.ALT,
16
- [TestKey.ESCAPE]: webdriver.Key.ESCAPE,
17
- [TestKey.PAGE_UP]: webdriver.Key.PAGE_UP,
18
- [TestKey.PAGE_DOWN]: webdriver.Key.PAGE_DOWN,
19
- [TestKey.END]: webdriver.Key.END,
20
- [TestKey.HOME]: webdriver.Key.HOME,
21
- [TestKey.LEFT_ARROW]: webdriver.Key.ARROW_LEFT,
22
- [TestKey.UP_ARROW]: webdriver.Key.ARROW_UP,
23
- [TestKey.RIGHT_ARROW]: webdriver.Key.ARROW_RIGHT,
24
- [TestKey.DOWN_ARROW]: webdriver.Key.ARROW_DOWN,
25
- [TestKey.INSERT]: webdriver.Key.INSERT,
26
- [TestKey.DELETE]: webdriver.Key.DELETE,
27
- [TestKey.F1]: webdriver.Key.F1,
28
- [TestKey.F2]: webdriver.Key.F2,
29
- [TestKey.F3]: webdriver.Key.F3,
30
- [TestKey.F4]: webdriver.Key.F4,
31
- [TestKey.F5]: webdriver.Key.F5,
32
- [TestKey.F6]: webdriver.Key.F6,
33
- [TestKey.F7]: webdriver.Key.F7,
34
- [TestKey.F8]: webdriver.Key.F8,
35
- [TestKey.F9]: webdriver.Key.F9,
36
- [TestKey.F10]: webdriver.Key.F10,
37
- [TestKey.F11]: webdriver.Key.F11,
38
- [TestKey.F12]: webdriver.Key.F12,
39
- [TestKey.META]: webdriver.Key.META,
40
- [TestKey.COMMA]: ',',
6
+ [TestKey.BACKSPACE]: webdriver.Key.BACK_SPACE,
7
+ [TestKey.TAB]: webdriver.Key.TAB,
8
+ [TestKey.ENTER]: webdriver.Key.ENTER,
9
+ [TestKey.SHIFT]: webdriver.Key.SHIFT,
10
+ [TestKey.CONTROL]: webdriver.Key.CONTROL,
11
+ [TestKey.ALT]: webdriver.Key.ALT,
12
+ [TestKey.ESCAPE]: webdriver.Key.ESCAPE,
13
+ [TestKey.PAGE_UP]: webdriver.Key.PAGE_UP,
14
+ [TestKey.PAGE_DOWN]: webdriver.Key.PAGE_DOWN,
15
+ [TestKey.END]: webdriver.Key.END,
16
+ [TestKey.HOME]: webdriver.Key.HOME,
17
+ [TestKey.LEFT_ARROW]: webdriver.Key.ARROW_LEFT,
18
+ [TestKey.UP_ARROW]: webdriver.Key.ARROW_UP,
19
+ [TestKey.RIGHT_ARROW]: webdriver.Key.ARROW_RIGHT,
20
+ [TestKey.DOWN_ARROW]: webdriver.Key.ARROW_DOWN,
21
+ [TestKey.INSERT]: webdriver.Key.INSERT,
22
+ [TestKey.DELETE]: webdriver.Key.DELETE,
23
+ [TestKey.F1]: webdriver.Key.F1,
24
+ [TestKey.F2]: webdriver.Key.F2,
25
+ [TestKey.F3]: webdriver.Key.F3,
26
+ [TestKey.F4]: webdriver.Key.F4,
27
+ [TestKey.F5]: webdriver.Key.F5,
28
+ [TestKey.F6]: webdriver.Key.F6,
29
+ [TestKey.F7]: webdriver.Key.F7,
30
+ [TestKey.F8]: webdriver.Key.F8,
31
+ [TestKey.F9]: webdriver.Key.F9,
32
+ [TestKey.F10]: webdriver.Key.F10,
33
+ [TestKey.F11]: webdriver.Key.F11,
34
+ [TestKey.F12]: webdriver.Key.F12,
35
+ [TestKey.META]: webdriver.Key.META,
36
+ [TestKey.COMMA]: ','
41
37
  };
42
- /** Gets a list of WebDriver `Key`s for the given `ModifierKeys`. */
43
38
  function getSeleniumWebDriverModifierKeys(modifiers) {
44
- const result = [];
45
- if (modifiers.control) {
46
- result.push(webdriver.Key.CONTROL);
47
- }
48
- if (modifiers.alt) {
49
- result.push(webdriver.Key.ALT);
50
- }
51
- if (modifiers.shift) {
52
- result.push(webdriver.Key.SHIFT);
53
- }
54
- if (modifiers.meta) {
55
- result.push(webdriver.Key.META);
56
- }
57
- return result;
39
+ const result = [];
40
+ if (modifiers.control) {
41
+ result.push(webdriver.Key.CONTROL);
42
+ }
43
+ if (modifiers.alt) {
44
+ result.push(webdriver.Key.ALT);
45
+ }
46
+ if (modifiers.shift) {
47
+ result.push(webdriver.Key.SHIFT);
48
+ }
49
+ if (modifiers.meta) {
50
+ result.push(webdriver.Key.META);
51
+ }
52
+ return result;
58
53
  }
59
54
 
60
- /** A `TestElement` implementation for WebDriver. */
61
55
  class SeleniumWebDriverElement {
62
- element;
63
- _stabilize;
64
- constructor(element, _stabilize) {
65
- this.element = element;
66
- this._stabilize = _stabilize;
67
- }
68
- /** Blur the element. */
69
- async blur() {
70
- await this._executeScript((element) => element.blur(), this.element());
71
- await this._stabilize();
72
- }
73
- /** Clear the element's input (for input and textarea elements only). */
74
- async clear() {
75
- await this.element().clear();
76
- await this._stabilize();
77
- }
78
- async click(...args) {
79
- await this._dispatchClickEventSequence(args, webdriver.Button.LEFT);
80
- await this._stabilize();
81
- }
82
- async rightClick(...args) {
83
- await this._dispatchClickEventSequence(args, webdriver.Button.RIGHT);
84
- await this._stabilize();
85
- }
86
- /** Focus the element. */
87
- async focus() {
88
- await this._executeScript((element) => element.focus(), this.element());
89
- await this._stabilize();
90
- }
91
- /** Get the computed value of the given CSS property for the element. */
92
- async getCssValue(property) {
93
- await this._stabilize();
94
- return this.element().getCssValue(property);
95
- }
96
- /** Hovers the mouse over the element. */
97
- async hover() {
98
- await this._actions().mouseMove(this.element()).perform();
99
- await this._stabilize();
100
- }
101
- /** Moves the mouse away from the element. */
102
- async mouseAway() {
103
- await this._actions().mouseMove(this.element(), { x: -1, y: -1 }).perform();
104
- await this._stabilize();
105
- }
106
- async sendKeys(...modifiersAndKeys) {
107
- const first = modifiersAndKeys[0];
108
- let modifiers;
109
- let rest;
110
- if (first !== undefined && typeof first !== 'string' && typeof first !== 'number') {
111
- modifiers = first;
112
- rest = modifiersAndKeys.slice(1);
113
- }
114
- else {
115
- modifiers = {};
116
- rest = modifiersAndKeys;
117
- }
118
- const modifierKeys = getSeleniumWebDriverModifierKeys(modifiers);
119
- const keys = rest
120
- .map(k => (typeof k === 'string' ? k.split('') : [seleniumWebDriverKeyMap[k]]))
121
- .reduce((arr, k) => arr.concat(k), [])
122
- // webdriver.Key.chord doesn't work well with geckodriver (mozilla/geckodriver#1502),
123
- // so avoid it if no modifier keys are required.
124
- .map(k => (modifierKeys.length > 0 ? webdriver.Key.chord(...modifierKeys, k) : k));
125
- // Throw an error if no keys have been specified. Calling this function with no
126
- // keys should not result in a focus event being dispatched unexpectedly.
127
- if (keys.length === 0) {
128
- throw getNoKeysSpecifiedError();
129
- }
130
- await this.element().sendKeys(...keys);
131
- await this._stabilize();
132
- }
133
- /**
134
- * Gets the text from the element.
135
- * @param options Options that affect what text is included.
136
- */
137
- async text(options) {
138
- await this._stabilize();
139
- if (options?.exclude) {
140
- return this._executeScript(_getTextWithExcludedElements, this.element(), options.exclude);
141
- }
142
- // We don't go through the WebDriver `getText`, because it excludes text from hidden elements.
143
- return this._executeScript((element) => (element.textContent || '').trim(), this.element());
144
- }
145
- /**
146
- * Sets the value of a `contenteditable` element.
147
- * @param value Value to be set on the element.
148
- */
149
- async setContenteditableValue(value) {
150
- const contenteditableAttr = await this.getAttribute('contenteditable');
151
- if (contenteditableAttr !== '' &&
152
- contenteditableAttr !== 'true' &&
153
- contenteditableAttr !== 'plaintext-only') {
154
- throw new Error('setContenteditableValue can only be called on a `contenteditable` element.');
155
- }
156
- await this._stabilize();
157
- return this._executeScript((element, valueToSet) => (element.textContent = valueToSet), this.element(), value);
158
- }
159
- /** Gets the value for the given attribute from the element. */
160
- async getAttribute(name) {
161
- await this._stabilize();
162
- return this._executeScript((element, attribute) => element.getAttribute(attribute), this.element(), name);
163
- }
164
- /** Checks whether the element has the given class. */
165
- async hasClass(name) {
166
- await this._stabilize();
167
- const classes = (await this.getAttribute('class')) || '';
168
- return new Set(classes.split(/\s+/).filter(c => c)).has(name);
169
- }
170
- /** Gets the dimensions of the element. */
171
- async getDimensions() {
172
- await this._stabilize();
173
- const { width, height } = await this.element().getSize();
174
- const { x: left, y: top } = await this.element().getLocation();
175
- return { width, height, left, top };
176
- }
177
- /** Gets the value of a property of an element. */
178
- async getProperty(name) {
179
- await this._stabilize();
180
- return this._executeScript((element, property) => element[property], this.element(), name);
181
- }
182
- /** Sets the value of a property of an input. */
183
- async setInputValue(newValue) {
184
- await this._executeScript((element, value) => (element.value = value), this.element(), newValue);
185
- await this._stabilize();
186
- }
187
- /** Selects the options at the specified indexes inside of a native `select` element. */
188
- async selectOptions(...optionIndexes) {
189
- await this._stabilize();
190
- const options = await this.element().findElements(webdriver.By.css('option'));
191
- const indexes = new Set(optionIndexes); // Convert to a set to remove duplicates.
192
- if (options.length && indexes.size) {
193
- // Reset the value so all the selected states are cleared. We can
194
- // reuse the input-specific method since the logic is the same.
195
- await this.setInputValue('');
196
- for (let i = 0; i < options.length; i++) {
197
- if (indexes.has(i)) {
198
- // We have to hold the control key while clicking on options so that multiple can be
199
- // selected in multi-selection mode. The key doesn't do anything for single selection.
200
- await this._actions().keyDown(webdriver.Key.CONTROL).perform();
201
- await options[i].click();
202
- await this._actions().keyUp(webdriver.Key.CONTROL).perform();
203
- }
204
- }
205
- await this._stabilize();
206
- }
207
- }
208
- /** Checks whether this element matches the given selector. */
209
- async matchesSelector(selector) {
210
- await this._stabilize();
211
- return this._executeScript((element, s) => (Element.prototype.matches || Element.prototype.msMatchesSelector).call(element, s), this.element(), selector);
212
- }
213
- /** Checks whether the element is focused. */
214
- async isFocused() {
215
- await this._stabilize();
216
- return webdriver.WebElement.equals(this.element(), this.element().getDriver().switchTo().activeElement());
217
- }
218
- /**
219
- * Dispatches an event with a particular name.
220
- * @param name Name of the event to be dispatched.
221
- */
222
- async dispatchEvent(name, data) {
223
- await this._executeScript(dispatchEvent, name, this.element(), data);
224
- await this._stabilize();
225
- }
226
- /** Gets the webdriver action sequence. */
227
- _actions() {
228
- return this.element().getDriver().actions();
229
- }
230
- /** Executes a function in the browser. */
231
- async _executeScript(script, ...var_args) {
232
- return this.element()
233
- .getDriver()
234
- .executeScript(script, ...var_args);
235
- }
236
- /** Dispatches all the events that are part of a click event sequence. */
237
- async _dispatchClickEventSequence(args, button) {
238
- let modifiers = {};
239
- if (args.length && typeof args[args.length - 1] === 'object') {
240
- modifiers = args.pop();
241
- }
242
- const modifierKeys = getSeleniumWebDriverModifierKeys(modifiers);
243
- // Omitting the offset argument to mouseMove results in clicking the center.
244
- // This is the default behavior we want, so we use an empty array of offsetArgs if
245
- // no args remain after popping the modifiers from the args passed to this function.
246
- const offsetArgs = (args.length === 2 ? [{ x: args[0], y: args[1] }] : []);
247
- let actions = this._actions().mouseMove(this.element(), ...offsetArgs);
248
- for (const modifierKey of modifierKeys) {
249
- actions = actions.keyDown(modifierKey);
250
- }
251
- actions = actions.click(button);
252
- for (const modifierKey of modifierKeys) {
253
- actions = actions.keyUp(modifierKey);
56
+ element;
57
+ _stabilize;
58
+ constructor(element, _stabilize) {
59
+ this.element = element;
60
+ this._stabilize = _stabilize;
61
+ }
62
+ async blur() {
63
+ await this._executeScript(element => element.blur(), this.element());
64
+ await this._stabilize();
65
+ }
66
+ async clear() {
67
+ await this.element().clear();
68
+ await this._stabilize();
69
+ }
70
+ async click(...args) {
71
+ await this._dispatchClickEventSequence(args, webdriver.Button.LEFT);
72
+ await this._stabilize();
73
+ }
74
+ async rightClick(...args) {
75
+ await this._dispatchClickEventSequence(args, webdriver.Button.RIGHT);
76
+ await this._stabilize();
77
+ }
78
+ async focus() {
79
+ await this._executeScript(element => element.focus(), this.element());
80
+ await this._stabilize();
81
+ }
82
+ async getCssValue(property) {
83
+ await this._stabilize();
84
+ return this.element().getCssValue(property);
85
+ }
86
+ async hover() {
87
+ await this._actions().mouseMove(this.element()).perform();
88
+ await this._stabilize();
89
+ }
90
+ async mouseAway() {
91
+ await this._actions().mouseMove(this.element(), {
92
+ x: -1,
93
+ y: -1
94
+ }).perform();
95
+ await this._stabilize();
96
+ }
97
+ async sendKeys(...modifiersAndKeys) {
98
+ const first = modifiersAndKeys[0];
99
+ let modifiers;
100
+ let rest;
101
+ if (first !== undefined && typeof first !== 'string' && typeof first !== 'number') {
102
+ modifiers = first;
103
+ rest = modifiersAndKeys.slice(1);
104
+ } else {
105
+ modifiers = {};
106
+ rest = modifiersAndKeys;
107
+ }
108
+ const modifierKeys = getSeleniumWebDriverModifierKeys(modifiers);
109
+ const keys = rest.map(k => typeof k === 'string' ? k.split('') : [seleniumWebDriverKeyMap[k]]).reduce((arr, k) => arr.concat(k), []).map(k => modifierKeys.length > 0 ? webdriver.Key.chord(...modifierKeys, k) : k);
110
+ if (keys.length === 0) {
111
+ throw getNoKeysSpecifiedError();
112
+ }
113
+ await this.element().sendKeys(...keys);
114
+ await this._stabilize();
115
+ }
116
+ async text(options) {
117
+ await this._stabilize();
118
+ if (options?.exclude) {
119
+ return this._executeScript(_getTextWithExcludedElements, this.element(), options.exclude);
120
+ }
121
+ return this._executeScript(element => (element.textContent || '').trim(), this.element());
122
+ }
123
+ async setContenteditableValue(value) {
124
+ const contenteditableAttr = await this.getAttribute('contenteditable');
125
+ if (contenteditableAttr !== '' && contenteditableAttr !== 'true' && contenteditableAttr !== 'plaintext-only') {
126
+ throw new Error('setContenteditableValue can only be called on a `contenteditable` element.');
127
+ }
128
+ await this._stabilize();
129
+ return this._executeScript((element, valueToSet) => element.textContent = valueToSet, this.element(), value);
130
+ }
131
+ async getAttribute(name) {
132
+ await this._stabilize();
133
+ return this._executeScript((element, attribute) => element.getAttribute(attribute), this.element(), name);
134
+ }
135
+ async hasClass(name) {
136
+ await this._stabilize();
137
+ const classes = (await this.getAttribute('class')) || '';
138
+ return new Set(classes.split(/\s+/).filter(c => c)).has(name);
139
+ }
140
+ async getDimensions() {
141
+ await this._stabilize();
142
+ const {
143
+ width,
144
+ height
145
+ } = await this.element().getSize();
146
+ const {
147
+ x: left,
148
+ y: top
149
+ } = await this.element().getLocation();
150
+ return {
151
+ width,
152
+ height,
153
+ left,
154
+ top
155
+ };
156
+ }
157
+ async getProperty(name) {
158
+ await this._stabilize();
159
+ return this._executeScript((element, property) => element[property], this.element(), name);
160
+ }
161
+ async setInputValue(newValue) {
162
+ await this._executeScript((element, value) => element.value = value, this.element(), newValue);
163
+ await this._stabilize();
164
+ }
165
+ async selectOptions(...optionIndexes) {
166
+ await this._stabilize();
167
+ const options = await this.element().findElements(webdriver.By.css('option'));
168
+ const indexes = new Set(optionIndexes);
169
+ if (options.length && indexes.size) {
170
+ await this.setInputValue('');
171
+ for (let i = 0; i < options.length; i++) {
172
+ if (indexes.has(i)) {
173
+ await this._actions().keyDown(webdriver.Key.CONTROL).perform();
174
+ await options[i].click();
175
+ await this._actions().keyUp(webdriver.Key.CONTROL).perform();
254
176
  }
255
- await actions.perform();
256
- }
177
+ }
178
+ await this._stabilize();
179
+ }
180
+ }
181
+ async matchesSelector(selector) {
182
+ await this._stabilize();
183
+ return this._executeScript((element, s) => (Element.prototype.matches || Element.prototype.msMatchesSelector).call(element, s), this.element(), selector);
184
+ }
185
+ async isFocused() {
186
+ await this._stabilize();
187
+ return webdriver.WebElement.equals(this.element(), this.element().getDriver().switchTo().activeElement());
188
+ }
189
+ async dispatchEvent(name, data) {
190
+ await this._executeScript(dispatchEvent, name, this.element(), data);
191
+ await this._stabilize();
192
+ }
193
+ _actions() {
194
+ return this.element().getDriver().actions();
195
+ }
196
+ async _executeScript(script, ...var_args) {
197
+ return this.element().getDriver().executeScript(script, ...var_args);
198
+ }
199
+ async _dispatchClickEventSequence(args, button) {
200
+ let modifiers = {};
201
+ if (args.length && typeof args[args.length - 1] === 'object') {
202
+ modifiers = args.pop();
203
+ }
204
+ const modifierKeys = getSeleniumWebDriverModifierKeys(modifiers);
205
+ const offsetArgs = args.length === 2 ? [{
206
+ x: args[0],
207
+ y: args[1]
208
+ }] : [];
209
+ let actions = this._actions().mouseMove(this.element(), ...offsetArgs);
210
+ for (const modifierKey of modifierKeys) {
211
+ actions = actions.keyDown(modifierKey);
212
+ }
213
+ actions = actions.click(button);
214
+ for (const modifierKey of modifierKeys) {
215
+ actions = actions.keyUp(modifierKey);
216
+ }
217
+ await actions.perform();
218
+ }
257
219
  }
258
- /**
259
- * Dispatches an event with a particular name and data to an element. Note that this needs to be a
260
- * pure function, because it gets stringified by WebDriver and is executed inside the browser.
261
- */
262
220
  function dispatchEvent(name, element, data) {
263
- const event = document.createEvent('Event');
264
- event.initEvent(name);
265
- // tslint:disable-next-line:ban Have to use `Object.assign` to preserve the original object.
266
- Object.assign(event, data || {});
267
- element.dispatchEvent(event);
221
+ const event = document.createEvent('Event');
222
+ event.initEvent(name);
223
+ Object.assign(event, data || {});
224
+ element.dispatchEvent(event);
268
225
  }
269
226
 
270
- /** The default environment options. */
271
227
  const defaultEnvironmentOptions = {
272
- queryFn: async (selector, root) => root().findElements(webdriver.By.css(selector)),
228
+ queryFn: async (selector, root) => root().findElements(webdriver.By.css(selector))
273
229
  };
274
- /**
275
- * This function is meant to be executed in the browser. It taps into the hooks exposed by Angular
276
- * and invokes the specified `callback` when the application is stable (no more pending tasks).
277
- */
278
230
  function whenStable(callback) {
279
- Promise.all(window.frameworkStabilizers.map(stabilizer => new Promise(stabilizer))).then(callback);
231
+ Promise.all(window.frameworkStabilizers.map(stabilizer => new Promise(stabilizer))).then(callback);
280
232
  }
281
- /**
282
- * This function is meant to be executed in the browser. It checks whether the Angular framework has
283
- * bootstrapped yet.
284
- */
285
233
  function isBootstrapped() {
286
- return !!window.frameworkStabilizers;
234
+ return !!window.frameworkStabilizers;
287
235
  }
288
- /** Waits for angular to be ready after the page load. */
289
236
  async function waitForAngularReady(wd) {
290
- await wd.wait(() => wd.executeScript(isBootstrapped));
291
- await wd.executeAsyncScript(whenStable);
237
+ await wd.wait(() => wd.executeScript(isBootstrapped));
238
+ await wd.executeAsyncScript(whenStable);
292
239
  }
293
- /** A `HarnessEnvironment` implementation for WebDriver. */
294
240
  class SeleniumWebDriverHarnessEnvironment extends HarnessEnvironment {
295
- /** The options for this environment. */
296
- _options;
297
- /** Environment stabilization callback passed to the created test elements. */
298
- _stabilizeCallback;
299
- constructor(rawRootElement, options) {
300
- super(rawRootElement);
301
- this._options = { ...defaultEnvironmentOptions, ...options };
302
- this._stabilizeCallback = () => this.forceStabilize();
303
- }
304
- /** Gets the ElementFinder corresponding to the given TestElement. */
305
- static getNativeElement(el) {
306
- if (el instanceof SeleniumWebDriverElement) {
307
- return el.element();
308
- }
309
- throw Error('This TestElement was not created by the WebDriverHarnessEnvironment');
310
- }
311
- /** Creates a `HarnessLoader` rooted at the document root. */
312
- static loader(driver, options) {
313
- return new SeleniumWebDriverHarnessEnvironment(() => driver.findElement(webdriver.By.css('body')), options);
314
- }
315
- /**
316
- * Flushes change detection and async tasks captured in the Angular zone.
317
- * In most cases it should not be necessary to call this manually. However, there may be some edge
318
- * cases where it is needed to fully flush animation events.
319
- */
320
- async forceStabilize() {
321
- await this.rawRootElement().getDriver().executeAsyncScript(whenStable);
322
- }
323
- /** @docs-private */
324
- async waitForTasksOutsideAngular() {
325
- // TODO: figure out how we can do this for the webdriver environment.
326
- // https://github.com/angular/components/issues/17412
327
- }
328
- /** Gets the root element for the document. */
329
- getDocumentRoot() {
330
- return () => this.rawRootElement().getDriver().findElement(webdriver.By.css('body'));
331
- }
332
- /** Creates a `TestElement` from a raw element. */
333
- createTestElement(element) {
334
- return new SeleniumWebDriverElement(element, this._stabilizeCallback);
335
- }
336
- /** Creates a `HarnessLoader` rooted at the given raw element. */
337
- createEnvironment(element) {
338
- return new SeleniumWebDriverHarnessEnvironment(element, this._options);
339
- }
340
- // Note: This seems to be working, though we may need to re-evaluate if we encounter issues with
341
- // stale element references. `() => Promise<webdriver.WebElement[]>` seems like a more correct
342
- // return type, though supporting it would require changes to the public harness API.
343
- /**
344
- * Gets a list of all elements matching the given selector under this environment's root element.
345
- */
346
- async getAllRawElements(selector) {
347
- const els = await this._options.queryFn(selector, this.rawRootElement);
348
- return els.map((x) => () => x);
349
- }
241
+ _options;
242
+ _stabilizeCallback;
243
+ constructor(rawRootElement, options) {
244
+ super(rawRootElement);
245
+ this._options = {
246
+ ...defaultEnvironmentOptions,
247
+ ...options
248
+ };
249
+ this._stabilizeCallback = () => this.forceStabilize();
250
+ }
251
+ static getNativeElement(el) {
252
+ if (el instanceof SeleniumWebDriverElement) {
253
+ return el.element();
254
+ }
255
+ throw Error('This TestElement was not created by the WebDriverHarnessEnvironment');
256
+ }
257
+ static loader(driver, options) {
258
+ return new SeleniumWebDriverHarnessEnvironment(() => driver.findElement(webdriver.By.css('body')), options);
259
+ }
260
+ async forceStabilize() {
261
+ await this.rawRootElement().getDriver().executeAsyncScript(whenStable);
262
+ }
263
+ async waitForTasksOutsideAngular() {}
264
+ getDocumentRoot() {
265
+ return () => this.rawRootElement().getDriver().findElement(webdriver.By.css('body'));
266
+ }
267
+ createTestElement(element) {
268
+ return new SeleniumWebDriverElement(element, this._stabilizeCallback);
269
+ }
270
+ createEnvironment(element) {
271
+ return new SeleniumWebDriverHarnessEnvironment(element, this._options);
272
+ }
273
+ async getAllRawElements(selector) {
274
+ const els = await this._options.queryFn(selector, this.rawRootElement);
275
+ return els.map(x => () => x);
276
+ }
350
277
  }
351
278
 
352
279
  export { SeleniumWebDriverElement, SeleniumWebDriverHarnessEnvironment, waitForAngularReady };