forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.ts
More file actions
121 lines (112 loc) · 3.73 KB
/
base.ts
File metadata and controls
121 lines (112 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
export type Event = 'request'
/**
* This is the base Browser interface all browser
* classes should build on, it is the bare
* methods we aim to support across tests
*/
export abstract class BrowserInterface implements PromiseLike<any> {
private promise?: Promise<any>
then: Promise<any>['then']
catch: Promise<any>['catch']
finally: Promise<any>['finally'];
// necessary for the type of the function below
readonly [Symbol.toStringTag]: string = 'BrowserInterface'
protected chain<T>(
nextCall: (current: any) => T | PromiseLike<T>
): BrowserInterface & Promise<T> {
const promise = Promise.resolve(this.promise).then(nextCall)
function get(target: BrowserInterface, p: string | symbol): any {
switch (p) {
case 'promise':
return promise
case 'then':
return promise.then.bind(promise)
case 'catch':
return promise.catch.bind(promise)
case 'finally':
return promise.finally.bind(promise)
default:
return target[p]
}
}
return new Proxy<any>(this, {
get,
})
}
protected chainWithReturnValue<T>(
callback: (value: any) => T | PromiseLike<T>
): Promise<T> {
return Promise.resolve(this.promise).then(callback)
}
abstract setup(
browserName: string,
locale: string,
javaScriptEnabled: boolean,
ignoreHttpsErrors: boolean,
headless: boolean
): Promise<void>
abstract close(): Promise<void>
abstract elementsByCss(selector: string): BrowserInterface[]
abstract elementByCss(selector: string): BrowserInterface
abstract elementById(selector: string): BrowserInterface
abstract touchStart(): BrowserInterface
abstract click(opts?: { modifierKey?: boolean }): BrowserInterface
abstract keydown(key: string): BrowserInterface
abstract keyup(key: string): BrowserInterface
abstract type(text: string): BrowserInterface
abstract moveTo(): BrowserInterface
// TODO(NEXT-290): type this correctly as awaitable
abstract waitForElementByCss(
selector: string,
timeout?: number
): BrowserInterface
abstract waitForCondition(snippet: string, timeout?: number): BrowserInterface
/**
* Use browsers `go back` functionality.
*/
abstract back(options?: any): BrowserInterface
/**
* Use browsers `go forward` functionality. Inverse of back.
*/
abstract forward(options?: any): BrowserInterface
abstract refresh(): BrowserInterface
abstract setDimensions(opts: {
height: number
width: number
}): BrowserInterface
abstract addCookie(opts: { name: string; value: string }): BrowserInterface
abstract deleteCookies(): BrowserInterface
abstract on(event: Event, cb: (...args: any[]) => void): void
abstract off(event: Event, cb: (...args: any[]) => void): void
abstract loadPage(
url: string,
{
disableCache,
cpuThrottleRate,
beforePageLoad,
pushErrorAsConsoleLog,
}: {
disableCache?: boolean
cpuThrottleRate?: number
beforePageLoad?: Function
pushErrorAsConsoleLog?: boolean
}
): Promise<void>
abstract get(url: string): Promise<void>
abstract getValue<T = any>(): Promise<T>
abstract getAttribute<T = any>(name: string): Promise<T>
abstract eval<T = any>(snippet: string | Function, ...args: any[]): Promise<T>
abstract evalAsync<T = any>(
snippet: string | Function,
...args: any[]
): Promise<T>
abstract text(): Promise<string>
abstract getComputedCss(prop: string): Promise<string>
abstract hasElementByCssSelector(selector: string): Promise<boolean>
abstract log(): Promise<
{ source: 'error' | 'info' | 'log'; message: string }[]
>
abstract websocketFrames(): Promise<any[]>
abstract url(): Promise<string>
abstract waitForIdleNetwork(): Promise<void>
}