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 This is an example of working with the different Firefox
|
20 | * release channels. Before running this example, you will need to have
|
21 | * installed Firefox's release, nightly, and developer editions:
|
22 | *
|
23 | * - https://www.mozilla.org/en-US/firefox/channel/desktop/#aurora
|
24 | * - https://www.mozilla.org/en-US/firefox/channel/desktop/#nightly
|
25 | */
|
26 |
|
27 |
|
28 |
|
29 | const { Builder, By, Key, promise, until } = require('..')
|
30 | const { Channel, Options } = require('../firefox')
|
31 |
|
32 | let i = 0
|
33 | function resposition(driver) {
|
34 | return driver
|
35 | .manage()
|
36 | .window()
|
37 | .setRect({
|
38 | width: 600,
|
39 | height: 400,
|
40 | x: 300 * i++,
|
41 | y: 0,
|
42 | })
|
43 | }
|
44 |
|
45 | async function doSearch(driver) {
|
46 | try {
|
47 | // Start on the base about page.
|
48 | await driver.get('about:')
|
49 | // Reposition so users can see the three windows.
|
50 | await resposition(driver)
|
51 | // Pause so users can see the magic.
|
52 | await promise.delayed(750)
|
53 | // Now do the rest.
|
54 | await driver.get('http://www.google.com/ncr')
|
55 | await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
|
56 | await driver.wait(until.titleIs('webdriver - Google Search'), 1000)
|
57 | console.log('Success!')
|
58 | } catch (ex) {
|
59 | console.log('An error occured! ' + ex)
|
60 | } finally {
|
61 | await driver.quit()
|
62 | }
|
63 | }
|
64 |
|
65 | function createDriver(channel) {
|
66 | let options = new Options().setBinary(channel)
|
67 | return new Builder().forBrowser('firefox').setFirefoxOptions(options).build()
|
68 | }
|
69 |
|
70 | Promise.all([
|
71 | doSearch(createDriver(Channel.RELEASE)),
|
72 | doSearch(createDriver(Channel.AURORA)), // Developer Edition.
|
73 | doSearch(createDriver(Channel.NIGHTLY)),
|
74 | ]).then(
|
75 | (_) => {
|
76 | console.log('All done!')
|
77 | },
|
78 | (err) => {
|
79 | console.error('An error occured! ' + err)
|
80 | setTimeout(() => {
|
81 | throw err
|
82 | }, 0)
|
83 | }
|
84 | )
|