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

Commit fc53bf1

Browse files
committed
feat(mobile): add extended wd commands for appium
1 parent bed5b07 commit fc53bf1

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

lib/browser.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {Plugins} from './plugins';
1111
import {protractor} from './ptor';
1212
import * as helper from './util';
1313

14+
import {extend as extendWD, ExtendedWebDriver} from 'webdriver-js-extender';
15+
1416
let clientSideScripts = require('./clientsidescripts');
1517
let webdriver = require('selenium-webdriver');
1618

@@ -118,9 +120,9 @@ export class Browser extends Webdriver {
118120
* The wrapped webdriver instance. Use this to interact with pages that do
119121
* not contain Angular (such as a log-in screen).
120122
*
121-
* @type {webdriver.WebDriver}
123+
* @type {ExtendedWebDriver}
122124
*/
123-
driver: webdriver.WebDriver;
125+
driver: ExtendedWebDriver;
124126

125127
/**
126128
* Helper function for finding elements.
@@ -248,23 +250,25 @@ export class Browser extends Webdriver {
248250
// wait for Angular to sync up before performing the action. This does not
249251
// include functions which are overridden by protractor below.
250252
let methodsToSync = ['getCurrentUrl', 'getPageSource', 'getTitle'];
253+
let extendWDInstance = extendWD(webdriverInstance);
254+
251255

252256

253257
// Mix all other driver functionality into Protractor.
254258
Object.getOwnPropertyNames(webdriver.WebDriver.prototype)
255259
.forEach((method: string) => {
256-
if (!this[method] && typeof webdriverInstance[method] == 'function') {
260+
if (!this[method] && typeof extendWDInstance[method] == 'function') {
257261
if (methodsToSync.indexOf(method) !== -1) {
258262
mixin(
259-
this, webdriverInstance, method,
263+
this, extendWDInstance, method,
260264
this.waitForAngular.bind(this));
261265
} else {
262-
mixin(this, webdriverInstance, method);
266+
mixin(this, extendWDInstance, method);
263267
}
264268
}
265269
});
266270

267-
this.driver = webdriverInstance;
271+
this.driver = extendWDInstance;
268272
this.element = buildElementHelper(this);
269273
this.$ = build$(this.element, webdriver.By);
270274
this.$$ = build$$(this.element, webdriver.By);

lib/selenium-webdriver/webdriver.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,40 @@ webdriver.WebElement.prototype.isDisplayed = function() {};
537537
* resolved to the screenshot as a base-64 encoded PNG.
538538
*/
539539
webdriver.WebElement.prototype.takeScreenshot = function(opt_scroll) {};
540+
541+
542+
// EXTENDED WD METHODS
543+
544+
/**
545+
* Schedules a command to retrieve the network connection type
546+
*
547+
* Network connection types are a bitmask with:
548+
* 1 -> airplane mode
549+
* 2 -> wifi
550+
* 4 -> data
551+
*
552+
* @example
553+
* expect(browser.getNetworkConnection()).toBe(6); //Expect wifi and data on
554+
*
555+
* @returns {!webdriver.promise.Promise.<number>} A promise that will be
556+
* resolved with the current network connection type.
557+
*/
558+
webdriver.WebDriver.prototype.getNetworkConnection = function() {};
559+
560+
/**
561+
* Schedules a command to set the network connection type
562+
*
563+
* Network connection types are a bitmask with:
564+
* 1 -> airplane mode
565+
* 2 -> wifi
566+
* 4 -> data
567+
*
568+
* @example
569+
* browser.setNetworkConnection(1); //Turn on airplane mode
570+
* expect(browser.getNetworkConnection()).toBe(1);
571+
*
572+
* @param {number} type The type to set the network connection to
573+
* @returns {!webdriver.promise.Promise.<void>} A promise that will be
574+
* resolved when the network connection type is set
575+
*/
576+
webdriver.WebDriver.prototype.setNetworkConnection = function(type) {};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"saucelabs": "~1.2.0",
2323
"selenium-webdriver": "2.53.3",
2424
"source-map-support": "~0.4.0",
25+
"webdriver-js-extender": "^0.1.1",
2526
"webdriver-manager": "^10.2.1"
2627
},
2728
"devDependencies": {

0 commit comments

Comments
 (0)