Path: blob/trunk/javascript/selenium-webdriver/test/builder_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'use strict'1819const assert = require('node:assert')2021const chrome = require('selenium-webdriver/chrome')22const edge = require('selenium-webdriver/edge')23const error = require('selenium-webdriver/lib/error')24const firefox = require('selenium-webdriver/firefox')25const ie = require('selenium-webdriver/ie')26const safari = require('selenium-webdriver/safari')27const test = require('../lib/test')28const { Browser } = require('selenium-webdriver/lib/capabilities')29const { Pages } = require('../lib/test')30const { Builder, Capabilities } = require('selenium-webdriver')3132test.suite(function (env) {33const BROWSER_MAP = new Map([34[Browser.CHROME, chrome.Driver],35[Browser.EDGE, edge.Driver],36[Browser.FIREFOX, firefox.Driver],37[Browser.INTERNET_EXPLORER, ie.Driver],38[Browser.SAFARI, safari.Driver],39])4041if (BROWSER_MAP.has(env.browser.name)) {42describe('builder creates thenable driver instances', function () {43let driver4445after(() => driver && driver.quit())4647it(env.browser.name, function () {48driver = env.builder().build()4950const want = BROWSER_MAP.get(env.browser.name)51assert.ok(driver instanceof want, `want ${want.name}, but got ${driver.name}`)52assert.strictEqual(typeof driver.then, 'function')5354return (55driver56.then((d) => assert.ok(d instanceof want, `want ${want.name}, but got ${d.name}`))57// Load something so the safari driver doesn't crash from starting and58// stopping in short time.59.then(() => driver.get(Pages.echoPage))60)61})62})63}6465if (BROWSER_MAP.has(env.browser.name)) {66describe('builder allows to set a single capability', function () {67let driver6869after(() => driver && driver.quit())7071it(env.browser.name, async function () {72let timeouts = { implicit: 0, pageLoad: 1000, script: 1000 }73driver = new Builder().setCapability('timeouts', timeouts).forBrowser(env.browser.name).build()7475let caps = await getCaps(driver)76assert.deepEqual(caps.get('timeouts'), timeouts)77})78})79}8081async function getCaps(driver) {82return driver.getCapabilities()83}8485describe('Builder', function () {86describe('catches incorrect use of browser options class', function () {87function test(key, options) {88it(key, async function () {89let builder = new Builder().withCapabilities(90new Capabilities().set('browserName', 'fake-browser-should-not-try-to-start').set(key, new options()),91)92try {93let driver = await builder.build()94await driver.quit()95return Promise.reject(Error('should have failed'))96} catch (ex) {97if (!(ex instanceof error.InvalidArgumentError)) {98throw ex99}100}101})102}103104test('chromeOptions', chrome.Options)105test('moz:firefoxOptions', firefox.Options)106test('safari.options', safari.Options)107})108})109})110111112