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

chore(typings): rename protractor to browser and add a protractor namespace #3214

Merged
merged 1 commit into from
May 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions lib/protractor.ts → lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {ProtractorBy} from './locators';
import {ElementArrayFinder, ElementFinder, build$, build$$} from './element';
export {ElementFinder, ElementArrayFinder};
import {Plugins} from './plugins';
import {protractor} from './ptor';

let clientSideScripts = require('./clientsidescripts');

Expand All @@ -16,8 +17,6 @@ let clientSideScripts = require('./clientsidescripts');
import * as EC from './expectedConditions';

let webdriver = require('selenium-webdriver');
let Command = require('selenium-webdriver/lib/command').Command;
let CommandName = require('selenium-webdriver/lib/command').Name;

// jshint browser: true
/* global angular */
Expand Down Expand Up @@ -76,14 +75,14 @@ export interface ElementHelper extends Function {
* @param {Protractor} ptor
* @return {function(webdriver.Locator): ElementFinder}
*/
function buildElementHelper(ptor: Protractor): ElementHelper {
function buildElementHelper(browser: Browser): ElementHelper {
let element: ElementHelper = function(locator: webdriver.Locator) {
return new ElementArrayFinder(ptor).all(locator).toElementFinder_();
return new ElementArrayFinder(browser).all(locator).toElementFinder_();
};

element.all =
function(locator: webdriver.Locator) {
return new ElementArrayFinder(ptor).all(locator);
return new ElementArrayFinder(browser).all(locator);
}

return element;
Expand All @@ -100,7 +99,9 @@ function buildElementHelper(ptor: Protractor): ElementHelper {
* @param {boolean=} opt_untrackOutstandingTimeouts Whether Protractor should
* stop tracking outstanding $timeouts.
*/
export class Protractor {
export class Browser {
ExpectedConditions = new EC.ExpectedConditions();

/**
* The wrapped webdriver instance. Use this to interact with pages that do
* not contain Angular (such as a log-in screen).
Expand All @@ -121,14 +122,14 @@ export class Protractor {
*
* @type {function(string): ElementFinder}
*/
$: Function;
$: (query: string) => ElementFinder;

/**
* Shorthand function for finding arrays of elements by css.
*
* @type {function(string): ElementArrayFinder}
*/
$$: Function;
$$: (query: string) => ElementArrayFinder;

/**
* All get methods will be resolved against this base URL. Relative URLs are =
Expand Down Expand Up @@ -184,7 +185,7 @@ export class Protractor {
*
* @type {Plugins} Object containing plugin funtions from config.
*/
private plugins_: Plugins;
plugins_: Plugins;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these no longer private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were marked as private; however, lib/browser.ts makes a call to a private variable. This is the same issue for all the private variables in browser. They probably should be using a Get method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe double check with Julie, but if they're not actually private then we should just drop the underscore at the end and remove the @Private annotations in the jsdoc as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yeah, these were fake private. We don't really want them as part of our documented API really, but the runner needs to access them. I'm fine making them public for now.


/**
* The reset URL to use between page loads.
Expand All @@ -198,7 +199,7 @@ export class Protractor {
* error message if Protractor fails to synchronize with Angular in time.
* @private {boolean}
*/
private trackOutstandingTimeouts_: boolean;
trackOutstandingTimeouts_: boolean;

/**
* If set, will be the universal timeout applied to all tests run by
Expand All @@ -213,16 +214,16 @@ export class Protractor {
* @type {Array<{name: string, script: function|string, args:
* Array.<string>}>}
*/
private mockModules_: any[];
mockModules_: any[];

/**
* If specified, start a debugger server at specified port instead of repl
* when running element explorer.
* @private {number}
*/
private debuggerServerPort_: number;
debuggerServerPort_: number;

private debuggerValidated_: boolean;
debuggerValidated_: boolean;

// This index type allows looking up methods by name so we can do mixins.
[key: string]: any;
Expand Down Expand Up @@ -339,7 +340,7 @@ export class Protractor {
}

return this.driver.schedule(
new Command(CommandName.EXECUTE_SCRIPT)
new protractor.Command(protractor.CommandName.EXECUTE_SCRIPT)
.setParameter('script', script)
.setParameter('args', scriptArgs),
description);
Expand All @@ -364,7 +365,7 @@ export class Protractor {
script = 'return (' + script + ').apply(null, arguments);';
}
return this.driver.schedule(
new Command(CommandName.EXECUTE_ASYNC_SCRIPT)
new protractor.Command(protractor.CommandName.EXECUTE_ASYNC_SCRIPT)
.setParameter('script', script)
.setParameter('args', scriptArgs),
description);
Expand Down Expand Up @@ -972,7 +973,7 @@ export class Protractor {
var context: Object = {require: require};
global.list = (locator: webdriver.Locator) => {
/* globals browser */
return browser.findElements(locator).then(
return protractor.browser.findElements(locator).then(
(arr: webdriver.WebElement[]) => {
var found: string[] = [];
for (var i = 0; i < arr.length; ++i) {
Expand Down Expand Up @@ -1200,7 +1201,7 @@ export class Protractor {
*/
export let wrapDriver =
(webdriver: webdriver.WebDriver, baseUrl?: string, rootElement?: string,
untrackOutstandingTimeouts?: boolean) => {
return new Protractor(
untrackOutstandingTimeouts?: boolean): Browser => {
return new Browser(
webdriver, baseUrl, rootElement, untrackOutstandingTimeouts);
};
3 changes: 2 additions & 1 deletion lib/configParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export class ConfigParser {

if (patterns) {
for (let fileName of patterns) {
let matches = glob.hasMagic(fileName) ? glob.sync(fileName, {cwd}) : [fileName];
let matches =
glob.hasMagic(fileName) ? glob.sync(fileName, {cwd}) : [fileName];
if (!matches.length && !opt_omitWarnings) {
logger.warn('pattern ' + fileName + ' did not match any files.');
}
Expand Down
16 changes: 16 additions & 0 deletions lib/driverProviders/driverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ export class DriverProvider {
return deferred.promise;
}

/**
* Default update job method.
* @return a promise
*/
updateJob(update: any): q.Promise<any> {
return q.fcall(function() {});
};

/**
* Default setup environment method.
* @return a promise
*/
setupEnv(): q.Promise<any> {
return q.fcall(function() {});
};

/**
* Teardown and destroy the environment and do any associated cleanup.
* Shuts down the drivers.
Expand Down
24 changes: 12 additions & 12 deletions lib/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let webdriver = require('selenium-webdriver');
let clientSideScripts = require('./clientsidescripts');

import {Logger} from './logger2';
import {Protractor} from './protractor';
import {Browser} from './browser';

let logger = new Logger('element');

Expand Down Expand Up @@ -56,7 +56,7 @@ let WEB_ELEMENT_FUNCTIONS = [
* });
*
* @constructor
* @param {Protractor} ptor A protractor instance.
* @param {Browser} browser A protractor instance.
* @param {function(): Array.<webdriver.WebElement>} getWebElements A function
* that returns a list of the underlying Web Elements.
* @param {webdriver.Locator} locator The most relevant locator. It is only
Expand All @@ -70,7 +70,7 @@ export class ElementArrayFinder {
getWebElements: Function;

constructor(
private ptor_: Protractor, getWebElements?: Function,
private browser_: Browser, getWebElements?: Function,
private locator_?: any, public actionResults_: webdriver.Promise = null) {
this.getWebElements = getWebElements || null;

Expand All @@ -96,7 +96,7 @@ export class ElementArrayFinder {
// modified. (Locator can be modified by the user, but that should
// rarely/never happen and it doesn't affect functionalities).
return new ElementArrayFinder(
this.ptor_, this.getWebElements, this.locator_, this.actionResults_);
this.browser_, this.getWebElements, this.locator_, this.actionResults_);
}

/**
Expand Down Expand Up @@ -132,7 +132,7 @@ export class ElementArrayFinder {
* @return {ElementArrayFinder}
*/
all(locator: any): ElementArrayFinder {
let ptor = this.ptor_;
let ptor = this.browser_;
let getWebElements = () => {
if (this.getWebElements === null) {
// This is the first time we are looking for an element
Expand Down Expand Up @@ -172,7 +172,7 @@ export class ElementArrayFinder {
});
}
};
return new ElementArrayFinder(this.ptor_, getWebElements, locator);
return new ElementArrayFinder(this.browser_, getWebElements, locator);
}

/**
Expand Down Expand Up @@ -210,7 +210,7 @@ export class ElementArrayFinder {
let list =
parentWebElements.map((parentWebElement: any, index: number) => {
let elementFinder = ElementFinder.fromWebElement_(
this.ptor_, parentWebElement, this.locator_);
this.browser_, parentWebElement, this.locator_);

return filterFn(elementFinder, index);
});
Expand All @@ -222,7 +222,7 @@ export class ElementArrayFinder {
});
});
};
return new ElementArrayFinder(this.ptor_, getWebElements, this.locator_);
return new ElementArrayFinder(this.browser_, getWebElements, this.locator_);
}

/**
Expand Down Expand Up @@ -268,7 +268,7 @@ export class ElementArrayFinder {
return [parentWebElements[i]];
});
};
return new ElementArrayFinder(this.ptor_, getWebElements, this.locator_)
return new ElementArrayFinder(this.browser_, getWebElements, this.locator_)
.toElementFinder_();
}

Expand Down Expand Up @@ -329,7 +329,7 @@ export class ElementArrayFinder {
* @private
*/
toElementFinder_(): ElementFinder {
return new ElementFinder(this.ptor_, this);
return new ElementFinder(this.browser_, this);
}

/**
Expand Down Expand Up @@ -399,7 +399,7 @@ export class ElementArrayFinder {
throw e;
});
return new ElementArrayFinder(
this.ptor_, this.getWebElements, this.locator_, actionResults);
this.browser_, this.getWebElements, this.locator_, actionResults);
}

/**
Expand All @@ -412,7 +412,7 @@ export class ElementArrayFinder {
return this.getWebElements().then((arr: webdriver.WebElement[]) => {
return arr.map((webElem: webdriver.WebElement) => {
return ElementFinder.fromWebElement_(
this.ptor_, webElem, this.locator_);
this.browser_, webElem, this.locator_);
});
});
}
Expand Down
14 changes: 8 additions & 6 deletions lib/expectedConditions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var webdriver = require('selenium-webdriver');
import {protractor} from './ptor';
let webdriver = require('selenium-webdriver');

/* globals browser */

Expand Down Expand Up @@ -140,7 +141,7 @@ export class ExpectedConditions {
*/
alertIsPresent(): Function {
return () => {
return browser.switchTo().alert().then(
return protractor.browser.driver.switchTo().alert().then(
(): boolean => { return true; },
(err: any) => {
if (err.code == webdriver.error.ErrorCode.NO_SUCH_ALERT) {
Expand Down Expand Up @@ -237,9 +238,10 @@ export class ExpectedConditions {
*/
titleContains(title: string): Function {
return () => {
return browser.getTitle().then((actualTitle: string): boolean => {
return actualTitle.indexOf(title) > -1;
});
return protractor.browser.driver.getTitle().then(
(actualTitle: string): boolean => {
return actualTitle.indexOf(title) > -1;
});
};
}

Expand All @@ -258,7 +260,7 @@ export class ExpectedConditions {
*/
titleIs(title: string): Function {
return () => {
return browser.getTitle().then(
return protractor.browser.driver.getTitle().then(
(actualTitle: string): boolean => { return actualTitle === title; });
};
}
Expand Down
36 changes: 21 additions & 15 deletions lib/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
// Typescript transpiling will give a warning about 'global'. This work around
// is to allow protractor to set global variables. Warning message as follows:
//
// lib/globals.d.ts(2,19): error TS2300: Duplicate identifier 'global'.
// typings/main/ambient/node/index.d.ts(33,13): error TS2300: Duplicate
// identifier 'global'.
declare var browser: any;
declare var protractor: any;
declare var $: any;
declare var $$: any;
declare var element: any;
declare var by: any;
declare var By: any;
declare var DartObject: any;

// Used for Protractor mock module loader.
declare namespace angular {
var module: Function;
Expand All @@ -35,7 +20,11 @@ declare namespace NodeJS {
element: any;
by: any;
By: any;
ExpectedConditions: any;
DartObject: any;
ActionSequence: any;
Command: any;
CommandName: any;
// Helper function added by the debugger in protractor.ps
list: (locator: webdriver.Locator) => string[];
[key: string]: any;
Expand All @@ -45,16 +34,21 @@ declare namespace NodeJS {
declare interface String { startsWith: Function; }

declare namespace webdriver {
var error: any;
class WebDriver {
findElements: Function;
getSession: Function;
quit: Function;
executeScript: Function;
getCapabilities: Function;
getCurrentUrl: Function;
getPageSource: Function;
getTitle: Function;
navigate: Function;
get: Function;
wait: Function;
schedule: Function;
switchTo: Function;
controlFlow: Function;
static attachToSession: Function;
// This index type allows looking up methods by name so we can do mixins.
Expand Down Expand Up @@ -87,6 +81,18 @@ declare namespace webdriver {
code: number;
}

class By {
static css: (css: string) => webdriver.By;
static id: (id: string) => webdriver.By;
static linkText: (linkText: string) => webdriver.By;
static js: (js: string) => webdriver.By;
static name: (name: string) => webdriver.By;
static partialLinkText: (partialLinkText: string) => webdriver.By;
static tagName: (tagName: string) => webdriver.By;
static xpath: (xpath: string) => webdriver.By;
toString(): string;
}

interface Locator {
toString(): string;
isPresent?: Function;
Expand Down
Loading