-
Notifications
You must be signed in to change notification settings - Fork 16
/
wd.js.node.txt
195 lines (171 loc) · 12.7 KB
/
wd.js.node.txt
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
WD.JS
MAIN OBJECTS ==> # - WD: require("wd")
# - BROWSER: a connection to the server.
# Can only run a single browser session at once.
# All following methods are BROWSER.*, unless specified otherwise
# - WINDOWH: an id to a WINDOW for a given BROWSER
# - ELEMENT: similar to ELEM|JQ, but different implementation
# To get the underlying ELEM, use getAttribute(...) (notably "outerHTML" and "textContent")
# When BROWER.FUNC([ELEMENT], ...):
# - can also be called either as ELEMENT.FUNC(...) or as BROWSER.FUNC(ELEMENT)
# (not as BROWSER.FUNC())
# - if doesn't say otherwise, returns ELEMENT
#Version 0.3.3
METHODS RETURN ==> #All methods "return VAL..." meaning depends on WD.remote() STR:
# - "async" (déf): returns undefined and use last argument CALLBACK(ERROR, VAL...)
# - "promise":
# - returns Q PROMISE with state value VAL (ARR if several VAL...), and state rejected if
# ERROR
# - Can also find link to Q (version 1.0.1) at WD.Q
# - To just get a PROMISE without doing anything, do BROWSER|ELEMENT.noop()
# - "promiseChain" (best): same but:
# - PROMISE.FUNC(VAL) shortcut for PROMISE.then(BROWSER.FUNC(VAL))
# - if VAL is ELEMENT, also shortcut for PROMISE.then(ELEMENT.FUNC(...))
# Can force BROWSER.FUNC() with first argument "<" or ELEMENT.FUNC() with ">"
# - should use CHAIASPROMISED.transferPromiseness = WD.transferPromiseness; with Chai,
# so BROWSER.should.eventually... returns BROWSER, not CHAIPROMISED
#Execution chain stops when a navigation step happens (e.g. clicking on link or going back in
#history) but not for AJAX calls (use wait*() then)
WD.remote(OBJ[, STR]) #Returns a BROWSER.
#OBJ members are same as Node.js URL.format(OBJ)
#Default: http://127.0.0.1:4444/wd/hub
#STR: see above
WD.remote(HOSTNAME[, PORT
[, USER[, PASSWORD]]]]) #Other syntax
WD.remote(STR[ ,STR2]) #Uses a URL STR like in Node.js URL
status() #Returns OBJ with members:
# - os { arch, name, version }
# - java.version
# - build { revision, time, version }
init([CAPAB_OBJ]) #Starts session (opens the browser).
#Returns SESSIONID
#CAPAB_OBJ are asked to server, just might refuse/not implement.
quit() #Stops session (closes the browser)
detach() #Detaches from session but does not close it.
attach(SESSIONID) #Attaches to session. Returns CAPAB_OBJ
sessions() #Returns SESSION_OBJ_ARR, where SESSION_OBJ has members id SESSIONID and capabilities CAPAB_OBJ
sessionCapabilities() #Returns CAPAB_OBJ
getSessionId() #Returns SESSIONID
get(URL) #Navigates to URL
[WD.]configureHttp(OBJ) #Some config for all BROWSER or one specific BROWSER:
# - timeout (déf: 60000ms): HTTP requests timeout
# - retries (déf: 3)
# - retryDelay (déf: 10ms): between two retries
# - baseUrl (déf: ""): of get(URL)
# - proxy: as in REQUEST
back|forward() #History
refresh() #
url() #Returns STR
WD.add[Element]Async|Promise #Create BROWSER|ELEMENT.FUNC_STR(ARGS), firing FUNC(ARGS):
[Chain]Method(FUNC_STR, FUNC) # - this is BROWSER|ELEMENT
# - For Promise[Chain]:
# - FUNC return VAL -> new PROMISE state value
# - so can also return PROMISE2, e.g. after:
# WD.addPromiseChainMethod(FUNC_STR, function(url){ return this.get(url).title(); })
# BROWSER.FUNC_STR(url) is same as BROWSER.get(url).title()
# - Chain should be used if using WD.remote("promiseChain")
# - For Async:
# - BROWSER|ELEMENT.FUNC_STR(ARGS) -> FUNC(ARGS)
# FUNC must call callback as last ARG:
# - can use WD.findCallback(arguments)
WD.removeMethod(FUNC_STR,FUNC)#
setImplicitWait|AsyncScript|
PageLoadTimeout(UINT) #Set default timeout in ms for searching for elements, for executeAsync() or for loading a page
[safeE|e]xecute[Async] #Execute JavaScript code in the page context. Prefer safe version.
(CODE[, ARGS_ARR]) #Returns the last line executed, as JSON. When returning ELEM, return it as ELEMENT.
#"Async" doesn't return anything.
#Be careful, webdrivers don't always have all usual the DOM, e.g. no WINDOW.navigator
[safeE|e]val(CODE) #Same thing.
newWindow(URL[, NAME]) #Uses WINDOW.open
#Should read CAPAB_OBJ.handlesAlert (read-only) to see if current driver supports handling
#popups (PhantomJS doesn't)
windowName() #Returns STR of current WINDOW
windowHandle[s]() #Returns WINDOWH[_ARR]
close() #Closes current WINDOW
window|frame(STR) #Changes focus to different WINDOW (WINDOW.name) or <frame>
setWindowSize(WIDTH, HEIGHT,
WINDOWH) #
getWindowSize([WINDOWH]) #Returns { height, width } (WINDOW.outerHeight|Width)
setWindowPosition(X,Y,WINDOWH)#
getWindowPosition([WINDOWH]) #Returns { x, y } (WINDOW.screenX|Y)
maximize(WINDOWH) #
scroll(X,Y) #Does not seem to work with most drivers yet.
allCookies() #Returns OBJ_ARR, where OBJ members are name, value, path, domain, secure, expiry
setCookie(OBJ) #
deleteAllCookies() #
deleteCookie(STR) #
takeScreenshot() #Returns as base64 PNG STR (needs to append "data:image/png;base64,")
#Should read CAPAB_OBJ.takesScreenshot (read-only) to see if current driver supports it.
BROWSER|ELEMENT.elementBy
ClassName|TagName(STR) #Returns ELEMENT2
BROWSER|ELEMENT. #Returns ELEMENT2
elementByCssSelector(STR) #Should read CAPAB_OBJ.cssSelectorsEnabled (read-only) to see if current driver supports it.
BROWSER|ELEMENT.
elementById|Name(STR) #Returns ELEMENT2
BROWSER|ELEMENT.elementBy
[Partial]LinkText(STR) #According to children text nodes (exact or partial nodes). Returns ELEMENT2
BROWSER|ELEMENT.elementByXPath
(STR) #Returns ELEMENT2
BROWSER|ELEMENT.elements*(STR)#Same as BROWSER|ELEMENT.element* but returns ELEMENT2_ARR
BROWSER.element*orNull|
ifExists(STR) #Same as BROWSER.element* but returns null|undefined if not found, instead of throwing exception
BROWER.hasElement*(STR) #Same as BROWSER.element* but returns BOOL
active() #Returns currently focused ELEMENT
source() #Returns root document HTML code as STR
title() #Returns <title>
getTagName([ELEMENT]) #Return HTML tag STR
getAttribute([ELEMENT, ]ATTR) #Returns JavaScript attribute value STR (can e.g. be "outerHTML")
getValue([ELEMENT]) #Same as getAttribute("value")
text([ELEMENT]) #Same as getAttribute("contentText")
alertText() #Same for current popup main element
#Same as above for CAPAB_OBJ.handlesAlert
textPresent(STR[, ELEMENT]) #Returns BOOL
getSize([ELEMENT]) #Returns { width, height } (ELEM.offsetWidth|Height)
getLocation[InView]([ELEMENT])#Returns { x, y }
#Without InView: ELEM.getBoundingClientRect().left|top
#With InView: y is calculated after scrolling to the element.
getComputedCss([ELEMENT, ]
CSS_PROP) #Returns CSS_VAL, like WINDOW.getComputedStyle(ELEM).CSS_PROP
equals([ELEMENT, ]ID) #Returns true if same element (ID is ELEMENT2.value)
EVENTS ==> #PROMISE is resolved once action is done, but page might take time to take effect, so should
#use a wait*() after.
ELEMENT.click() #
clickElement(ELEMENT) #
click|buttondown|up(NUM) #Click on current ELEMENT, NUM is 0 left, 1 middle, 1 right
doubleC|click([ELEMENT]) #
submit([ELEMENT]) #
type|keys([ELEMENT, ]STR) #STR can contain require("lib/special-keys.js") OBJ, e.g. OBJ["Tab"] ("\uE004"), OBJ["Enter"],
#etc.
#With keys() (not type()), ELEMENT has a default value of active()
ELEMENT.sendKeys(STR) #Similar
alertKeys(STR) #Same for current popup
#Should read CAPAB_OBJ.handlesAlert (read-only) to see if current driver supports it.
clear([ELEMENT]) #Resets a TEXTAREA|INPUT value
accept|dismissAlert() #For popups
moveTo([ELEMENT, ]X, Y) #Move mouse to ELEMENT, with offset X and Y
isSelected|Enabled|
[Not]Displayed([ELEMENT]) #Returns BOOL
setLocalStorageKey(VAR, VAL) #
getLocalStorageKey(VAR) #
removeLocalStorageKey(VAR) #
clearLocalStorageKey() #Should check CAPAB_OBJ.webStorageEnabled (PhantomJS doesn't accept by default)
BROWSER|ELEMENT.sleep(NUM) #ms
waitFor(ASSERTER, #ASSERTER is fired every NUM2ms (def: 200) until timeout NUM (def: 1000):
[, NUM[, NUM2]]) # - is new WD.Asserter(FUNC(BROWSER, FUNC2(ERROR, BOOL, VAL))):
# - FUNC() must call FUNC2() with true when no need to wait anymore, false otherwise.
# VAL is the return value when true.
# - can return PROMISE instead of using FUNC2
# - There are some available ASSERTER:
# - WD.asserters.nonEmptyText: state value is textContent
# - WD.asserters.textInclude(STR): state value is STR
# - WD.asserters.is[Not]Displayed
# - WD.asserters.jsCondition(STR[, BOOL]): use [safeE|e]val (safe if BOOL (déf: false))
waitForElement*(ARGS[, ...]) #Same as waitFor(...) but test existence of element*(ARGS) (except orNull|ifExists()) first,
#then executes waitFor(...), but ASSERTER is optional
log(LOGTYPE) #Get logs as STR_ARR. Available LOGTYPE can be obtained with logTypes() returning
#["client", "driver", "server", "browser"]
on("status", FUNC(STR)) #Server-related logs
on("command",FUNC(STR, STR2,
OBJ)) #For each Selenium command: STR is "CALL|RESPONSE", STR2 is commande, OBJ is response