firefox_channels.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * @fileoverview This is an example of working with the different Firefox
  19. * release channels. Before running this example, you will need to have
  20. * installed Firefox's release, nightly, and developer editions:
  21. *
  22. * - https://www.mozilla.org/en-US/firefox/channel/desktop/#aurora
  23. * - https://www.mozilla.org/en-US/firefox/channel/desktop/#nightly
  24. */
  25. 'use strict';
  26. const {Builder, By, Key, promise, until} = require('..');
  27. const {Channel, Options} = require('../firefox');
  28. let i = 0;
  29. function resposition(driver) {
  30. return driver.manage().window().setSize(600, 400)
  31. .then(_ => driver.manage().window().setPosition(300 * (i++), 0));
  32. }
  33. function doSearch(driver) {
  34. // Start on the base about page.
  35. return driver.get('about:')
  36. // Reposition so users can see the three windows.
  37. .then(_ => resposition(driver))
  38. // Pause so users can see the magic.
  39. .then(_ => promise.delayed(750))
  40. // Now do the rest.
  41. .then(_ => driver.get('http://www.google.com/ncr'))
  42. .then(_ =>
  43. driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN))
  44. .then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
  45. .then(_ => driver.quit());
  46. }
  47. function createDriver(channel) {
  48. let options = new Options().setBinary(channel);
  49. return new Builder().forBrowser('firefox').setFirefoxOptions(options).build();
  50. }
  51. // NOTE: disabling the promise manager so searches all run concurrently.
  52. // For more on the promise manager and its pending deprecation, see
  53. // https://github.com/SeleniumHQ/selenium/issues/2969
  54. promise.USE_PROMISE_MANAGER = false;
  55. Promise.all([
  56. doSearch(createDriver(Channel.RELEASE)),
  57. doSearch(createDriver(Channel.AURORA)), // Developer Edition.
  58. doSearch(createDriver(Channel.NIGHTLY)),
  59. ]).then(_ => {
  60. console.log('Success!');
  61. }, err => {
  62. console.error('An error occured! ' + err);
  63. setTimeout(() => {throw err}, 0);
  64. });