selenium-webdriver 3.5.0 → 4.0.0-alpha.4

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 (366) hide show
  1. package/CHANGES.md +246 -0
  2. package/LICENSE +1 -1
  3. package/NOTICE +1 -1
  4. package/README.md +40 -40
  5. package/chrome.js +118 -134
  6. package/edge.js +43 -117
  7. package/example/chrome_android.js +8 -9
  8. package/example/chrome_mobile_emulation.js +8 -9
  9. package/example/firefox_channels.js +23 -19
  10. package/example/google_search.js +3 -3
  11. package/example/google_search_test.js +38 -27
  12. package/example/{chrome_headless.js → headless.js} +15 -7
  13. package/example/logging.js +40 -7
  14. package/firefox.js +789 -0
  15. package/http/index.js +62 -9
  16. package/http/util.js +11 -6
  17. package/ie.js +83 -97
  18. package/index.js +198 -114
  19. package/io/exec.js +29 -15
  20. package/io/index.js +1 -1
  21. package/io/zip.js +1 -1
  22. package/lib/actions.js +68 -63
  23. package/lib/atoms/get-attribute.js +86 -0
  24. package/lib/atoms/is-displayed.js +76 -76
  25. package/lib/by.js +7 -4
  26. package/lib/capabilities.js +310 -210
  27. package/lib/command.js +27 -51
  28. package/lib/error.js +100 -41
  29. package/lib/http.js +161 -120
  30. package/lib/input.js +1044 -8
  31. package/lib/logging.js +1 -5
  32. package/lib/promise.js +222 -3331
  33. package/lib/proxy.js +134 -39
  34. package/lib/session.js +2 -2
  35. package/lib/symbols.js +0 -0
  36. package/lib/until.js +1 -1
  37. package/lib/webdriver.js +717 -953
  38. package/net/index.js +21 -25
  39. package/net/portprober.js +51 -68
  40. package/package.json +17 -12
  41. package/proxy.js +0 -0
  42. package/remote/index.js +63 -44
  43. package/safari.js +41 -128
  44. package/testing/index.js +386 -315
  45. package/.npmignore +0 -2
  46. package/example/async_await_test.js +0 -68
  47. package/example/google_search_generator.js +0 -50
  48. package/example/parallel_flows.js +0 -54
  49. package/firefox/binary.js +0 -344
  50. package/firefox/extension.js +0 -224
  51. package/firefox/index.js +0 -626
  52. package/firefox/profile.js +0 -394
  53. package/lib/README +0 -5
  54. package/lib/atoms/getAttribute.js +0 -9
  55. package/lib/devmode.js +0 -34
  56. package/lib/events.js +0 -210
  57. package/lib/firefox/webdriver.json +0 -70
  58. package/lib/test/build.js +0 -151
  59. package/lib/test/data/ClickTest_testClicksASurroundingStrongTag.html +0 -11
  60. package/lib/test/data/Page.aspx +0 -17
  61. package/lib/test/data/Page.aspx.cs +0 -22
  62. package/lib/test/data/Redirect.aspx +0 -11
  63. package/lib/test/data/Redirect.aspx.cs +0 -9
  64. package/lib/test/data/Settings.StyleCop +0 -759
  65. package/lib/test/data/Web.Config +0 -59
  66. package/lib/test/data/actualXhtmlPage.xhtml +0 -14
  67. package/lib/test/data/ajaxy_page.html +0 -81
  68. package/lib/test/data/alerts.html +0 -85
  69. package/lib/test/data/banner.gif +0 -0
  70. package/lib/test/data/beach.jpg +0 -0
  71. package/lib/test/data/blank.html +0 -1
  72. package/lib/test/data/bodyTypingTest.html +0 -41
  73. package/lib/test/data/booleanAttributes.html +0 -19
  74. package/lib/test/data/child/childPage.html +0 -8
  75. package/lib/test/data/child/grandchild/grandchildPage.html +0 -8
  76. package/lib/test/data/clickEventPage.html +0 -26
  77. package/lib/test/data/click_frames.html +0 -10
  78. package/lib/test/data/click_jacker.html +0 -38
  79. package/lib/test/data/click_out_of_bounds.html +0 -23
  80. package/lib/test/data/click_out_of_bounds_overflow.html +0 -85
  81. package/lib/test/data/click_rtl.html +0 -19
  82. package/lib/test/data/click_source.html +0 -18
  83. package/lib/test/data/click_tests/click_iframe.html +0 -6
  84. package/lib/test/data/click_tests/click_in_iframe.html +0 -8
  85. package/lib/test/data/click_tests/disabled_element.html +0 -12
  86. package/lib/test/data/click_tests/disappearing_element.html +0 -62
  87. package/lib/test/data/click_tests/google_map.html +0 -15
  88. package/lib/test/data/click_tests/google_map.png +0 -0
  89. package/lib/test/data/click_tests/html5_submit_buttons.html +0 -16
  90. package/lib/test/data/click_tests/issue5237.html +0 -9
  91. package/lib/test/data/click_tests/issue5237_frame.html +0 -1
  92. package/lib/test/data/click_tests/issue5237_target.html +0 -10
  93. package/lib/test/data/click_tests/link_that_wraps.html +0 -11
  94. package/lib/test/data/click_tests/mapped_page1.html +0 -9
  95. package/lib/test/data/click_tests/mapped_page2.html +0 -9
  96. package/lib/test/data/click_tests/mapped_page3.html +0 -9
  97. package/lib/test/data/click_tests/overlapping_elements.html +0 -70
  98. package/lib/test/data/click_tests/partially_overlapping_elements.html +0 -124
  99. package/lib/test/data/click_tests/span_that_wraps.html +0 -11
  100. package/lib/test/data/click_tests/submitted_page.html +0 -9
  101. package/lib/test/data/click_tests/wrapped_overlapping_elements.html +0 -13
  102. package/lib/test/data/click_too_big.html +0 -10
  103. package/lib/test/data/click_too_big_in_frame.html +0 -11
  104. package/lib/test/data/clicks.html +0 -35
  105. package/lib/test/data/closeable_window.html +0 -8
  106. package/lib/test/data/cn-test.html +0 -156
  107. package/lib/test/data/colorPage.html +0 -20
  108. package/lib/test/data/cookies.html +0 -30
  109. package/lib/test/data/coordinates_tests/element_in_frame.html +0 -9
  110. package/lib/test/data/coordinates_tests/element_in_nested_frame.html +0 -9
  111. package/lib/test/data/coordinates_tests/page_with_element_out_of_view.html +0 -11
  112. package/lib/test/data/coordinates_tests/page_with_empty_element.html +0 -10
  113. package/lib/test/data/coordinates_tests/page_with_fixed_element.html +0 -12
  114. package/lib/test/data/coordinates_tests/page_with_hidden_element.html +0 -10
  115. package/lib/test/data/coordinates_tests/page_with_invisible_element.html +0 -10
  116. package/lib/test/data/coordinates_tests/page_with_transparent_element.html +0 -10
  117. package/lib/test/data/coordinates_tests/simple_page.html +0 -10
  118. package/lib/test/data/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  119. package/lib/test/data/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  120. package/lib/test/data/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  121. package/lib/test/data/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  122. package/lib/test/data/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  123. package/lib/test/data/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  124. package/lib/test/data/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  125. package/lib/test/data/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  126. package/lib/test/data/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  127. package/lib/test/data/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  128. package/lib/test/data/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  129. package/lib/test/data/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  130. package/lib/test/data/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  131. package/lib/test/data/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  132. package/lib/test/data/css/ui-lightness/jquery-ui-1.8.10.custom.css +0 -573
  133. package/lib/test/data/cssTransform.html +0 -61
  134. package/lib/test/data/cssTransform2.html +0 -20
  135. package/lib/test/data/document_write_in_onload.html +0 -13
  136. package/lib/test/data/dragAndDropInsideScrolledDiv.html +0 -67
  137. package/lib/test/data/dragAndDropTest.html +0 -102
  138. package/lib/test/data/dragDropOverflow.html +0 -104
  139. package/lib/test/data/draggableLists.html +0 -67
  140. package/lib/test/data/droppableItems.html +0 -65
  141. package/lib/test/data/dynamic.html +0 -39
  142. package/lib/test/data/dynamicallyModifiedPage.html +0 -42
  143. package/lib/test/data/errors.html +0 -15
  144. package/lib/test/data/firefox/jetpack-sample.xpi +0 -0
  145. package/lib/test/data/firefox/sample.xpi +0 -0
  146. package/lib/test/data/firefox/webextension.xpi +0 -0
  147. package/lib/test/data/fixedFooterNoScroll.html +0 -13
  148. package/lib/test/data/fixedFooterNoScrollQuirksMode.html +0 -12
  149. package/lib/test/data/formPage.html +0 -175
  150. package/lib/test/data/formSelectionPage.html +0 -46
  151. package/lib/test/data/form_handling_js_submit.html +0 -30
  152. package/lib/test/data/framePage3.html +0 -7
  153. package/lib/test/data/frameScrollChild.html +0 -26
  154. package/lib/test/data/frameScrollPage.html +0 -14
  155. package/lib/test/data/frameScrollParent.html +0 -11
  156. package/lib/test/data/frameWithAnimals.html +0 -11
  157. package/lib/test/data/frame_switching_tests/bug4876.html +0 -9
  158. package/lib/test/data/frame_switching_tests/bug4876_iframe.html +0 -9
  159. package/lib/test/data/frame_switching_tests/deletingFrame.html +0 -29
  160. package/lib/test/data/frame_switching_tests/deletingFrame_iframe.html +0 -8
  161. package/lib/test/data/frame_switching_tests/deletingFrame_iframe2.html +0 -7
  162. package/lib/test/data/frameset.html +0 -14
  163. package/lib/test/data/framesetPage2.html +0 -7
  164. package/lib/test/data/framesetPage3.html +0 -4
  165. package/lib/test/data/globalscope.html +0 -15
  166. package/lib/test/data/hidden.html +0 -5
  167. package/lib/test/data/hidden_partially.html +0 -45
  168. package/lib/test/data/html5/blue.jpg +0 -0
  169. package/lib/test/data/html5/database.js +0 -84
  170. package/lib/test/data/html5/geolocation.js +0 -18
  171. package/lib/test/data/html5/green.jpg +0 -0
  172. package/lib/test/data/html5/red.jpg +0 -0
  173. package/lib/test/data/html5/status.html +0 -1
  174. package/lib/test/data/html5/test.appcache +0 -11
  175. package/lib/test/data/html5/yellow.jpg +0 -0
  176. package/lib/test/data/html5Page.html +0 -32
  177. package/lib/test/data/icon.gif +0 -0
  178. package/lib/test/data/idElements.html +0 -2
  179. package/lib/test/data/iframeAtBottom.html +0 -15
  180. package/lib/test/data/iframeWithAlert.html +0 -1
  181. package/lib/test/data/iframeWithIframe.html +0 -1
  182. package/lib/test/data/iframes.html +0 -11
  183. package/lib/test/data/injectableContent.html +0 -22
  184. package/lib/test/data/javascriptEnhancedForm.html +0 -30
  185. package/lib/test/data/javascriptPage.html +0 -285
  186. package/lib/test/data/jquery-1.3.2.js +0 -4376
  187. package/lib/test/data/js/jquery-1.4.4.min.js +0 -167
  188. package/lib/test/data/js/jquery-ui-1.8.10.custom.min.js +0 -782
  189. package/lib/test/data/js/skins/lightgray/content.inline.min.css +0 -1
  190. package/lib/test/data/js/skins/lightgray/content.min.css +0 -1
  191. package/lib/test/data/js/skins/lightgray/fonts/readme.md +0 -1
  192. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.dev.svg +0 -175
  193. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.eot +0 -0
  194. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.svg +0 -62
  195. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.ttf +0 -0
  196. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.woff +0 -0
  197. package/lib/test/data/js/skins/lightgray/fonts/tinymce.dev.svg +0 -153
  198. package/lib/test/data/js/skins/lightgray/fonts/tinymce.eot +0 -0
  199. package/lib/test/data/js/skins/lightgray/fonts/tinymce.svg +0 -63
  200. package/lib/test/data/js/skins/lightgray/fonts/tinymce.ttf +0 -0
  201. package/lib/test/data/js/skins/lightgray/fonts/tinymce.woff +0 -0
  202. package/lib/test/data/js/skins/lightgray/img/anchor.gif +0 -0
  203. package/lib/test/data/js/skins/lightgray/img/loader.gif +0 -0
  204. package/lib/test/data/js/skins/lightgray/img/object.gif +0 -0
  205. package/lib/test/data/js/skins/lightgray/img/trans.gif +0 -0
  206. package/lib/test/data/js/skins/lightgray/skin.ie7.min.css +0 -1
  207. package/lib/test/data/js/skins/lightgray/skin.min.css +0 -1
  208. package/lib/test/data/js/themes/modern/theme.min.js +0 -1
  209. package/lib/test/data/js/tinymce.min.js +0 -10
  210. package/lib/test/data/key_logger.html +0 -34
  211. package/lib/test/data/key_tests/remove_on_keypress.html +0 -36
  212. package/lib/test/data/keyboard_shortcut.html +0 -36
  213. package/lib/test/data/linked_image.html +0 -16
  214. package/lib/test/data/locators_tests/boolean_attribute_selected.html +0 -13
  215. package/lib/test/data/locators_tests/boolean_attribute_selected_html4.html +0 -13
  216. package/lib/test/data/longContentPage.html +0 -55
  217. package/lib/test/data/macbeth.html +0 -5255
  218. package/lib/test/data/map.png +0 -0
  219. package/lib/test/data/map_visibility.html +0 -8
  220. package/lib/test/data/markerTransparent.png +0 -0
  221. package/lib/test/data/messages.html +0 -15
  222. package/lib/test/data/meta-redirect.html +0 -11
  223. package/lib/test/data/missedJsReference.html +0 -11
  224. package/lib/test/data/modal_dialogs/modal_1.html +0 -21
  225. package/lib/test/data/modal_dialogs/modal_2.html +0 -21
  226. package/lib/test/data/modal_dialogs/modal_3.html +0 -15
  227. package/lib/test/data/modal_dialogs/modalindex.html +0 -21
  228. package/lib/test/data/mouseOver.html +0 -17
  229. package/lib/test/data/mousePositionTracker.html +0 -33
  230. package/lib/test/data/nestedElements.html +0 -164
  231. package/lib/test/data/overflow/x_auto_y_auto.html +0 -30
  232. package/lib/test/data/overflow/x_auto_y_hidden.html +0 -30
  233. package/lib/test/data/overflow/x_auto_y_scroll.html +0 -30
  234. package/lib/test/data/overflow/x_hidden_y_auto.html +0 -30
  235. package/lib/test/data/overflow/x_hidden_y_hidden.html +0 -30
  236. package/lib/test/data/overflow/x_hidden_y_scroll.html +0 -30
  237. package/lib/test/data/overflow/x_scroll_y_auto.html +0 -30
  238. package/lib/test/data/overflow/x_scroll_y_hidden.html +0 -30
  239. package/lib/test/data/overflow/x_scroll_y_scroll.html +0 -30
  240. package/lib/test/data/overflow-body.html +0 -15
  241. package/lib/test/data/pageWithOnBeforeUnloadMessage.html +0 -20
  242. package/lib/test/data/pageWithOnLoad.html +0 -6
  243. package/lib/test/data/pageWithOnUnload.html +0 -6
  244. package/lib/test/data/page_with_link_to_slow_loading_page.html +0 -6
  245. package/lib/test/data/plain.txt +0 -1
  246. package/lib/test/data/proxy/page1.html +0 -20
  247. package/lib/test/data/proxy/page2.html +0 -24
  248. package/lib/test/data/proxy/page3.html +0 -5
  249. package/lib/test/data/readOnlyPage.html +0 -24
  250. package/lib/test/data/rectangles.html +0 -40
  251. package/lib/test/data/resultPage.html +0 -25
  252. package/lib/test/data/rich_text.html +0 -161
  253. package/lib/test/data/safari/frames_benchmark.html +0 -31
  254. package/lib/test/data/screen/screen.css +0 -19
  255. package/lib/test/data/screen/screen.html +0 -72
  256. package/lib/test/data/screen/screen.js +0 -7
  257. package/lib/test/data/screen/screen_frame1.html +0 -72
  258. package/lib/test/data/screen/screen_frame2.html +0 -72
  259. package/lib/test/data/screen/screen_frames.html +0 -11
  260. package/lib/test/data/screen/screen_iframes.html +0 -12
  261. package/lib/test/data/screen/screen_too_long.html +0 -68
  262. package/lib/test/data/screen/screen_x_long.html +0 -72
  263. package/lib/test/data/screen/screen_x_too_long.html +0 -72
  264. package/lib/test/data/screen/screen_y_long.html +0 -72
  265. package/lib/test/data/screen/screen_y_too_long.html +0 -72
  266. package/lib/test/data/scroll.html +0 -27
  267. package/lib/test/data/scroll2.html +0 -21
  268. package/lib/test/data/scroll3.html +0 -8
  269. package/lib/test/data/scroll4.html +0 -7
  270. package/lib/test/data/scroll5.html +0 -18
  271. package/lib/test/data/scrolling_tests/frame_with_height_above_200.html +0 -26
  272. package/lib/test/data/scrolling_tests/frame_with_height_above_2000.html +0 -26
  273. package/lib/test/data/scrolling_tests/frame_with_nested_scrolling_frame.html +0 -11
  274. package/lib/test/data/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html +0 -12
  275. package/lib/test/data/scrolling_tests/frame_with_small_height.html +0 -10
  276. package/lib/test/data/scrolling_tests/page_with_double_overflow_auto.html +0 -19
  277. package/lib/test/data/scrolling_tests/page_with_frame_out_of_view.html +0 -12
  278. package/lib/test/data/scrolling_tests/page_with_nested_scrolling_frames.html +0 -11
  279. package/lib/test/data/scrolling_tests/page_with_nested_scrolling_frames_out_of_view.html +0 -12
  280. package/lib/test/data/scrolling_tests/page_with_non_scrolling_frame.html +0 -11
  281. package/lib/test/data/scrolling_tests/page_with_scrolling_frame.html +0 -11
  282. package/lib/test/data/scrolling_tests/page_with_scrolling_frame_out_of_view.html +0 -12
  283. package/lib/test/data/scrolling_tests/page_with_tall_frame.html +0 -11
  284. package/lib/test/data/scrolling_tests/page_with_y_overflow_auto.html +0 -14
  285. package/lib/test/data/scrolling_tests/target_page.html +0 -9
  286. package/lib/test/data/selectPage.html +0 -58
  287. package/lib/test/data/selectableItems.html +0 -65
  288. package/lib/test/data/sessionCookie.html +0 -21
  289. package/lib/test/data/sessionCookieDest.html +0 -34
  290. package/lib/test/data/simple.xml +0 -5
  291. package/lib/test/data/simpleTest.html +0 -98
  292. package/lib/test/data/single_text_input.html +0 -12
  293. package/lib/test/data/slowLoadingAlert.html +0 -10
  294. package/lib/test/data/slowLoadingResourcePage.html +0 -12
  295. package/lib/test/data/slow_loading_iframes.html +0 -14
  296. package/lib/test/data/styledPage.html +0 -28
  297. package/lib/test/data/svgPiechart.xhtml +0 -81
  298. package/lib/test/data/svgTest.svg +0 -4
  299. package/lib/test/data/tables.html +0 -36
  300. package/lib/test/data/tinymce.html +0 -10
  301. package/lib/test/data/transformable.xml +0 -11
  302. package/lib/test/data/transformable.xsl +0 -37
  303. package/lib/test/data/transparentUpload.html +0 -70
  304. package/lib/test/data/underscore.html +0 -9
  305. package/lib/test/data/unicode_ltr.html +0 -8
  306. package/lib/test/data/upload.html +0 -45
  307. package/lib/test/data/userDefinedProperty.html +0 -8
  308. package/lib/test/data/veryLargeCanvas.html +0 -81
  309. package/lib/test/data/visibility-css.html +0 -21
  310. package/lib/test/data/win32frameset.html +0 -8
  311. package/lib/test/data/window_switching_tests/page_with_frame.html +0 -12
  312. package/lib/test/data/window_switching_tests/simple_page.html +0 -9
  313. package/lib/test/data/xhtmlFormPage.xhtml +0 -17
  314. package/lib/test/data/xhtmlTest.html +0 -76
  315. package/lib/test/fileserver.js +0 -321
  316. package/lib/test/httpserver.js +0 -120
  317. package/lib/test/index.js +0 -270
  318. package/lib/test/promise.js +0 -79
  319. package/lib/test/resources.js +0 -44
  320. package/opera.js +0 -405
  321. package/phantomjs.js +0 -282
  322. package/test/actions_test.js +0 -52
  323. package/test/chrome/options_test.js +0 -227
  324. package/test/chrome/service_test.js +0 -45
  325. package/test/cookie_test.js +0 -214
  326. package/test/element_finding_test.js +0 -426
  327. package/test/execute_script_test.js +0 -350
  328. package/test/fingerprint_test.js +0 -62
  329. package/test/firefox/extension_test.js +0 -120
  330. package/test/firefox/firefox_test.js +0 -261
  331. package/test/firefox/profile_test.js +0 -140
  332. package/test/http/http_test.js +0 -223
  333. package/test/http/util_test.js +0 -178
  334. package/test/io/io_test.js +0 -360
  335. package/test/io/zip_test.js +0 -128
  336. package/test/lib/by_test.js +0 -160
  337. package/test/lib/capabilities_test.js +0 -111
  338. package/test/lib/error_test.js +0 -305
  339. package/test/lib/events_test.js +0 -177
  340. package/test/lib/http_test.js +0 -696
  341. package/test/lib/logging_test.js +0 -272
  342. package/test/lib/promise_aplus_test.js +0 -78
  343. package/test/lib/promise_error_test.js +0 -884
  344. package/test/lib/promise_flow_test.js +0 -2288
  345. package/test/lib/promise_generator_test.js +0 -310
  346. package/test/lib/promise_test.js +0 -1109
  347. package/test/lib/testutil.js +0 -90
  348. package/test/lib/until_test.js +0 -478
  349. package/test/lib/webdriver_test.js +0 -2311
  350. package/test/logging_test.js +0 -167
  351. package/test/net/index_test.js +0 -60
  352. package/test/net/portprober_test.js +0 -128
  353. package/test/page_loading_test.js +0 -166
  354. package/test/phantomjs/execute_phantomjs_test.js +0 -59
  355. package/test/proxy_test.js +0 -180
  356. package/test/rect_test.js +0 -60
  357. package/test/remote_test.js +0 -117
  358. package/test/safari_test.js +0 -108
  359. package/test/session_test.js +0 -99
  360. package/test/stale_element_test.js +0 -63
  361. package/test/tag_name_test.js +0 -36
  362. package/test/testing/assert_test.js +0 -373
  363. package/test/testing/index_test.js +0 -224
  364. package/test/upload_test.js +0 -86
  365. package/test/window_test.js +0 -161
  366. package/testing/assert.js +0 -378
package/firefox.js ADDED
@@ -0,0 +1,789 @@
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 Defines the {@linkplain Driver WebDriver} client for Firefox.
20
+ * Before using this module, you must download the latest
21
+ * [geckodriver release] and ensure it can be found on your system [PATH].
22
+ *
23
+ * Each FirefoxDriver instance will be created with an anonymous profile,
24
+ * ensuring browser historys do not share session data (cookies, history, cache,
25
+ * offline storage, etc.)
26
+ *
27
+ * __Customizing the Firefox Profile__
28
+ *
29
+ * The profile used for each WebDriver session may be configured using the
30
+ * {@linkplain Options} class. For example, you may install an extension, like
31
+ * Firebug:
32
+ *
33
+ * const {Builder} = require('selenium-webdriver');
34
+ * const firefox = require('selenium-webdriver/firefox');
35
+ *
36
+ * let options = new firefox.Options()
37
+ * .addExtensions('/path/to/firebug.xpi')
38
+ * .setPreference('extensions.firebug.showChromeErrors', true);
39
+ *
40
+ * let driver = new Builder()
41
+ * .forBrowser('firefox')
42
+ * .setFirefoxOptions(options)
43
+ * .build();
44
+ *
45
+ * The {@linkplain Options} class may also be used to configure WebDriver based
46
+ * on a pre-existing browser profile:
47
+ *
48
+ * let profile = '/usr/local/home/bob/.mozilla/firefox/3fgog75h.testing';
49
+ * let options = new firefox.Options().setProfile(profile);
50
+ *
51
+ * The FirefoxDriver will _never_ modify a pre-existing profile; instead it will
52
+ * create a copy for it to modify. By extension, there are certain browser
53
+ * preferences that are required for WebDriver to function properly and they
54
+ * will always be overwritten.
55
+ *
56
+ * __Using a Custom Firefox Binary__
57
+ *
58
+ * On Windows and MacOS, the FirefoxDriver will search for Firefox in its
59
+ * default installation location:
60
+ *
61
+ * - Windows: C:\Program Files and C:\Program Files (x86).
62
+ * - MacOS: /Applications/Firefox.app
63
+ *
64
+ * For Linux, Firefox will always be located on the PATH: `$(where firefox)`.
65
+ *
66
+ * Several methods are provided for starting Firefox with a custom executable.
67
+ * First, on Windows and MacOS, you may configure WebDriver to check the default
68
+ * install location for a non-release channel. If the requested channel cannot
69
+ * be found in its default location, WebDriver will fallback to searching your
70
+ * PATH. _Note:_ on Linux, Firefox is _always_ located on your path, regardless
71
+ * of the requested channel.
72
+ *
73
+ * const {Builder} = require('selenium-webdriver');
74
+ * const firefox = require('selenium-webdriver/firefox');
75
+ *
76
+ * let options = new firefox.Options().setBinary(firefox.Channel.NIGHTLY);
77
+ * let driver = new Builder()
78
+ * .forBrowser('firefox')
79
+ * .setFirefoxOptions(options)
80
+ * .build();
81
+ *
82
+ * On all platforms, you may configrue WebDriver to use a Firefox specific
83
+ * executable:
84
+ *
85
+ * let options = new firefox.Options()
86
+ * .setBinary('/my/firefox/install/dir/firefox-bin');
87
+ *
88
+ * __Remote Testing__
89
+ *
90
+ * You may customize the Firefox binary and profile when running against a
91
+ * remote Selenium server. Your custom profile will be packaged as a zip and
92
+ * transfered to the remote host for use. The profile will be transferred
93
+ * _once for each new session_. The performance impact should be minimal if
94
+ * you've only configured a few extra browser preferences. If you have a large
95
+ * profile with several extensions, you should consider installing it on the
96
+ * remote host and defining its path via the {@link Options} class. Custom
97
+ * binaries are never copied to remote machines and must be referenced by
98
+ * installation path.
99
+ *
100
+ * const {Builder} = require('selenium-webdriver');
101
+ * const firefox = require('selenium-webdriver/firefox');
102
+ *
103
+ * let options = new firefox.Options()
104
+ * .setProfile('/profile/path/on/remote/host')
105
+ * .setBinary('/install/dir/on/remote/host/firefox-bin');
106
+ *
107
+ * let driver = new Builder()
108
+ * .forBrowser('firefox')
109
+ * .usingServer('http://127.0.0.1:4444/wd/hub')
110
+ * .setFirefoxOptions(options)
111
+ * .build();
112
+ *
113
+ * [geckodriver release]: https://github.com/mozilla/geckodriver/releases/
114
+ * [PATH]: http://en.wikipedia.org/wiki/PATH_%28variable%29
115
+ */
116
+
117
+ 'use strict';
118
+
119
+ const path = require('path');
120
+ const url = require('url');
121
+
122
+ const Symbols = require('./lib/symbols');
123
+ const command = require('./lib/command');
124
+ const exec = require('./io/exec');
125
+ const http = require('./http');
126
+ const httpUtil = require('./http/util');
127
+ const io = require('./io');
128
+ const net = require('./net');
129
+ const portprober = require('./net/portprober');
130
+ const remote = require('./remote');
131
+ const webdriver = require('./lib/webdriver');
132
+ const zip = require('./io/zip');
133
+ const {Browser, Capabilities} = require('./lib/capabilities');
134
+ const {Zip} = require('./io/zip');
135
+
136
+
137
+ /**
138
+ * Thrown when there an add-on is malformed.
139
+ * @final
140
+ */
141
+ class AddonFormatError extends Error {
142
+ /** @param {string} msg The error message. */
143
+ constructor(msg) {
144
+ super(msg);
145
+ /** @override */
146
+ this.name = this.constructor.name;
147
+ }
148
+ }
149
+
150
+
151
+ /**
152
+ * Installs an extension to the given directory.
153
+ * @param {string} extension Path to the xpi extension file to install.
154
+ * @param {string} dir Path to the directory to install the extension in.
155
+ * @return {!Promise<string>} A promise for the add-on ID once
156
+ * installed.
157
+ */
158
+ async function installExtension(extension, dir) {
159
+ if (extension.slice(-4) !== '.xpi') {
160
+ throw Error('Path ath is not a xpi file: ' + extension);
161
+ }
162
+
163
+ let archive = await zip.load(extension);
164
+ if (!archive.has('manifest.json')) {
165
+ throw new AddonFormatError(`Couldn't find manifest.json in ${extension}`);
166
+ }
167
+
168
+ let buf = await archive.getFile('manifest.json');
169
+ let parsedJSON = JSON.parse(buf.toString('utf8'));
170
+
171
+ let { browser_specific_settings } =
172
+ /** @type {{browser_specific_settings:{gecko:{id:string}}}} */
173
+ parsedJSON;
174
+
175
+ if (
176
+ browser_specific_settings &&
177
+ browser_specific_settings.gecko
178
+ ) {
179
+ /* browser_specific_settings is an alternative to applications
180
+ * It is meant to facilitate cross-browser plugins since Firefox48
181
+ * see https://bugzilla.mozilla.org/show_bug.cgi?id=1262005
182
+ */
183
+ parsedJSON.applications = browser_specific_settings;
184
+ }
185
+
186
+ let { applications } =
187
+ /** @type {{applications:{gecko:{id:string}}}} */
188
+ parsedJSON;
189
+ if (!(applications && applications.gecko && applications.gecko.id)) {
190
+ throw new AddonFormatError(`Could not find add-on ID for ${extension}`);
191
+ }
192
+
193
+ await io.copy(extension, `${path.join(dir, applications.gecko.id)}.xpi`);
194
+ return applications.gecko.id;
195
+ }
196
+
197
+
198
+ class Profile {
199
+ constructor() {
200
+ /** @private {?string} */
201
+ this.template_ = null;
202
+
203
+ /** @private {!Array<string>} */
204
+ this.extensions_ = [];
205
+ }
206
+
207
+ addExtensions(/** !Array<string> */paths) {
208
+ this.extensions_ = this.extensions_.concat(...paths);
209
+ }
210
+
211
+ /**
212
+ * @return {(!Promise<string>|undefined)} a promise for a base64 encoded
213
+ * profile, or undefined if there's no data to include.
214
+ */
215
+ [Symbols.serialize]() {
216
+ if (this.template_ || this.extensions_.length) {
217
+ return buildProfile(this.template_, this.extensions_);
218
+ }
219
+ return undefined;
220
+ }
221
+ }
222
+
223
+
224
+ /**
225
+ * @param {?string} template path to an existing profile to use as a template.
226
+ * @param {!Array<string>} extensions paths to extensions to install in the new
227
+ * profile.
228
+ * @return {!Promise<string>} a promise for the base64 encoded profile.
229
+ */
230
+ async function buildProfile(template, extensions) {
231
+ let dir = template;
232
+
233
+ if (extensions.length) {
234
+ dir = await io.tmpDir();
235
+ if (template) {
236
+ await io.copyDir(
237
+ /** @type {string} */(template),
238
+ dir, /(parent\.lock|lock|\.parentlock)/);
239
+ }
240
+
241
+ const extensionsDir = path.join(dir, 'extensions');
242
+ await io.mkdir(extensionsDir);
243
+
244
+ for (let i = 0; i < extensions.length; i++) {
245
+ await installExtension(extensions[i], extensionsDir);
246
+ }
247
+ }
248
+
249
+ let zip = new Zip;
250
+ return zip.addDir(dir)
251
+ .then(() => zip.toBuffer())
252
+ .then(buf => buf.toString('base64'));
253
+ }
254
+
255
+
256
+ /**
257
+ * Configuration options for the FirefoxDriver.
258
+ */
259
+ class Options extends Capabilities {
260
+ /**
261
+ * @param {(Capabilities|Map<string, ?>|Object)=} other Another set of
262
+ * capabilities to initialize this instance from.
263
+ */
264
+ constructor(other) {
265
+ super(other);
266
+ this.setBrowserName(Browser.FIREFOX);
267
+ }
268
+
269
+ /**
270
+ * @return {!Object}
271
+ * @private
272
+ */
273
+ firefoxOptions_() {
274
+ let options = this.get('moz:firefoxOptions');
275
+ if (!options) {
276
+ options = {};
277
+ this.set('moz:firefoxOptions', options);
278
+ }
279
+ return options;
280
+ }
281
+
282
+ /**
283
+ * @return {!Profile}
284
+ * @private
285
+ */
286
+ profile_() {
287
+ let options = this.firefoxOptions_();
288
+ if (!options.profile) {
289
+ options.profile = new Profile();
290
+ }
291
+ return options.profile;
292
+ }
293
+
294
+ /**
295
+ * Specify additional command line arguments that should be used when starting
296
+ * the Firefox browser.
297
+ *
298
+ * @param {...(string|!Array<string>)} args The arguments to include.
299
+ * @return {!Options} A self reference.
300
+ */
301
+ addArguments(...args) {
302
+ if (args.length) {
303
+ let options = this.firefoxOptions_();
304
+ options.args = options.args ? options.args.concat(...args) : args;
305
+ }
306
+ return this;
307
+ }
308
+
309
+ /**
310
+ * Configures the geckodriver to start Firefox in headless mode.
311
+ *
312
+ * @return {!Options} A self reference.
313
+ */
314
+ headless() {
315
+ return this.addArguments('-headless');
316
+ }
317
+
318
+ /**
319
+ * Sets the initial window size when running in
320
+ * {@linkplain #headless headless} mode.
321
+ *
322
+ * @param {{width: number, height: number}} size The desired window size.
323
+ * @return {!Options} A self reference.
324
+ * @throws {TypeError} if width or height is unspecified, not a number, or
325
+ * less than or equal to 0.
326
+ */
327
+ windowSize({width, height}) {
328
+ function checkArg(arg) {
329
+ if (typeof arg !== 'number' || arg <= 0) {
330
+ throw TypeError('Arguments must be {width, height} with numbers > 0');
331
+ }
332
+ }
333
+ checkArg(width);
334
+ checkArg(height);
335
+ return this.addArguments(`--width=${width}`, `--height=${height}`);
336
+ }
337
+
338
+ /**
339
+ * Add extensions that should be installed when starting Firefox.
340
+ *
341
+ * @param {...string} paths The paths to the extension XPI files to install.
342
+ * @return {!Options} A self reference.
343
+ */
344
+ addExtensions(...paths) {
345
+ this.profile_().addExtensions(paths);
346
+ return this;
347
+ }
348
+
349
+ /**
350
+ * @param {string} key the preference key.
351
+ * @param {(string|number|boolean)} value the preference value.
352
+ * @return {!Options} A self reference.
353
+ * @throws {TypeError} if either the key or value has an invalid type.
354
+ */
355
+ setPreference(key, value) {
356
+ if (typeof key !== 'string') {
357
+ throw TypeError(`key must be a string, but got ${typeof key}`);
358
+ }
359
+ if (typeof value !== 'string'
360
+ && typeof value !== 'number'
361
+ && typeof value !== 'boolean') {
362
+ throw TypeError(
363
+ `value must be a string, number, or boolean, but got ${typeof value}`);
364
+ }
365
+ let options = this.firefoxOptions_();
366
+ options.prefs = options.prefs || {};
367
+ options.prefs[key] = value;
368
+ return this;
369
+ }
370
+
371
+ /**
372
+ * Sets the path to an existing profile to use as a template for new browser
373
+ * sessions. This profile will be copied for each new session - changes will
374
+ * not be applied to the profile itself.
375
+ *
376
+ * @param {string} profile The profile to use.
377
+ * @return {!Options} A self reference.
378
+ * @throws {TypeError} if profile is not a string.
379
+ */
380
+ setProfile(profile) {
381
+ if (typeof profile !== 'string') {
382
+ throw TypeError(`profile must be a string, but got ${typeof profile}`);
383
+ }
384
+ this.profile_().template_ = profile;
385
+ return this;
386
+ }
387
+
388
+ /**
389
+ * Sets the binary to use. The binary may be specified as the path to a
390
+ * Firefox executable or a desired release {@link Channel}.
391
+ *
392
+ * @param {(string|!Channel)} binary The binary to use.
393
+ * @return {!Options} A self reference.
394
+ * @throws {TypeError} If `binary` is an invalid type.
395
+ */
396
+ setBinary(binary) {
397
+ if (binary instanceof Channel || typeof binary === 'string') {
398
+ this.firefoxOptions_().binary = binary;
399
+ return this;
400
+ }
401
+ throw TypeError('binary must be a string path or Channel object');
402
+ }
403
+ }
404
+
405
+
406
+ /**
407
+ * Enum of available command contexts.
408
+ *
409
+ * Command contexts are specific to Marionette, and may be used with the
410
+ * {@link #context=} method. Contexts allow you to direct all subsequent
411
+ * commands to either "content" (default) or "chrome". The latter gives
412
+ * you elevated security permissions.
413
+ *
414
+ * @enum {string}
415
+ */
416
+ const Context = {
417
+ CONTENT: "content",
418
+ CHROME: "chrome",
419
+ };
420
+
421
+
422
+ const GECKO_DRIVER_EXE =
423
+ process.platform === 'win32' ? 'geckodriver.exe' : 'geckodriver';
424
+
425
+
426
+ /**
427
+ * _Synchronously_ attempts to locate the geckodriver executable on the current
428
+ * system.
429
+ *
430
+ * @return {?string} the located executable, or `null`.
431
+ */
432
+ function locateSynchronously() {
433
+ return io.findInPath(GECKO_DRIVER_EXE, true);
434
+ }
435
+
436
+
437
+ /**
438
+ * @return {string} .
439
+ * @throws {Error}
440
+ */
441
+ function findGeckoDriver() {
442
+ let exe = locateSynchronously();
443
+ if (!exe) {
444
+ throw Error(
445
+ 'The ' + GECKO_DRIVER_EXE + ' executable could not be found on the current ' +
446
+ 'PATH. Please download the latest version from ' +
447
+ 'https://github.com/mozilla/geckodriver/releases/ ' +
448
+ 'and ensure it can be found on your PATH.');
449
+ }
450
+ return exe;
451
+ }
452
+
453
+
454
+ /**
455
+ * @param {string} file Path to the file to find, relative to the program files
456
+ * root.
457
+ * @return {!Promise<?string>} A promise for the located executable.
458
+ * The promise will resolve to {@code null} if Firefox was not found.
459
+ */
460
+ function findInProgramFiles(file) {
461
+ let files = [
462
+ process.env['PROGRAMFILES'] || 'C:\\Program Files',
463
+ process.env['PROGRAMFILES(X86)'] || 'C:\\Program Files (x86)'
464
+ ].map(prefix => path.join(prefix, file));
465
+ return io.exists(files[0]).then(function(exists) {
466
+ return exists ? files[0] : io.exists(files[1]).then(function(exists) {
467
+ return exists ? files[1] : null;
468
+ });
469
+ });
470
+ }
471
+
472
+
473
+ /** @enum {string} */
474
+ const ExtensionCommand = {
475
+ GET_CONTEXT: 'getContext',
476
+ SET_CONTEXT: 'setContext',
477
+ INSTALL_ADDON: 'install addon',
478
+ UNINSTALL_ADDON: 'uninstall addon',
479
+ };
480
+
481
+
482
+ /**
483
+ * Creates a command executor with support for Marionette's custom commands.
484
+ * @param {!Promise<string>} serverUrl The server's URL.
485
+ * @return {!command.Executor} The new command executor.
486
+ */
487
+ function createExecutor(serverUrl) {
488
+ let client = serverUrl.then(url => new http.HttpClient(url));
489
+ let executor = new http.Executor(client);
490
+ configureExecutor(executor);
491
+ return executor;
492
+ }
493
+
494
+
495
+ /**
496
+ * Configures the given executor with Firefox-specific commands.
497
+ * @param {!http.Executor} executor the executor to configure.
498
+ */
499
+ function configureExecutor(executor) {
500
+ executor.defineCommand(
501
+ ExtensionCommand.GET_CONTEXT,
502
+ 'GET',
503
+ '/session/:sessionId/moz/context');
504
+
505
+ executor.defineCommand(
506
+ ExtensionCommand.SET_CONTEXT,
507
+ 'POST',
508
+ '/session/:sessionId/moz/context');
509
+
510
+ executor.defineCommand(
511
+ ExtensionCommand.INSTALL_ADDON,
512
+ 'POST',
513
+ '/session/:sessionId/moz/addon/install');
514
+
515
+ executor.defineCommand(
516
+ ExtensionCommand.UNINSTALL_ADDON,
517
+ 'POST',
518
+ '/session/:sessionId/moz/addon/uninstall');
519
+ }
520
+
521
+
522
+ /**
523
+ * Creates {@link selenium-webdriver/remote.DriverService} instances that manage
524
+ * a [geckodriver](https://github.com/mozilla/geckodriver) server in a child
525
+ * process.
526
+ */
527
+ class ServiceBuilder extends remote.DriverService.Builder {
528
+ /**
529
+ * @param {string=} opt_exe Path to the server executable to use. If omitted,
530
+ * the builder will attempt to locate the geckodriver on the system PATH.
531
+ */
532
+ constructor(opt_exe) {
533
+ super(opt_exe || findGeckoDriver());
534
+ this.setLoopback(true); // Required.
535
+ }
536
+
537
+ /**
538
+ * Enables verbose logging.
539
+ *
540
+ * @param {boolean=} opt_trace Whether to enable trace-level logging. By
541
+ * default, only debug logging is enabled.
542
+ * @return {!ServiceBuilder} A self reference.
543
+ */
544
+ enableVerboseLogging(opt_trace) {
545
+ return this.addArguments(opt_trace ? '-vv' : '-v');
546
+ }
547
+ }
548
+
549
+
550
+ /**
551
+ * A WebDriver client for Firefox.
552
+ */
553
+ class Driver extends webdriver.WebDriver {
554
+ /**
555
+ * Creates a new Firefox session.
556
+ *
557
+ * @param {(Options|Capabilities|Object)=} opt_config The
558
+ * configuration options for this driver, specified as either an
559
+ * {@link Options} or {@link Capabilities}, or as a raw hash object.
560
+ * @param {(http.Executor|remote.DriverService)=} opt_executor Either a
561
+ * pre-configured command executor to use for communicating with an
562
+ * externally managed remote end (which is assumed to already be running),
563
+ * or the `DriverService` to use to start the geckodriver in a child
564
+ * process.
565
+ *
566
+ * If an executor is provided, care should e taken not to use reuse it with
567
+ * other clients as its internal command mappings will be updated to support
568
+ * Firefox-specific commands.
569
+ *
570
+ * _This parameter may only be used with Mozilla's GeckoDriver._
571
+ *
572
+ * @throws {Error} If a custom command executor is provided and the driver is
573
+ * configured to use the legacy FirefoxDriver from the Selenium project.
574
+ * @return {!Driver} A new driver instance.
575
+ */
576
+ static createSession(opt_config, opt_executor) {
577
+ let caps =
578
+ opt_config instanceof Capabilities
579
+ ? opt_config : new Options(opt_config);
580
+
581
+ let executor;
582
+ let onQuit;
583
+
584
+ if (opt_executor instanceof http.Executor) {
585
+ executor = opt_executor;
586
+ configureExecutor(executor);
587
+ } else if (opt_executor instanceof remote.DriverService) {
588
+ executor = createExecutor(opt_executor.start());
589
+ onQuit = () => opt_executor.kill();
590
+ } else {
591
+ let service = new ServiceBuilder().build();
592
+ executor = createExecutor(service.start());
593
+ onQuit = () => service.kill();
594
+ }
595
+
596
+ return /** @type {!Driver} */(super.createSession(executor, caps, onQuit));
597
+ }
598
+
599
+ /**
600
+ * This function is a no-op as file detectors are not supported by this
601
+ * implementation.
602
+ * @override
603
+ */
604
+ setFileDetector() {
605
+ }
606
+
607
+ /**
608
+ * Get the context that is currently in effect.
609
+ *
610
+ * @return {!Promise<Context>} Current context.
611
+ */
612
+ getContext() {
613
+ return this.execute(new command.Command(ExtensionCommand.GET_CONTEXT));
614
+ }
615
+
616
+ /**
617
+ * Changes target context for commands between chrome- and content.
618
+ *
619
+ * Changing the current context has a stateful impact on all subsequent
620
+ * commands. The {@link Context.CONTENT} context has normal web
621
+ * platform document permissions, as if you would evaluate arbitrary
622
+ * JavaScript. The {@link Context.CHROME} context gets elevated
623
+ * permissions that lets you manipulate the browser chrome itself,
624
+ * with full access to the XUL toolkit.
625
+ *
626
+ * Use your powers wisely.
627
+ *
628
+ * @param {!Promise<void>} ctx The context to switch to.
629
+ */
630
+ setContext(ctx) {
631
+ return this.execute(
632
+ new command.Command(ExtensionCommand.SET_CONTEXT)
633
+ .setParameter("context", ctx));
634
+ }
635
+
636
+ /**
637
+ * Installs a new addon with the current session. This function will return an
638
+ * ID that may later be used to {@linkplain #uninstallAddon uninstall} the
639
+ * addon.
640
+ *
641
+ *
642
+ * @param {string} path Path on the local filesystem to the web extension to
643
+ * install.
644
+ * @param {boolean} temporary Flag indicating whether the extension should be
645
+ * installed temporarily - gets removed on restart
646
+ * @return {!Promise<string>} A promise that will resolve to an ID for the
647
+ * newly installed addon.
648
+ * @see #uninstallAddon
649
+ */
650
+ async installAddon(path, temporary=false) {
651
+ let buf = await io.read(path);
652
+ return this.execute(
653
+ new command.Command(ExtensionCommand.INSTALL_ADDON)
654
+ .setParameter('addon', buf.toString('base64'))
655
+ .setParameter('temporary', temporary));
656
+ }
657
+
658
+ /**
659
+ * Uninstalls an addon from the current browser session's profile.
660
+ *
661
+ * @param {(string|!Promise<string>)} id ID of the addon to uninstall.
662
+ * @return {!Promise} A promise that will resolve when the operation has
663
+ * completed.
664
+ * @see #installAddon
665
+ */
666
+ async uninstallAddon(id) {
667
+ id = await Promise.resolve(id);
668
+ return this.execute(
669
+ new command.Command(ExtensionCommand.UNINSTALL_ADDON)
670
+ .setParameter('id', id));
671
+ }
672
+ }
673
+
674
+
675
+ /**
676
+ * Provides methods for locating the executable for a Firefox release channel
677
+ * on Windows and MacOS. For other systems (i.e. Linux), Firefox will always
678
+ * be located on the system PATH.
679
+ *
680
+ * @final
681
+ */
682
+ class Channel {
683
+ /**
684
+ * @param {string} darwin The path to check when running on MacOS.
685
+ * @param {string} win32 The path to check when running on Windows.
686
+ */
687
+ constructor(darwin, win32) {
688
+ /** @private @const */ this.darwin_ = darwin;
689
+ /** @private @const */ this.win32_ = win32;
690
+ /** @private {Promise<string>} */
691
+ this.found_ = null;
692
+ }
693
+
694
+ /**
695
+ * Attempts to locate the Firefox executable for this release channel. This
696
+ * will first check the default installation location for the channel before
697
+ * checking the user's PATH. The returned promise will be rejected if Firefox
698
+ * can not be found.
699
+ *
700
+ * @return {!Promise<string>} A promise for the location of the located
701
+ * Firefox executable.
702
+ */
703
+ locate() {
704
+ if (this.found_) {
705
+ return this.found_;
706
+ }
707
+
708
+ let found;
709
+ switch (process.platform) {
710
+ case 'darwin':
711
+ found = io.exists(this.darwin_)
712
+ .then(exists => exists ? this.darwin_ : io.findInPath('firefox'));
713
+ break;
714
+
715
+ case 'win32':
716
+ found = findInProgramFiles(this.win32_)
717
+ .then(found => found || io.findInPath('firefox.exe'));
718
+ break;
719
+
720
+ default:
721
+ found = Promise.resolve(io.findInPath('firefox'));
722
+ break;
723
+ }
724
+
725
+ this.found_ = found.then(found => {
726
+ if (found) {
727
+ // TODO: verify version info.
728
+ return found;
729
+ }
730
+ throw Error('Could not locate Firefox on the current system');
731
+ });
732
+ return this.found_;
733
+ }
734
+
735
+ /** @return {!Promise<string>} */
736
+ [Symbols.serialize]() {
737
+ return this.locate();
738
+ }
739
+ }
740
+
741
+
742
+ /**
743
+ * Firefox's developer channel.
744
+ * @const
745
+ * @see <https://www.mozilla.org/en-US/firefox/channel/desktop/#aurora>
746
+ */
747
+ Channel.AURORA = new Channel(
748
+ '/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin',
749
+ 'Firefox Developer Edition\\firefox.exe');
750
+
751
+ /**
752
+ * Firefox's beta channel. Note this is provided mainly for convenience as
753
+ * the beta channel has the same installation location as the main release
754
+ * channel.
755
+ * @const
756
+ * @see <https://www.mozilla.org/en-US/firefox/channel/desktop/#beta>
757
+ */
758
+ Channel.BETA = new Channel(
759
+ '/Applications/Firefox.app/Contents/MacOS/firefox-bin',
760
+ 'Mozilla Firefox\\firefox.exe');
761
+
762
+ /**
763
+ * Firefox's release channel.
764
+ * @const
765
+ * @see <https://www.mozilla.org/en-US/firefox/desktop/>
766
+ */
767
+ Channel.RELEASE = new Channel(
768
+ '/Applications/Firefox.app/Contents/MacOS/firefox-bin',
769
+ 'Mozilla Firefox\\firefox.exe');
770
+
771
+ /**
772
+ * Firefox's nightly release channel.
773
+ * @const
774
+ * @see <https://www.mozilla.org/en-US/firefox/channel/desktop/#nightly>
775
+ */
776
+ Channel.NIGHTLY = new Channel(
777
+ '/Applications/Firefox Nightly.app/Contents/MacOS/firefox-bin',
778
+ 'Nightly\\firefox.exe');
779
+
780
+
781
+ // PUBLIC API
782
+
783
+
784
+ exports.Channel = Channel;
785
+ exports.Context = Context;
786
+ exports.Driver = Driver;
787
+ exports.Options = Options;
788
+ exports.ServiceBuilder = ServiceBuilder;
789
+ exports.locateSynchronously = locateSynchronously;