Path: blob/trunk/javascript/selenium-webdriver/test/remote_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')20const path = require('node:path')21const io = require('selenium-webdriver/io')22const cmd = require('selenium-webdriver/lib/command')23const remote = require('selenium-webdriver/remote')24const { CancellationError } = require('selenium-webdriver/http/util')2526describe('DriverService', function () {27describe('start()', function () {28var service2930beforeEach(function () {31service = new remote.DriverService(process.execPath, {32port: 1234,33args: ['-e', 'process.exit(1)'],34})35})3637afterEach(function () {38return service.kill()39})4041it('fails if child-process dies', function () {42return service.start(500).then(expectFailure, verifyFailure)43})4445function verifyFailure(e) {46assert.ok(!(e instanceof CancellationError))47assert.strictEqual('Server terminated early with status 1', e.message)48}4950function expectFailure() {51throw Error('expected to fail')52}53})54})5556describe('FileDetector', function () {57class ExplodingDriver {58execute() {59throw Error('unexpected call')60}61}6263it('returns the original path if the file does not exist', function () {64return io.tmpDir().then((dir) => {65let theFile = path.join(dir, 'not-there')66return new remote.FileDetector()67.handleFile(new ExplodingDriver(), theFile)68.then((f) => assert.strictEqual(f, theFile))69})70})7172it('returns the original path if it is a directory', function () {73return io.tmpDir().then((dir) => {74return new remote.FileDetector().handleFile(new ExplodingDriver(), dir).then((f) => assert.strictEqual(f, dir))75})76})7778it('attempts to upload valid files', function () {79return io.tmpFile().then((theFile) => {80return new remote.FileDetector()81.handleFile(82new (class FakeDriver {83execute(command) {84assert.strictEqual(command.getName(), cmd.Name.UPLOAD_FILE)85assert.strictEqual(typeof command.getParameters()['file'], 'string')86return Promise.resolve('success!')87}88})(),89theFile,90)91.then((f) => assert.strictEqual(f, 'success!'))92})93})94})959697