Added more tests.

This commit is contained in:
Bill Armstrong
2014-12-14 15:21:32 -05:00
parent a8d7b34eda
commit 6edec4889a
7 changed files with 270 additions and 83 deletions

View File

@@ -51,15 +51,15 @@ function TestWebDriverExports() {
var webElementPromise: protractor.WebElementPromise = new protractor.WebElementPromise(driver, { ELEMENT: 'abc' });
var baseWebElementPromise: webdriver.WebElementPromise = webElementPromise;
}
// error module
function TestWebDriverErrorModule() {
var errorCode: number = protractor.error.ErrorCode.ELEMENT_NOT_VISIBLE;
var error: protractor.error.Error = new protractor.error.Error(protractor.error.ErrorCode.ELEMENT_NOT_VISIBLE);
var baseError: webdriver.error.Error = error;
}
// logging module
function TestWebDriverLoggingModule() {
var levelName: string = protractor.logging.Level.ALL.name;
var loggingType: string = protractor.logging.Type.CLIENT;
@@ -71,9 +71,9 @@ function TestWebDriverExports() {
level = protractor.logging.getLevel('DEBUG');
var prefs: protractor.logging.Preferences = new protractor.logging.Preferences();
}
// promise module
function TestWebDriverPromiseModule() {
var cancelError: protractor.promise.CancellationError = new protractor.promise.CancellationError();
cancelError = new protractor.promise.CancellationError('message');
var baseCancelError: webdriver.promise.CancellationError = cancelError;
@@ -92,10 +92,10 @@ function TestWebDriverExports() {
var arrayPromise: protractor.promise.Promise<any[]> = protractor.promise.all([new protractor.promise.Promise<number>(), new protractor.promise.Promise<string>()]);
protractor.promise.asap(promise, function(value: any){ return true; });
protractor.promise.asap(promise, function(value: any){}, function(err: any) { return 'ABC'; });
protractor.promise.asap(promise, function (value: any) { return true; });
protractor.promise.asap(promise, function (value: any) { }, function (err: any) { return 'ABC'; });
promise = protractor.promise.checkedNodeCall(function(err: any, value: any) { return 123; });
promise = protractor.promise.checkedNodeCall(function (err: any, value: any) { return 123; });
promise = protractor.promise.consume(function () {
return 5;
@@ -109,7 +109,7 @@ function TestWebDriverExports() {
flow = protractor.promise.controlFlow();
promise = protractor.promise.createFlow(function(newFlow: webdriver.promise.ControlFlow) { });
promise = protractor.promise.createFlow(function (newFlow: webdriver.promise.ControlFlow) { });
deferred = protractor.promise.defer();
@@ -142,21 +142,22 @@ function TestWebDriverExports() {
}, this);
promise = protractor.promise.fulfilled();
promise = protractor.promise.fulfilled({a: 123});
promise = protractor.promise.fulfilled({ a: 123 });
promise = protractor.promise.fullyResolved({a: 123});
promise = protractor.promise.fullyResolved({ a: 123 });
var bool: boolean = protractor.promise.isGenerator(function () { });
var bool: boolean = protractor.promise.isPromise('ABC');
promise = protractor.promise.rejected({a: 123});
promise = protractor.promise.rejected({ a: 123 });
protractor.promise.setDefaultFlow(new webdriver.promise.ControlFlow());
promise = protractor.promise.when(promise, function (value: any) { return 123; }, function (err: Error) { return 123; });
}
// stacktrace module
bool = protractor.stacktrace.BROWSER_SUPPORTED;
function TestWebDriverStacktraceModule() {
var bool: boolean = protractor.stacktrace.BROWSER_SUPPORTED;
var frame: protractor.stacktrace.Frame = new protractor.stacktrace.Frame();
var baseFrame: webdriver.stacktrace.Frame = frame;
@@ -166,8 +167,9 @@ function TestWebDriverExports() {
var err: Error = protractor.stacktrace.format(new Error("Error"));
var frames: protractor.stacktrace.Frame[] = protractor.stacktrace.get();
}
// until module
function TestWebDriverUntilModule() {
var conditionB: protractor.until.Condition<boolean> = new protractor.until.Condition<boolean>('message', function (driver: webdriver.WebDriver) { return true; });
var conditionBBase: webdriver.until.Condition<boolean> = conditionB;
var conditionWebElement: protractor.until.Condition<webdriver.IWebElement>;

View File

@@ -0,0 +1,47 @@
/// <reference path="selenium-webdriver.d.ts" />
function TestChromeDriver() {
var driver: chrome.Driver = new chrome.Driver();
driver = new chrome.Driver(webdriver.Capabilities.chrome());
driver = new chrome.Driver(webdriver.Capabilities.chrome(), new webdriver.promise.ControlFlow());
var baseDriver: webdriver.WebDriver = driver;
}
function TestChromeOptions() {
var options: chrome.Options = new chrome.Options();
options = chrome.Options.fromCapabilities(webdriver.Capabilities.chrome());
options = options.addArguments("a", "b", "c");
options = options.addExtensions("a", "b", "c");
options = options.detachDriver(true);
options = options.setChromeBinaryPath("path");
options = options.setChromeLogFile("logfile");
options = options.setLocalState("state");
options = options.setLoggingPrefs(new webdriver.logging.Preferences());
options = options.setProxy({ proxyType: "proxyType" });
options = options.setUserPreferences("preferences");
var capabilities: webdriver.Capabilities = options.toCapabilities();
capabilities = options.toCapabilities(webdriver.Capabilities.chrome());
var values: chrome.IOptionsValues = options.toJSON();
}
function TestServiceBuilder() {
var builder: chrome.ServiceBuilder = new chrome.ServiceBuilder();
builder = new chrome.ServiceBuilder("exe");
var anything: any = builder.build();
builder = builder.enableVerboseLogging();
builder = builder.loggingTo("path");
builder = builder.setNumHttpThreads(5);
builder = builder.setStdio("config");
builder = builder.setStdio(["A", "B"]);
builder = builder.setUrlBasePath("path");
builder = builder.usingPort(8080);
builder = builder.withEnvironment({ "A": "a", "B": "b" });
}
function TestChromeModule() {
var service: any = chrome.getDefaultService();
chrome.setDefaultService({});
}

View File

@@ -0,0 +1,8 @@
/// <reference path="selenium-webdriver.d.ts" />
/// <reference path="executors.d.ts" />
function TestExecutors() {
var exec: webdriver.CommandExecutor = executors.createExecutor("url");
exec = executors.createExecutor(new webdriver.promise.Promise<string>());
}

View File

@@ -0,0 +1,53 @@
/// <reference path="selenium-webdriver.d.ts" />
function TestBinary() {
var binary: firefox.Binary = new firefox.Binary();
binary = new firefox.Binary("exe");
binary.addArguments("A", "B", "C");
var promise: webdriver.promise.Promise<void> = binary.kill();
binary.launch("profile").then(function (result: any) { });
}
function TestFirefoxDriver() {
var driver: firefox.Driver = new firefox.Driver();
driver = new chrome.Driver(webdriver.Capabilities.firefox());
driver = new chrome.Driver(webdriver.Capabilities.firefox(), new webdriver.promise.ControlFlow());
var baseDriver: webdriver.WebDriver = driver;
}
function TestFirefoxOptions() {
var options: firefox.Options = new firefox.Options();
options = options.setBinary("binary");
options = options.setBinary(new firefox.Binary());
options = options.setLoggingPreferences(new webdriver.logging.Preferences());
options = options.setProfile("profile");
options = options.setProfile(new firefox.Profile());
options = options.setProxy({ proxyType: "proxy" });
var capabilities: webdriver.Capabilities = options.toCapabilities();
var capabilities: webdriver.Capabilities = options.toCapabilities({});
}
function TestFirefoxProfile() {
var profile: firefox.Profile = new firefox.Profile();
profile = new firefox.Profile("dir");
var bool: boolean = profile.acceptUntrustedCerts();
profile.addExtension("ext");
bool = profile.assumeUntrustedCertIssuer();
profile.encode().then(function (prof: string) { });
var num: number = profile.getPort();
var anything: any = profile.getPreference("key");
bool = profile.nativeEventsEnabled();
profile.setAcceptUntrustedCerts(true);
profile.setAssumeUntrustedCertIssuer(true);
profile.setNativeEventsEnabled(true);
profile.setPort(8080);
profile.setPreference("key", "value");
profile.setPreference("key", 5);
profile.setPreference("key", true);
var stringPromise: webdriver.promise.Promise<string> = profile.writeToDisk();
stringPromise = profile.writeToDisk(true);
}

View File

@@ -548,8 +548,9 @@ function TestWebDriver() {
var stringPromise: webdriver.promise.Promise<string>;
var booleanPromise: webdriver.promise.Promise<boolean>;
// Call
var actions: webdriver.ActionSequence = driver.actions();
// call
stringPromise = driver.call<string>(function(){});
stringPromise = driver.call<string>(function(){ var d: any = this;}, driver);
stringPromise = driver.call<string>(function(a: number){}, driver, 1);
@@ -557,24 +558,26 @@ function TestWebDriver() {
voidPromise = driver.close();
flow = driver.controlFlow();
// ExecuteAsyncScript
// executeAsyncScript
stringPromise = driver.executeAsyncScript<string>('function(){}');
stringPromise = driver.executeAsyncScript<string>('function(){}', 1, 2, 3);
stringPromise = driver.executeAsyncScript<string>(function(){});
stringPromise = driver.executeAsyncScript<string>(function(a: number){}, 1);
// ExecuteScript
// executeScript
stringPromise = driver.executeScript<string>('function(){}');
stringPromise = driver.executeScript<string>('function(){}', 1, 2, 3);
stringPromise = driver.executeScript<string>(function(){});
stringPromise = driver.executeScript<string>(function(a: number){}, 1);
// findElement
var element: webdriver.WebElement;
element = driver.findElement(webdriver.By.id('ABC'));
element = driver.findElement({id: 'ABC'});
element = driver.findElement(webdriver.By.js('function(){}'), 1, 2, 3);
element = driver.findElement({js: 'function(){}'}, 1, 2, 3);
// findElements
driver.findElements(webdriver.By.className('ABC')).then(function (elements: webdriver.WebElement[]) { });
driver.findElements({ className: 'ABC' }).then(function (elements: webdriver.WebElement[]) { });
driver.findElements(webdriver.By.js('function(){}'), 1, 2, 3).then(function (elements: webdriver.WebElement[]) { });
@@ -657,6 +660,28 @@ function TestWebElement() {
var key: string = webdriver.WebElement.ELEMENT_KEY;
}
function TestWebElementPromise() {
var driver: webdriver.WebDriver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
var elementPromise: webdriver.WebElementPromise = driver.findElement(webdriver.By.id('id'));
elementPromise.cancel();
elementPromise.cancel('reason');
var bool: boolean = elementPromise.isPending();
elementPromise.then();
elementPromise.then(function (element: webdriver.WebElement) { });
elementPromise.then(function (element: webdriver.WebElement) { }, function (error: any) { });
elementPromise.then<string>(function (element: webdriver.WebElement) { }, function (error: any) { }).then(function (result: string) { });
elementPromise.thenCatch(function (error: any) { }).then(function (value: any) { });
elementPromise.thenFinally(function () { });
}
function TestLogging() {
var preferences: webdriver.logging.Preferences = new webdriver.logging.Preferences();
preferences.setLevel(webdriver.logging.Type.BROWSER, webdriver.logging.Level.ALL);
@@ -703,17 +728,60 @@ function TestLoggingEntry() {
entry = webdriver.logging.Entry.fromClosureLogRecord({}, webdriver.logging.Type.DRIVER);
}
function TestPromiseNamespace() {
function TestPromiseModule() {
var cancellationError: webdriver.promise.CancellationError = new webdriver.promise.CancellationError();
cancellationError = new webdriver.promise.CancellationError("message");
var str: string = cancellationError.message;
str = cancellationError.name;
var stringPromise: webdriver.promise.Promise<string> = new webdriver.promise.Promise<string>();
var numberPromise: webdriver.promise.Promise<number>;
var booleanPromise: webdriver.promise.Promise<boolean>;
var voidPromise: webdriver.promise.Promise<void>;
webdriver.promise.all([new webdriver.promise.Promise<string>()]).then(function (values: string[]) { });
webdriver.promise.asap('abc', function(value: any){ return true; });
webdriver.promise.asap('abc', function(value: any){}, function(err: any) { return 'ABC'; });
stringPromise = webdriver.promise.checkedNodeCall<string>(function(err: any, value: any) { return 'abc'; });
webdriver.promise.consume(function () {
return 5;
}).then(function (value: number) { });
webdriver.promise.consume(function () {
return 5;
}, this).then(function (value: number) { });
webdriver.promise.consume(function (a: number, b: number, c: number) {
return 5;
}, this, 1, 2, 3).then(function (value: number) { });
var numbersPromise: webdriver.promise.Promise<number[]> = webdriver.promise.filter([1, 2, 3], function (el: number, index: number, arr: number[]) {
return true;
});
numbersPromise = webdriver.promise.filter([1, 2, 3], function (el: number, index: number, arr: number[]) {
return true;
}, this);
numbersPromise = webdriver.promise.filter(numbersPromise, function (el: number, index: number, arr: number[]) {
return true;
});
numbersPromise = webdriver.promise.filter(numbersPromise, function (el: number, index: number, arr: number[]) {
return true;
}, this);
numbersPromise = webdriver.promise.map([1, 2, 3], function (el: number, index: number, arr: number[]) {
return true;
});
numbersPromise = webdriver.promise.map([1, 2, 3], function (el: number, index: number, arr: number[]) {
return true;
}, this);
numbersPromise = webdriver.promise.map(numbersPromise, function (el: number, index: number, arr: number[]) {
return true;
});
numbersPromise = webdriver.promise.map(numbersPromise, function (el: number, index: number, arr: number[]) {
return true;
}, this);
var flow: webdriver.promise.ControlFlow = webdriver.promise.controlFlow();
stringPromise = webdriver.promise.createFlow<string>(function(newFlow: webdriver.promise.ControlFlow) { return 'ABC' });
@@ -734,6 +802,7 @@ function TestPromiseNamespace() {
stringPromise = webdriver.promise.fullyResolved('abc');
var bool: boolean = webdriver.promise.isGenerator(function () { });
var isPromise: boolean = webdriver.promise.isPromise('ABC');
voidPromise = webdriver.promise.rejected({a: 123});
@@ -743,6 +812,50 @@ function TestPromiseNamespace() {
numberPromise = webdriver.promise.when('abc', function(value: any) { return 123; }, function(err: Error) { return 123; });
}
function TestStacktraceModule() {
var bool: boolean = webdriver.stacktrace.BROWSER_SUPPORTED;
var frame: webdriver.stacktrace.Frame = new webdriver.stacktrace.Frame();
var baseFrame: webdriver.stacktrace.Frame = frame;
var snapshot: webdriver.stacktrace.Snapshot = new webdriver.stacktrace.Snapshot();
var baseSnapshot: webdriver.stacktrace.Snapshot = snapshot;
var err: Error = webdriver.stacktrace.format(new Error("Error"));
var frames: webdriver.stacktrace.Frame[] = webdriver.stacktrace.get();
}
function TestUntilModule() {
var driver: webdriver.WebDriver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
var conditionB: webdriver.until.Condition<boolean> = new webdriver.until.Condition<boolean>('message', function (driver: webdriver.WebDriver) { return true; });
var conditionBBase: webdriver.until.Condition<boolean> = conditionB;
var conditionWebElement: webdriver.until.Condition<webdriver.IWebElement>;
var conditionWebElements: webdriver.until.Condition<webdriver.IWebElement[]>;
conditionB = webdriver.until.ableToSwitchToFrame(5);
var conditionAlert: webdriver.until.Condition<webdriver.Alert> = webdriver.until.alertIsPresent();
var el: webdriver.WebElement = driver.findElement(webdriver.By.id('id'));
conditionB = webdriver.until.elementIsDisabled(el);
conditionB = webdriver.until.elementIsEnabled(el);
conditionB = webdriver.until.elementIsNotSelected(el);
conditionB = webdriver.until.elementIsNotVisible(el);
conditionB = webdriver.until.elementIsSelected(el);
conditionB = webdriver.until.elementIsVisible(el);
conditionB = webdriver.until.elementTextContains(el, 'text');
conditionB = webdriver.until.elementTextIs(el, 'text');
conditionB = webdriver.until.elementTextMatches(el, /text/);
conditionB = webdriver.until.stalenessOf(el);
conditionB = webdriver.until.titleContains('text');
conditionB = webdriver.until.titleIs('text');
conditionB = webdriver.until.titleMatches(/text/);
conditionWebElement = webdriver.until.elementLocated(webdriver.By.id('id'));
conditionWebElements = webdriver.until.elementsLocated(webdriver.By.className('class'));
}
function TestControlFlow() {
var flow: webdriver.promise.ControlFlow;
flow = new webdriver.promise.ControlFlow();
@@ -756,6 +869,7 @@ function TestControlFlow() {
var eventType: string;
eventType = webdriver.promise.ControlFlow.EventType.IDLE;
eventType = webdriver.promise.ControlFlow.EventType.RESET;
eventType = webdriver.promise.ControlFlow.EventType.SCHEDULE_TASK;
eventType = webdriver.promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION;
@@ -816,7 +930,29 @@ function TestPromiseClass() {
promise = promise.then(function( a: string ) { });
promise = promise.then(function( a: string ) { return 'cde'; });
promise = promise.then(function( a: string ) {}, function( e: any) {});
promise = promise.then(function( a: string ) {}, function( e: any) { return 123; });
promise = promise.then(function (a: string) { }, function (e: any) { return 123; });
promise = promise.thenCatch(function (error: any) { });
promise.thenFinally(function () { });
}
function TestThenableClass() {
var thenable: webdriver.promise.Thenable<string> = new webdriver.promise.Thenable<string>();
thenable.cancel('Abort');
var isPending: boolean = thenable.isPending();
thenable = thenable.then();
thenable = thenable.then(function (a: string) { });
thenable = thenable.then(function (a: string) { return 'cde'; });
thenable = thenable.then(function (a: string) { }, function (e: any) { });
thenable = thenable.then(function (a: string) { }, function (e: any) { return 123; });
thenable = thenable.thenCatch(function (error: any) { });
thenable.thenFinally(function () { });
}
function TestErrorCode() {

View File

@@ -1030,6 +1030,9 @@ declare module webdriver {
/** Emitted when all tasks have been successfully executed. */
IDLE: string;
/** Emitted when a ControlFlow has been reset. */
RESET: string;
/** Emitted whenever a new task has been scheduled. */
SCHEDULE_TASK: string;

View File

@@ -1,62 +0,0 @@
declare module 'selenium-webdriver/testing' {
/**
* Registers a new test suite.
* @param name The suite name.
* @param fn The suite function, or {@code undefined} to define a pending test suite.
*/
function describe(name: string, fn: Function): void;
/**
* Defines a suppressed test suite.
* @param name The suite name.
* @param fn The suite function, or {@code undefined} to define a pending test suite.
*/
function xdescribe(name: string, fn: Function): void;
/**
* Register a function to call after the current suite finishes.
* @param fn
*/
function after(fn: Function): void;
/**
* Register a function to call after each test in a suite.
* @param fn
*/
function afterEach(fn: Function): void;
/**
* Register a function to call before the current suite starts.
* @param fn
*/
function before(fn: Function): void;
/**
* Register a function to call before each test in a suite.
* @param fn
*/
function beforeEach(fn: Function): void;
/**
* Add a test to the current suite.
* @param name The test name.
* @param fn The test function, or {@code undefined} to define a pending test case.
*/
function it(name: string, fn: Function): void;
/**
* An alias for {@link #it()} that flags the test as the only one that should
* be run within the current suite.
* @param name The test name.
* @param fn The test function, or {@code undefined} to define a pending test case.
*/
function iit(name: string, fn: Function): void;
/**
* Adds a test to the current suite while suppressing it so it is not run.
* @param name The test name.
* @param fn The test function, or {@code undefined} to define a pending test case.
*/
function xit(name: string, fn: Function): void;
}