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 An example test that may be run using Mocha.
|
20 | *
|
21 | * This example uses the `selenium-webdriver/testing.suite` function, which will
|
22 | * automatically run tests against every available WebDriver browser on the
|
23 | * current system. Alternatively, you may use the `SELENIUM_BROWSER`
|
24 | * environment variable to narrow the scope at runtime.
|
25 | *
|
26 | * Usage:
|
27 | *
|
28 | * # Automatically determine which browsers to run against.
|
29 | * mocha -t 10000 selenium-webdriver/example/google_search_test.js
|
30 | *
|
31 | * # Configure tests to only run against Google Chrome.
|
32 | * SELENIUM_BROWSER=chrome \
|
33 | * mocha -t 10000 selenium-webdriver/example/google_search_test.js
|
34 | */
|
35 |
|
36 | const { Browser, By, Key, until } = require('..')
|
37 | const { ignore, suite } = require('../testing')
|
38 |
|
39 | suite(function (env) {
|
40 | describe('Google Search', function () {
|
41 | let driver
|
42 |
|
43 | before(async function () {
|
44 | // env.builder() returns a Builder instance preconfigured for the
|
45 | // envrionment's target browser (you may still define browser specific
|
46 | // options if necessary (i.e. firefox.Options or chrome.Options)).
|
47 | driver = await env.builder().build()
|
48 | })
|
49 |
|
50 | it('demo', async function () {
|
51 | await driver.get('https://www.google.com/ncr')
|
52 | await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)
|
53 | await driver.wait(until.titleIs('webdriver - Google Search'), 1000)
|
54 | })
|
55 |
|
56 | // The ignore function returns wrappers around describe & it that will
|
57 | // suppress tests if the provided predicate returns true. You may provide
|
58 | // any synchronous predicate. The env.browsers(...) function generates a
|
59 | // predicate that will suppress tests if the env targets one of the
|
60 | // specified browsers.
|
61 | //
|
62 | // This example is always configured to skip Chrome.
|
63 | ignore(env.browsers(Browser.CHROME)).it('demo 2', async function () {
|
64 | await driver.get('https://www.google.com/ncr')
|
65 | await driver.wait(until.urlIs('https://www.google.com/'), 1500)
|
66 | })
|
67 |
|
68 | after(() => driver && driver.quit())
|
69 | })
|
70 | })
|