|
1 | 1 | ## Atom notes
|
2 | 2 |
|
3 |
| -The Selenium atoms can generally be used without change. Two changes are needed |
4 |
| -in order to maintain current functionality in the mobile context. |
| 3 | +Until the following PRs are merged and published, building the atoms requires patching the tmp |
| 4 | +Selenium checkout in this repo with the change listed in the PR (otherwise certain fragments will |
| 5 | +get deleted on build). |
5 | 6 |
|
6 |
| -### React input operation |
| 7 | +- https://github.com/SeleniumHQ/selenium/pull/12532 |
| 8 | +- https://github.com/SeleniumHQ/selenium/pull/12555 |
| 9 | +- https://github.com/SeleniumHQ/selenium/pull/12557 |
7 | 10 |
|
8 |
| -React manages the content of input elements, and reverts changes that it did |
9 |
| -not handle itself. This means any direct call to `element.value` will be reverted |
10 |
| -by React. To get around this, bypass the React `value` function and work directly |
11 |
| -with the `HTMLInputElement`. This will still trigger all the React event handling |
12 |
| -apparatus. |
13 |
| -```diff |
14 |
| ---- a/javascript/atoms/keyboard.js |
15 |
| -+++ b/javascript/atoms/keyboard.js |
16 |
| -@@ -605,12 +605,19 @@ bot.Keyboard.prototype.updateOnCharacter_ = function(key) { |
17 |
| - |
18 |
| - var character = this.getChar_(key); |
19 |
| - var newPos = goog.dom.selection.getStart(this.getElement()) + 1; |
20 |
| -- if (bot.Keyboard.supportsSelection(this.getElement())) { |
21 |
| -+ |
22 |
| -+ // for react support, if this is an input element then skip any added value setters |
23 |
| -+ // otherwise the input will not get past the react change handlers |
24 |
| -+ if (this.getElement() instanceof window.HTMLInputElement) { |
25 |
| -+ var valueAccessor = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value'); |
26 |
| -+ var value = valueAccessor.get.call(/** @type {window.HTMLInputElement} */ (this.getElement())); |
27 |
| -+ valueAccessor.set.call(/** @type {window.HTMLInputElement} */ (this.getElement()), value + character); |
28 |
| -+ } else if (bot.Keyboard.supportsSelection(this.getElement())) { |
29 |
| - goog.dom.selection.setText(this.getElement(), character); |
30 |
| -- goog.dom.selection.setStart(this.getElement(), newPos); |
31 |
| - } else { |
32 |
| - this.getElement().value += character; |
33 |
| - } |
34 |
| -+ |
35 |
| - if (goog.userAgent.WEBKIT) { |
36 |
| - this.fireHtmlEvent(bot.events.EventType.TEXTINPUT); |
37 |
| - } |
38 |
| -``` |
39 |
| - |
40 |
| - |
41 |
| -### Shadow DOM handling |
42 |
| - |
43 |
| -Support for Shadow DOM elements. This is needed until https://github.com/SeleniumHQ/selenium/pull/7808 |
44 |
| -is merged and published. |
45 |
| -```diff |
46 |
| ---- a/javascript/atoms/inject.js |
47 |
| -+++ b/javascript/atoms/inject.js |
48 |
| -@@ -524,6 +524,9 @@ bot.inject.cache.getElement = function(key, opt_doc) { |
49 |
| - if (node == doc.documentElement) { |
50 |
| - return el; |
51 |
| - } |
52 |
| -+ if (node.host && node.nodeType === 11) { |
53 |
| -+ node = node.host; |
54 |
| -+ } |
55 |
| - node = node.parentNode; |
56 |
| - } |
57 |
| - delete cache[key]; |
58 |
| -``` |
59 |
| - |
60 |
| - |
61 |
| -### Circular reference handling |
62 |
| - |
63 |
| -Shadow DOM elements can be reported multiple times, which leads to an error |
64 |
| -for "recursive object" references. |
65 |
| - |
66 |
| -```diff |
67 |
| ---- a/javascript/atoms/inject.js |
68 |
| -+++ b/javascript/atoms/inject.js |
69 |
| -@@ -100,6 +100,7 @@ bot.inject.WINDOW_KEY = 'WINDOW'; |
70 |
| - * @see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol |
71 |
| - */ |
72 |
| - bot.inject.wrapValue = function(value) { |
73 |
| -+ var parentIsShadow = value instanceof ShadowRoot; |
74 |
| - var _wrap = function(value, seen) { |
75 |
| - switch (goog.typeOf(value)) { |
76 |
| - case 'string': |
77 |
| -@@ -121,6 +122,11 @@ bot.inject.wrapValue = function(value) { |
78 |
| - // a ton of compiler warnings. |
79 |
| - value = /**@type {!Object}*/ (value); |
80 |
| - if (seen.indexOf(value) >= 0) { |
81 |
| -+ if (parentIsShadow) { |
82 |
| -+ // elements get reported multiple times in shadow elements, |
83 |
| -+ // so ignore reported circularity |
84 |
| -+ return null; |
85 |
| -+ } |
86 |
| - throw new bot.Error(bot.ErrorCode.JAVASCRIPT_ERROR, |
87 |
| - 'Recursive object cannot be transferred'); |
88 |
| - } |
89 |
| -``` |
| 11 | +When these PRs are merged and our Selenium version updated to match, we can delete this note! |
0 commit comments