Handle Callbacks, Return Values

This commit is contained in:
Jed Hunsaker
2013-02-16 10:57:30 -08:00
parent ad54ebff92
commit 33e627ba31
2 changed files with 166 additions and 29 deletions
+76 -20
View File
@@ -30,7 +30,7 @@ interface Casper {
debugPage();
die(message: string, status?: number);
download(url: string, target?: string, method?: string, data?: any);
each(array: Array, fn: Function);
each(array: Array, fn: (self, link) => void);
echo(message: string, style?: string);
evaluate(fn: Function, ...args: any[]);
evaluateOrDie(fn: Function, message?: string);
@@ -40,32 +40,32 @@ interface Casper {
forward();
log(message: string, level?: string, space?: string);
fill(selector: string, values: any, submit?: bool);
getCurrentUrl();
getElementAttribute(selector: string, attribute: string);
getElementBounds(selector: string);
getElementsBounds(selector: string);
getElementInfo(selector: string);
getFormValues(selector: string);
getGlobal(name: string);
getHTML(selector?: string, outer?: bool);
getPageContent();
getTitle();
getCurrentUrl(): string;
getElementAttribute(selector: string, attribute: string): string;
getElementBounds(selector: string): ElementBounds;
getElementsBounds(selector: string): ElementBounds[];
getElementInfo(selector: string): ElementInfo;
getFormValues(selector: string): any;
getGlobal(name: string): any;
getHTML(selector?: string, outer?: bool): string;
getPageContent(): string;
getTitle(): string;
mouseEvent(type: string, selector: string);
open(location: string, settings: any);
reload(then?: Function);
open(location: string, settings: OpenSettings): Casper;
reload(then?: (response: HttpResponse) => void);
repeat(times: number, then: Function);
resourceExists(test: Function);
resourceExists(test: string);
run(onComplete: Function, time?: number);
sendKeys(selector: string, keys: string, options?: any);
setHttpAuth(username: string, password: string);
start(url: string, then?: Function);
status(asString: bool);
then(fn: Function);
start(url: string, then?: (response: HttpResponse) => void): Casper;
status(asString: bool): any;
then(fn: (self?: Casper) => void);
thenClick(selector: string);
thenEvaluate(fn: Function, ...args: any[]);
thenOpen(location: string, then?: Function);
thenOpen(location: string, options?: any, then?: Function);
thenOpen(location: string, then?: (response: HttpResponse) => void);
thenOpen(location: string, options?: OpenSettings, then?: (response: HttpResponse) => void);
thenOpenAndEvaluate(location: string, then?: Function, ...args: any[]);
toString();
userAgent(agent: string);
@@ -90,6 +90,44 @@ interface Casper {
zoom(factor: number);
}
interface HttpResponse {
contentType: string;
headers: any[];
id: number;
redirectURL: string;
stage: string;
status: number;
statusText: string;
time: string;
url: string;
}
interface OpenSettings {
method: string;
data: any;
headers: any;
}
interface ElementBounds {
top: number;
left: number;
width: number;
height: number;
}
interface ElementInfo {
nodeName: string;
attributes: any;
tag: string;
html: string;
text: string;
x: number;
y: number;
width: number;
height: number;
visible: bool;
}
interface CasperOptions {
clientScripts: Array;
exitOnError: bool;
@@ -176,13 +214,31 @@ interface Tester {
error(message: string);
fail(message: string);
formatMessage(message: string, style: string);
getFailures();
getPasses();
getFailures(): Cases;
getPasses(): Cases;
info(message: string);
pass(message: string);
renderResults(exit: bool, status: number, save: string);
}
interface Cases {
length: number;
cases: Case[];
}
interface Case {
success: bool;
type: string;
standard: string;
file: string;
values: CaseValues;
}
interface CaseValues {
subject: bool;
expected: bool;
}
interface Utils {
betterTypeOf(input: any);
dump(value: any);
+90 -9
View File
@@ -15,7 +15,7 @@ interface Phantom {
scriptName: string; // DEPRECATED
version: any;
// Methods
// Functions
addCookie(cookie: Cookie): bool;
clearCookies();
deleteCookie(cookieName: string): bool;
@@ -65,7 +65,7 @@ interface WebPage {
ownsPages: bool;
pages;
pagesWindowName: string;
paperSize: any;
paperSize: PaperSize;
plainText: string;
scrollPosition: TopLeft;
settings: WebPageSettings;
@@ -75,7 +75,7 @@ interface WebPage {
windowName: string;
zoomFactor: number;
// Methods
// Functions
addCookie(cookie: Cookie): bool;
childFramesCount(): number; // DEPRECATED
childFramesName(): string; // DEPRECATED
@@ -92,7 +92,7 @@ interface WebPage {
goForward();
includeJs(url: string, callback: Function);
injectJs(filename: string): bool;
open(url: string, callback: Function);
open(url: string, callback: (status: string) => void);
openUrl(url: string, httpConf: any, settings: any);
release(); // DEPRECATED
reload();
@@ -143,6 +143,14 @@ interface WebPage {
urlChanged(url: string);
}
interface PaperSize {
width: string;
height: string;
border: string;
format: string;
orientation: string;
}
interface WebPageSettings {
javascriptEnabled: bool;
loadImages: bool;
@@ -153,6 +161,83 @@ interface WebPageSettings {
webSecurityEnabled: bool;
}
interface FileSystem {
// Properties
separator: string;
workingDirectory: string;
// Functions
// Query Functions
list(path: string): string[];
absolute(path: string): string;
exists(path: string): bool;
isDirectory(path: string): bool;
isFile(path: string): bool;
isAbsolute(path: string): bool;
isExecutable(path: string): bool;
isReadable(path: string): bool;
isWritable(path: string): bool;
isLink(path: string): bool;
readLink(path: string): string;
// Directory Functions
changeWorkingDirectory(path: string);
makeDirectory(path: string);
makeTree(path: string);
removeDirectory(path: string);
removeTree(path: string);
copyTree(source: string, destination: string);
// File Functions
open(path: string, mode: string): Stream;
read(path: string): string;
write(path: string, content: string, mode: string);
size(path: string): number;
remove(path: string);
copy(source: string, destination: string);
move(source: string, destination: string);
touch(path: string);
}
interface Stream {
read(): string;
readLine(): string;
write(data: string);
writeLine(data: string);
flush();
close();
}
interface WebServer {
port: number;
listen(port: number, cb?:(request, response) => void): bool;
listen(ipAddressPort: string, cb?:(request, response) => void): bool;
close();
}
interface Request {
method: string;
url: string;
httpVersion: number;
headers: any;
post: string;
postRaw: string;
}
interface Response {
headers: any;
setHeader(name: string, value: string);
header(name: string): string;
statusCode: number;
setEncoding(encoding: string);
write(data: string);
writeHead(statusCode: number, headers?: any);
close();
closeGracefully();
}
interface TopLeft {
top: number;
left: number;
@@ -168,11 +253,7 @@ interface ClipRect extends TopLeft, Size {
height: number;
}
interface NameValuePair {
interface Cookie {
name: string;
value: any;
}
interface Cookie extends NameValuePair {
value: string;
}