Path: blob/trunk/javascript/selenium-webdriver/example/google_search_test.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* @fileoverview An example test that may be run using Mocha.19*20* This example uses the `selenium-webdriver/testing.suite` function, which will21* automatically run tests against every available WebDriver browser on the22* current system. Alternatively, you may use the `SELENIUM_BROWSER`23* environment variable to narrow the scope at runtime.24*25* Usage:26*27* # Automatically determine which browsers to run against.28* mocha -t 10000 selenium-webdriver/example/google_search_test.js29*30* # Configure tests to only run against Google Chrome.31* SELENIUM_BROWSER=chrome \32* mocha -t 10000 selenium-webdriver/example/google_search_test.js33*/3435const { Browser, By, Key, until } = require('..')36const { ignore, suite } = require('../testing')3738suite(function (env) {39describe('Google Search', function () {40let driver4142before(async function () {43// env.builder() returns a Builder instance preconfigured for the44// envrionment's target browser (you may still define browser specific45// options if necessary (i.e. firefox.Options or chrome.Options)).46driver = await env.builder().build()47})4849it('demo', async function () {50await driver.get('https://www.google.com/ncr')51await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)52await driver.wait(until.titleIs('webdriver - Google Search'), 1000)53})5455// The ignore function returns wrappers around describe & it that will56// suppress tests if the provided predicate returns true. You may provide57// any synchronous predicate. The env.browsers(...) function generates a58// predicate that will suppress tests if the env targets one of the59// specified browsers.60//61// This example is always configured to skip Chrome.62ignore(env.browsers(Browser.CHROME)).it('demo 2', async function () {63await driver.get('https://www.google.com/ncr')64await driver.wait(until.urlIs('https://www.google.com/'), 1500)65})6667after(() => driver && driver.quit())68})69})707172