Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Update to selenium 3.x #12

Merged
merged 9 commits into from
Jul 6, 2018
Merged
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: node_js
sudo: false
node_js:
- "4"
- "5"
- "6"
- "8"
- "10"

env:
global:
Expand Down
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,8 @@ You can view the full list of commands in [`lib/index.ts`](lib/index.ts#L8).
Usage
-----

If you are using a versoin of `selenium-webdriver` below `3.0.0-beta-1`, you
must use the `patch()` function before you create your webdriver instance:
Use WebDriver JS Extender's `extend` function on your webdriver instance:

```js
require('webdriver-js-extender').patch(
require('selenium-webdriver/lib/command'),
require('selenium-webdriver/executors'),
require('selenium-webdriver/http'));
```

Once you've patched `selenium-webdriver` (or if you're using version `3.x`), all
you need to do is run the `extend` function on your webdriver instance:

```js
var extendedWebdriver = require('webdriver-js-extender').extend(webdriver);
Expand Down
32 changes: 0 additions & 32 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {promise as wdpromise, WebDriver} from 'selenium-webdriver';

import {CommandDefinition} from './command_definition';
import * as commandDefinitions from './command_definitions';
import {DeferredExecutor} from './deferred_executor';
import {Extender} from './extender';

export interface ExtendedWebDriver extends WebDriver {
Expand Down Expand Up @@ -155,34 +154,3 @@ export function extend(baseDriver: WebDriver, fallbackGracefully = false): Exten

return extendedDriver;
}

/**
* Patches webdriver so that the extender can defie new commands.
*
* @example
* patch(require('selenium-webdriver/lib/command'),
* require('selenium-webdriver/executors'),
* require('selenium-webdriver/http'));
*
* @param {*} lib_command The object at 'selenium-webdriver/lib/command'
* @param {*} executors The object at 'selenium-webdriver/executors'
* @param {*} http The object at 'selenium-webdriver/http'
*/
export function patch(lib_command: any, executors: any, http: any) {
if (lib_command.DeferredExecutor === undefined) {
throw new Error(
'The version of `selenium-webdriver` you provided does ' +
'not use Deferred Executors. Are you using version 3.x or above? If ' +
'so, you do not need to call the `patch()` function.');
}
lib_command.DeferredExecutor = DeferredExecutor;
executors.DeferredExecutor = DeferredExecutor;
// Based off of
// https://github.com/SeleniumHQ/selenium/blob/selenium-2.53.0/javascript/node/selenium-webdriver/executors.js#L45
executors.createExecutor = (url: any, opt_agent?: any, opt_proxy?: any) => {
return new DeferredExecutor(wdpromise.when(url, (url: any) => {
var client = new http.HttpClient(url, opt_agent, opt_proxy);
return new http.Executor(client);
}));
};
}
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webdriver-js-extender",
"version": "1.0.0",
"version": "2.0.0",
"description": "A plugin which adds additional commands to selenium's javascript implementation of the webdriver client side API",
"scripts": {
"prepublish": "gulp prepublish",
Expand All @@ -22,13 +22,11 @@
"license": "MIT",
"typings": "built/lib/index.d.ts",
"dependencies": {
"@types/selenium-webdriver": "^2.53.35",
"selenium-webdriver": "^2.53.2"
"@types/selenium-webdriver": "^3.0.0",
"selenium-webdriver": "^3.0.1"
},
"devDependencies": {
"@types/es6-promise": "0.0.32",
"@types/jasmine": "^2.5.37",
"@types/node": "^6.0.46",
"clang-format": "^1.0.42",
"gulp": "^3.9.1",
"gulp-clang-format": "^1.0.23",
Expand All @@ -37,5 +35,8 @@
"run-sequence": "^1.2.2",
"selenium-mock": "^0.1.5",
"typescript": "^2.0.0"
},
"engines": {
"node": ">=6.9.x"
}
}
5 changes: 1 addition & 4 deletions spec/command_tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {MockAppium} from '../mock-server';
import {Session, CommandList} from '../mock-server/interfaces';
import {session as commandList} from '../mock-server/commands';
import {Command} from 'selenium-mock';
import {extend, patch, ExtendedWebDriver} from '../../lib';
import {extend, ExtendedWebDriver} from '../../lib';
let portfinder = require('portfinder');


Expand All @@ -28,9 +28,6 @@ export function initMockSeleniumStandaloneServerAndGetDriverFactory(annotateComm
let server: MockAppium;
let port: number;
beforeAll((done) => {
patch(require('selenium-webdriver/lib/command'),
require('selenium-webdriver/executors'),
require('selenium-webdriver/http'));
portfinder.getPort((err: Error, p: number) => {
if (err) {
done.fail(err);
Expand Down
2 changes: 1 addition & 1 deletion spec/command_tests/normal_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('normal tests', () => {
}).then((fileContents) => {
expect(fileContents).toBe('bar');
return driver.pullFolderFromDevice('/tmp/wd_js_ext/folder');
}).then((folderContents) => {
}).then((folderContents: any) => {
expect(folderContents['a.txt']).toBe('x');
expect(folderContents['b.txt']).toBe('y');
expect(folderContents['c.txt']).toBe('z');
Expand Down
52 changes: 0 additions & 52 deletions spec/deferred_executor_spec.ts

This file was deleted.

11 changes: 1 addition & 10 deletions spec/index_spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as webdriver from 'selenium-webdriver';
import {extend, patch} from '../lib';
import {DeferredExecutor} from '../lib/deferred_executor';
import {extend} from '../lib';
import {buildMockDriver, Data} from './mockdriver';


Expand Down Expand Up @@ -28,12 +27,4 @@ describe('extender', () => {
done();
});
});

it('should patch selenium-webdriver', () => {
patch(require('selenium-webdriver/lib/command'),
require('selenium-webdriver/executors'),
require('selenium-webdriver/http'));
expect(require('selenium-webdriver/executors').createExecutor(
'http://localhost')).toEqual(jasmine.any(DeferredExecutor));
});
});
2 changes: 1 addition & 1 deletion spec/mockdriver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as webdriver from 'selenium-webdriver';
let buildPath = require('selenium-webdriver/http').buildPath;
let buildPath = require('selenium-webdriver/lib/http').buildPath;

export interface Data {
sessionId: string;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
Expand Down