selenium-webdriver 4.0.0-alpha.8 → 4.0.0-beta.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.
Files changed (53) hide show
  1. package/CHANGES.md +14 -1
  2. package/LICENSE +202 -0
  3. package/NOTICE +2 -0
  4. package/README.md +0 -0
  5. package/chrome.js +0 -0
  6. package/chromium.js +7 -202
  7. package/devtools/CDPConnection.js +0 -0
  8. package/edge.js +1 -1
  9. package/example/chrome_android.js +45 -0
  10. package/{lib/atoms/make-atoms-module.js → example/chrome_mobile_emulation.js} +26 -15
  11. package/example/firefox_channels.js +84 -0
  12. package/example/google_search.js +50 -0
  13. package/example/google_search_test.js +70 -0
  14. package/example/headless.js +63 -0
  15. package/example/logging.js +64 -0
  16. package/firefox.js +10 -9
  17. package/http/index.js +0 -0
  18. package/http/util.js +3 -3
  19. package/ie.js +0 -0
  20. package/index.js +2 -2
  21. package/io/exec.js +0 -0
  22. package/io/index.js +4 -4
  23. package/io/zip.js +0 -0
  24. package/lib/actions.js +16 -15
  25. package/lib/atoms/find-elements.js +4 -3
  26. package/lib/atoms/get-attribute.js +0 -0
  27. package/lib/atoms/is-displayed.js +0 -0
  28. package/lib/atoms/mutation-listener.js +38 -0
  29. package/lib/by.js +1 -1
  30. package/lib/capabilities.js +2 -2
  31. package/lib/command.js +2 -0
  32. package/lib/error.js +0 -0
  33. package/lib/http.js +17 -1
  34. package/lib/input.js +0 -0
  35. package/lib/logging.js +0 -0
  36. package/lib/promise.js +1 -1
  37. package/lib/proxy.js +0 -0
  38. package/lib/session.js +0 -0
  39. package/lib/symbols.js +0 -0
  40. package/lib/until.js +17 -15
  41. package/lib/webdriver.js +322 -50
  42. package/net/index.js +0 -0
  43. package/net/portprober.js +8 -8
  44. package/opera.js +0 -0
  45. package/package.json +8 -8
  46. package/proxy.js +0 -0
  47. package/remote/index.js +0 -0
  48. package/safari.js +0 -0
  49. package/testing/index.js +509 -0
  50. package/.eslintrc.js +0 -27
  51. package/.prettierrc +0 -4
  52. package/devtools/generator/protocol-dts-generator.js +0 -429
  53. package/lib/README +0 -5
package/CHANGES.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## v4.0.0-beta.1
2
+
3
+ * JS Binding support for WebDriver Bidi in Firefox
4
+ - This requires Firefox 87 and Geckodriver 0.29 to be able to work
5
+ * Update the supported CDP versions
6
+ * Update tmp package version (#9155)
7
+ * Adding support for /computedlabel (getAccessibleName) (#9073)
8
+ * Adding support for computedrole (#8990)
9
+ * Use subfolder for NPM package homepage (#8938)
10
+ * Fix typo: tracingCategories -> traceCategories (#8976)
11
+ * Package up mutation-listener for node. Fixes #8955
12
+ * Adding support for `print` endpoint (#8880)
13
+
1
14
  ## v4.0.0-alpha.8
2
15
 
3
16
  * Rolling back native support for Opera Browser
@@ -7,7 +20,7 @@
7
20
  - setEdgeChromium
8
21
  - setScrollBehavior
9
22
  - For consistent naming, deprecating `addArguments(...args)` in favor of `addBrowserCommandSwitches(...args)`
10
-
23
+
11
24
  * Added relative locators
12
25
  * Added Chrome DevTools Protocol (CDP) support
13
26
  * Added support for BASIC authentication.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2021 Software Freedom Conservancy (SFC)
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Copyright 2011-2021 Software Freedom Conservancy
2
+ Copyright 2004-2011 Selenium committers
package/README.md CHANGED
File without changes
package/chrome.js CHANGED
File without changes
package/chromium.js CHANGED
@@ -82,11 +82,7 @@ const command = require('./lib/command')
82
82
  const error = require('./lib/error')
83
83
  const Symbols = require('./lib/symbols')
84
84
  const webdriver = require('./lib/webdriver')
85
- const WebSocket = require('ws')
86
- const cdp = require('./devtools/CDPConnection')
87
85
  const remote = require('./remote')
88
- const cdpTargets = ['page', 'browser']
89
- const fs = require('fs')
90
86
 
91
87
  /**
92
88
  * Custom command names supported by Chromium WebDriver.
@@ -112,9 +108,9 @@ const Command = {
112
108
  * @return {!command.Executor} The new command executor.
113
109
  */
114
110
  function createExecutor(url, vendorPrefix) {
115
- let agent = new http.Agent({ keepAlive: true })
116
- let client = url.then((url) => new http.HttpClient(url, agent))
117
- let executor = new http.Executor(client)
111
+ const agent = new http.Agent({ keepAlive: true })
112
+ const client = url.then((url) => new http.HttpClient(url, agent))
113
+ const executor = new http.Executor(client)
118
114
  configureExecutor(executor, vendorPrefix)
119
115
  return executor
120
116
  }
@@ -394,7 +390,7 @@ class Options extends Capabilities {
394
390
  * - `enableTimeline`: Whether or not to collect events from Timeline domain.
395
391
  * Note: when tracing is enabled, Timeline domain is implicitly disabled,
396
392
  * unless `enableTimeline` is explicitly set to true.
397
- * - `tracingCategories`: A comma-separated string of Chromium tracing
393
+ * - `traceCategories`: A comma-separated string of Chromium tracing
398
394
  * categories for which trace events should be collected. An unspecified
399
395
  * or empty string disables tracing.
400
396
  * - `bufferUsageReportingInterval`: The requested number of milliseconds
@@ -405,7 +401,7 @@ class Options extends Capabilities {
405
401
  * @param {{enableNetwork: boolean,
406
402
  * enablePage: boolean,
407
403
  * enableTimeline: boolean,
408
- * tracingCategories: string,
404
+ * traceCategories: string,
409
405
  * bufferUsageReportingInterval: number}} prefs The performance
410
406
  * logging preferences.
411
407
  * @return {!Options} A self reference.
@@ -569,7 +565,7 @@ class Options extends Capabilities {
569
565
  return extension.toString('base64')
570
566
  }
571
567
  return io
572
- .read(/** @type {string} */ (extension))
568
+ .read(/** @type {string} */(extension))
573
569
  .then((buffer) => buffer.toString('base64'))
574
570
  })
575
571
  }
@@ -622,7 +618,7 @@ class Driver extends webdriver.WebDriver {
622
618
  * implementation.
623
619
  * @override
624
620
  */
625
- setFileDetector() {}
621
+ setFileDetector() { }
626
622
 
627
623
  /**
628
624
  * Schedules a command to launch Chrome App with given ID.
@@ -709,127 +705,6 @@ class Driver extends webdriver.WebDriver {
709
705
  )
710
706
  }
711
707
 
712
- /**
713
- * Creates a new WebSocket connection.
714
- * @return {!Promise<resolved>} A new CDP instance.
715
- */
716
- async createCDPConnection(target) {
717
- const caps = await this.getCapabilities()
718
- const seOptions = caps['map_'].get('se:options') || new Map()
719
- const vendorInfo =
720
- caps['map_'].get(this.VENDOR_COMMAND_PREFIX + ':chromeOptions') ||
721
- new Map()
722
- const debuggerUrl = seOptions['cdp'] || vendorInfo['debuggerAddress']
723
- this._wsUrl = await this.getWsUrl(debuggerUrl, target)
724
-
725
- return new Promise((resolve, reject) => {
726
- try {
727
- this._wsConnection = new WebSocket(this._wsUrl)
728
- } catch (err) {
729
- reject(err)
730
- return
731
- }
732
-
733
- this._wsConnection.on('open', () => {
734
- this._cdpConnection = new cdp.CdpConnection(this._wsConnection)
735
- resolve(this._cdpConnection)
736
- })
737
-
738
- this._wsConnection.on('error', (error) => {
739
- reject(error)
740
- })
741
- })
742
- }
743
-
744
- /**
745
- * Retrieves 'webSocketDebuggerUrl' by sending a http request using debugger address
746
- * @param {string} debuggerAddress
747
- * @param {string} target
748
- * @return {string} Returns parsed webSocketDebuggerUrl obtained from the http request
749
- */
750
- async getWsUrl(debuggerAddress, target) {
751
- if (target && cdpTargets.indexOf(target.toLowerCase()) === -1) {
752
- throw new error.InvalidArgumentError('invalid target value')
753
- }
754
- let path = '/json/version'
755
-
756
- if (target === 'page') {
757
- path = '/json'
758
- }
759
- let request = new http.Request('GET', path)
760
- let client = new http.HttpClient('http://' + debuggerAddress)
761
- let response = await client.send(request)
762
- let url = JSON.parse(response.body)['webSocketDebuggerUrl']
763
- if (target.toLowerCase() === 'page') {
764
- url = JSON.parse(response.body)[0]['webSocketDebuggerUrl']
765
- }
766
-
767
- return url
768
- }
769
-
770
- /**
771
- * Sets a listener for Fetch.authRequired event from CDP
772
- * If event is triggered, it enter username and password
773
- * and allows the test to move forward
774
- * @param {string} username
775
- * @param {string} password
776
- * @param connection CDP Connection
777
- */
778
- async register(username, password, connection) {
779
- await connection.execute("Network.setCacheDisabled", this.getRandomNumber(1, 10), {
780
- cacheDisabled: true,
781
- }, null);
782
-
783
- this._wsConnection.on('message', (message) => {
784
- const params = JSON.parse(message)
785
-
786
- if (params.method === 'Fetch.authRequired') {
787
- const requestParams = params['params']
788
- connection.execute('Fetch.continueWithAuth', this.getRandomNumber(1, 10), {
789
- requestId: requestParams['requestId'],
790
- authChallengeResponse: {
791
- response: 'ProvideCredentials',
792
- username: username,
793
- password: password,
794
- }})
795
- } else if (params.method === 'Fetch.requestPaused') {
796
- const requestPausedParams = params['params']
797
- connection.execute('Fetch.continueRequest', this.getRandomNumber(1, 10), {
798
- requestId: requestPausedParams['requestId'],
799
- })
800
- }
801
- })
802
-
803
- await connection.execute('Fetch.enable', 1, {
804
- handleAuthRequests: true,
805
- }, null)
806
- }
807
-
808
- /**
809
- *
810
- * @param connection
811
- * @param callback
812
- * @returns {Promise<void>}
813
- */
814
- async onLogEvent(connection, callback) {
815
- await connection.execute('Runtime.enable', this.getRandomNumber(1, 10), {}, null)
816
-
817
- this._wsConnection.on('message', (message) => {
818
- const params = JSON.parse(message)
819
-
820
- if (params.method === 'Runtime.consoleAPICalled') {
821
- const consoleEventParams = params['params']
822
- let event = {
823
- type: consoleEventParams['type'],
824
- timestamp: new Date(consoleEventParams['timestamp']),
825
- args: consoleEventParams['args']
826
- }
827
-
828
- callback(event)
829
- }
830
- })
831
- }
832
-
833
708
  /**
834
709
  * Set a permission state to the given value.
835
710
  *
@@ -848,72 +723,6 @@ class Driver extends webdriver.WebDriver {
848
723
  )
849
724
  }
850
725
 
851
- /**
852
- *
853
- * @param connection
854
- * @param callback
855
- * @returns {Promise<void>}
856
- */
857
- async onLogException(connection, callback) {
858
- await connection.execute('Runtime.enable', this.getRandomNumber(1, 10), {}, null)
859
-
860
- this._wsConnection.on('message', (message) => {
861
- const params = JSON.parse(message)
862
-
863
- if (params.method === 'Runtime.exceptionThrown') {
864
- const exceptionEventParams = params['params']
865
- let event = {
866
- exceptionDetails: exceptionEventParams['exceptionDetails'],
867
- timestamp: new Date(exceptionEventParams['timestamp']),
868
- }
869
-
870
- callback(event)
871
- }
872
- })
873
- }
874
-
875
- /**
876
- * @param connection
877
- * @param callback
878
- * @returns {Promise<void>}
879
- */
880
- async logMutationEvents(connection, callback) {
881
- await connection.execute('Runtime.enable', this.getRandomNumber(1, 10), {}, null)
882
- await connection.execute('Page.enable', this.getRandomNumber(1, 10), {}, null)
883
-
884
- await connection.execute('Runtime.addBinding', this.getRandomNumber(1, 10), {
885
- name: '__webdriver_attribute',
886
- }, null)
887
-
888
- const mutationListener = fs.readFileSync('../../cdp-support/mutation-listener.js', 'utf-8').toString()
889
-
890
- this.executeScript(mutationListener)
891
-
892
- await connection.execute('Page.addScriptToEvaluateOnNewDocument', this.getRandomNumber(1, 10), {
893
- source: mutationListener,
894
- }, null)
895
-
896
- this._wsConnection.on('message', async (message) => {
897
- const params = JSON.parse(message)
898
- if (params.method === 'Runtime.bindingCalled') {
899
- let payload = JSON.parse(params['params']['payload'])
900
- let elements = await this.findElements({css: "*[data-__webdriver_id=" + payload['target']})
901
-
902
- if (elements.length === 0) {
903
- return
904
- }
905
-
906
- let event = {
907
- element: elements[0],
908
- attribute_name: payload['name'],
909
- current_value: payload['value'],
910
- old_value: payload['oldValue']
911
- }
912
- callback(event)
913
- }
914
- })
915
- }
916
-
917
726
  /**
918
727
  * Sends a DevTools command to change the browser's download directory.
919
728
  *
@@ -1011,10 +820,6 @@ class Driver extends webdriver.WebDriver {
1011
820
  'Driver.stopCasting(' + deviceName + ')'
1012
821
  )
1013
822
  }
1014
-
1015
- getRandomNumber(min, max) {
1016
- return Math.floor(Math.random() * (max - min + 1) + min)
1017
- }
1018
823
  }
1019
824
 
1020
825
  // PUBLIC API
File without changes
package/edge.js CHANGED
@@ -169,7 +169,7 @@ class ServiceBuilder extends chromium.ServiceBuilder {
169
169
  * MicrosoftWebDriver cannot be found on the PATH.
170
170
  */
171
171
  constructor(opt_exe) {
172
- let exe = opt_exe || locateSynchronously()
172
+ const exe = opt_exe || locateSynchronously()
173
173
  if (!exe) {
174
174
  throw Error(
175
175
  'The WebDriver for Edge could not be found on the current PATH. Please ' +
@@ -0,0 +1,45 @@
1
+ // Licensed to the Software Freedom Conservancy (SFC) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The SFC licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ /**
19
+ * @fileoverview A basic example of working with Chrome on Android. Before
20
+ * running this example, you must start adb and connect a device (or start an
21
+ * AVD).
22
+ */
23
+
24
+ 'use strict'
25
+
26
+ const { Builder, By, Key, until } = require('..')
27
+ const { Options } = require('../chrome')
28
+
29
+ ;(async function () {
30
+ let driver
31
+ try {
32
+ driver = await new Builder()
33
+ .forBrowser('chrome')
34
+ .setChromeOptions(new Options().androidChrome())
35
+ .build()
36
+ await driver.get('http://www.google.com/ncr')
37
+ await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
38
+ await driver.wait(until.titleIs('webdriver - Google Search'), 1000)
39
+ } finally {
40
+ ;(await driver) && driver.quit()
41
+ }
42
+ })().then(
43
+ (_) => console.log('SUCCESS'),
44
+ (err) => console.error('ERROR: ' + err)
45
+ )
@@ -15,21 +15,32 @@
15
15
  // specific language governing permissions and limitations
16
16
  // under the License.
17
17
 
18
- const fs = require('fs')
19
- const path = require('path')
18
+ /**
19
+ * @fileoverview This is an example of emulating a mobile device using the
20
+ * ChromeDriver.
21
+ */
20
22
 
21
- if (process.argv.length < 3) {
22
- process.stderr.write(
23
- `Usage: node ${path.basename(__filename)} <src file> <dst file>\n`
24
- )
25
- // eslint-disable-next-line no-process-exit
26
- process.exit(-1)
27
- }
23
+ 'use strict'
28
24
 
29
- const buffer = fs.readFileSync(process.argv[2])
30
- fs.writeFileSync(
31
- process.argv[3],
32
- `// GENERATED CODE - DO NOT EDIT
33
- module.exports = ${buffer.toString('utf8').trim()};
34
- `
25
+ const { Builder, By, Key, until } = require('..')
26
+ const { Options } = require('../chrome')
27
+
28
+ ;(async function () {
29
+ let driver
30
+ try {
31
+ driver = await new Builder()
32
+ .forBrowser('chrome')
33
+ .setChromeOptions(
34
+ new Options().setMobileEmulation({ deviceName: 'Nexus 5X' })
35
+ )
36
+ .build()
37
+ await driver.get('http://www.google.com/ncr')
38
+ await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
39
+ await driver.wait(until.titleIs('webdriver - Google Search'), 1000)
40
+ } finally {
41
+ ;(await driver) && driver.quit()
42
+ }
43
+ })().then(
44
+ (_) => console.log('SUCCESS'),
45
+ (err) => console.error('ERROR: ' + err)
35
46
  )