ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-WebDriver/README
(Generate patch)

Comparing AnyEvent-WebDriver/README (file contents):
Revision 1.2 by root, Tue Aug 28 22:59:53 2018 UTC vs.
Revision 1.3 by root, Tue Aug 28 23:33:10 2018 UTC

38 38
39 https://w3c.github.io/webdriver/ 39 https://w3c.github.io/webdriver/
40 40
41 CREATING WEBDRIVER OBJECTS 41 CREATING WEBDRIVER OBJECTS
42 new AnyEvent::WebDriver key => value... 42 new AnyEvent::WebDriver key => value...
43 Create a new WebDriver object. Example for a remote webdriver 43 Create a new WebDriver object. Example for a remote WebDriver
44 connection (the only type supported at the moment): 44 connection (the only type supported at the moment):
45 45
46 my $wd = new AnyEvent::WebDriver host => "localhost", port => 4444; 46 my $wd = new AnyEvent::WebDriver host => "localhost", port => 4444;
47 47
48 Supported keys are: 48 Supported keys are:
60 autodelete => $boolean 60 autodelete => $boolean
61 If true (the default), then automatically execute 61 If true (the default), then automatically execute
62 "delete_session" when the WebDriver object is destroyed with an 62 "delete_session" when the WebDriver object is destroyed with an
63 active session. IF set to a false value, then the session will 63 active session. IF set to a false value, then the session will
64 continue to exist. 64 continue to exist.
65
66 timeout => $seconds
67 The HTTP timeout, in (fractional) seconds (default: 300, but
68 this will likely drastically reduce). This timeout is reset on
69 any activity, so it is not an overall request timeout. Also,
70 individual requests might extend this timeout if they are known
71 to take longer.
65 72
66 SIMPLIFIED API 73 SIMPLIFIED API
67 This section documents the simplified API, which is really just a very 74 This section documents the simplified API, which is really just a very
68 thin wrapper around the WebDriver protocol commands. They all block 75 thin wrapper around the WebDriver protocol commands. They all block
69 (using AnyEvent condvars) the caller until the result is available, so 76 (using AnyEvent condvars) the caller until the result is available, so
70 must not be called from an event loop callback - see "EVENT BASED API" 77 must not be called from an event loop callback - see "EVENT BASED API"
71 for an alternative. 78 for an alternative.
72 79
73 The method names are preetty much taken directly from the W3C WebDriver 80 The method names are pretty much taken directly from the W3C WebDriver
74 specification, e.g. the request documented in the "Get All Cookies" 81 specification, e.g. the request documented in the "Get All Cookies"
75 section is implemented via the "get_all_cookies" method. 82 section is implemented via the "get_all_cookies" method.
76 83
77 The order is the same as in the WebDriver draft at the tiome of this 84 The order is the same as in the WebDriver draft at the time of this
78 writing, and only minimal massaging is done to request parameters and 85 writing, and only minimal massaging is done to request parameters and
79 results. 86 results.
80 87
81 SESSIONS 88 SESSIONS
82 $wd->new_session ({ key => value... }) 89 $wd->new_session ({ key => value... })
83 Try to connect to a webdriver and initialize session with a "new 90 Try to connect to the WebDriver and initialize a new session with a
84 session" command, passing the given key-value pairs as value (e.g. 91 "new session" command, passing the given key-value pairs as value
85 "capabilities"). 92 (e.g. "capabilities").
86 93
87 No session-dependent methods must be called before this function 94 No session-dependent methods must be called before this function
88 returns successfully. 95 returns successfully, and only one session can be created per
96 WebDriver object.
89 97
90 On success, "$wd->{sid}" is set to the session id, and 98 On success, "$wd->{sid}" is set to the session ID, and
91 "$wd->{capabilities}" is set to the returned capabilities. 99 "$wd->{capabilities}" is set to the returned capabilities.
92 100
93 my $wd = new AnyEvent::Selenium host => "localhost", port => 4545; 101 my $wd = new AnyEvent::Selenium endpoint => "http://localhost:4545";
94 102
95 $wd->new_session ({ 103 $wd->new_session ({
96 capabilities => { 104 capabilities => {
97 pageLoadStrategy => "normal", 105 pageLoadStrategy => "normal",
98 }. 106 }.
104 112
105 $timeouts = $wd->get_timeouts 113 $timeouts = $wd->get_timeouts
106 Get the current timeouts, e.g.: 114 Get the current timeouts, e.g.:
107 115
108 my $timeouts = $wd->get_timeouts; 116 my $timeouts = $wd->get_timeouts;
109
110 # { implicit => 0, pageLoad => 300000, script => 30000 } 117 => { implicit => 0, pageLoad => 300000, script => 30000 }
111 118
112 $wd->set_timeouts ($timeouts) 119 $wd->set_timeouts ($timeouts)
113 Sets one or more timeouts, e.g.: 120 Sets one or more timeouts, e.g.:
114 121
115 $wd->set_timeouts ({ script => 60000 }); 122 $wd->set_timeouts ({ script => 60000 });
117 NAVIGATION 124 NAVIGATION
118 $wd->navigate_to ($url) 125 $wd->navigate_to ($url)
119 Navigates to the specified URL. 126 Navigates to the specified URL.
120 127
121 $url = $wd->get_current_url 128 $url = $wd->get_current_url
122 Queries the czurrent page URL as set by "navigate_to". 129 Queries the current page URL as set by "navigate_to".
123 130
124 $wd->back 131 $wd->back
125 The equivalent of pressing "back" in the browser. 132 The equivalent of pressing "back" in the browser.
126 133
127 $wd->forward 134 $wd->forward
145 152
146 $handles = $wd->get_window_handles 153 $handles = $wd->get_window_handles
147 Return the current window handles as an array-ref of handle IDs. 154 Return the current window handles as an array-ref of handle IDs.
148 155
149 $handles = $wd->switch_to_frame ($frame) 156 $handles = $wd->switch_to_frame ($frame)
150 Switch to the given frame. 157 Switch to the given frame identified by $frame, which must be either
158 "undef" to go back to the top-level browsing context, an integer to
159 select the nth subframe, or an element object (as e.g. returned by
160 the "element_object" method.
151 161
152 $handles = $wd->switch_to_parent_frame 162 $handles = $wd->switch_to_parent_frame
153 Switch to the parent frame. 163 Switch to the parent frame.
154 164
155 $rect = $wd->get_window_rect 165 $rect = $wd->get_window_rect
156 Return the current window rect, e.g.: 166 Return the current window rect, e.g.:
157 167
158 $rect = $wd->get_window_rect 168 $rect = $wd->get_window_rect
159 # { height => 1040, width => 540, x => 0, y => 0 } 169 => { height => 1040, width => 540, x => 0, y => 0 }
160 170
161 $wd->set_window_rect ($rect) 171 $wd->set_window_rect ($rect)
162 Sets the window rect. 172 Sets the window rect.
163 173
164 $wd->maximize_window 174 $wd->maximize_window
165 $wd->minimize_window 175 $wd->minimize_window
166 $wd->fullscreen_window 176 $wd->fullscreen_window
167 Changes the window size by eithe3r maximising, minimising or making 177 Changes the window size by either maximising, minimising or making
168 it fullscreen. In my experience, this might timeout if no window 178 it fullscreen. In my experience, this will timeout if no window
169 manager is running. 179 manager is running.
170 180
171 ELEMENT RETRIEVAL 181 ELEMENT RETRIEVAL
172 $element_id = $wd->find_element ($location_strategy, $selector) 182 $element_id = $wd->find_element ($location_strategy, $selector)
173 Finds the first element specified by the given selector and returns 183 Finds the first element specified by the given selector and returns
174 its web element id (the strong, not the object from the protocol). 184 its web element ID (the strong, not the object from the protocol).
175 Raises an error when no element was found. 185 Raises an error when no element was found.
176 186
177 $element = $wd->find_element ("css selector" => "body a"); 187 $element = $wd->find_element ("css selector" => "body a");
178 $element = $wd->find_element ("link text" => "Click Here For Porn"); 188 $element = $wd->find_element ("link text" => "Click Here For Porn");
179 $element = $wd->find_element ("partial link text" => "orn"); 189 $element = $wd->find_element ("partial link text" => "orn");
180 $element = $wd->find_element ("tag name" => "input"); 190 $element = $wd->find_element ("tag name" => "input");
181 $element = $wd->find_element ("xpath" => '//input[@type="text"]'); 191 $element = $wd->find_element ("xpath" => '//input[@type="text"]');
182 # "decddca8-5986-4e1d-8c93-efe952505a5f" 192 => e.g. "decddca8-5986-4e1d-8c93-efe952505a5f"
183 193
184 $element_ids = $wd->find_elements ($location_strategy, $selector) 194 $element_ids = $wd->find_elements ($location_strategy, $selector)
185 As above, but returns an arrayref of all found element IDs. 195 As above, but returns an arrayref of all found element IDs.
186 196
187 $element_id = $wd->find_element_from_element ($element_id, 197 $element_id = $wd->find_element_from_element ($element_id,
208 218
209 $string = $wd->get_element_property ($element_id, $name) 219 $string = $wd->get_element_property ($element_id, $name)
210 Returns the value of the given property. 220 Returns the value of the given property.
211 221
212 $string = $wd->get_element_css_value ($element_id, $name) 222 $string = $wd->get_element_css_value ($element_id, $name)
213 Returns the value of the given css value. 223 Returns the value of the given CSS value.
214 224
215 $string = $wd->get_element_text ($element_id) 225 $string = $wd->get_element_text ($element_id)
216 Returns the (rendered) text content of the given element. 226 Returns the (rendered) text content of the given element.
217 227
218 $string = $wd->get_element_tag_name ($element_id) 228 $string = $wd->get_element_tag_name ($element_id)
219 Returns the tag of the given element. 229 Returns the tag of the given element.
220 230
221 $rect = $wd->get_element_rect ($element_id) 231 $rect = $wd->get_element_rect ($element_id)
222 Returns the element rect of the given element. 232 Returns the element rect(angle) of the given element.
223 233
224 $bool = $wd->is_element_enabled 234 $bool = $wd->is_element_enabled
225 Returns whether the element is enabled or not. 235 Returns whether the element is enabled or not.
226 236
227 ELEMENT INTERACTION 237 ELEMENT INTERACTION
335 $text = $wd->send_alert_text 345 $text = $wd->send_alert_text
336 Fills in the user prompt with the given text. 346 Fills in the user prompt with the given text.
337 347
338 SCREEN CAPTURE 348 SCREEN CAPTURE
339 $wd->take_screenshot 349 $wd->take_screenshot
340 Create a screenshot, returning it as a PNG image in a data url. 350 Create a screenshot, returning it as a PNG image in a "data:" URL.
341 351
342 $wd->take_element_screenshot ($element_id) 352 $wd->take_element_screenshot ($element_id)
343 Accept a simple dialog, if present. 353 Accept a simple dialog, if present.
344 354
345 HELPER METHODS 355 HELPER METHODS
356 $object = AnyEvent::WebDriver->element_object ($element_id)
346 $object = $wd->element_object ($element_id) 357 $object = $wd->element_object ($element_id)
347 Encoding element ids in data structures is done by represetning them 358 Encoding element IDs in data structures is done by representing them
348 as an object with a special key and the element id as value. This 359 as an object with a special key and the element ID as value. This
349 helper method does this for you. 360 helper method does this for you.
350 361
351 EVENT BASED API 362 EVENT BASED API
352 This module wouldn't be a good AnyEvent citizen if it didn't have a true 363 This module wouldn't be a good AnyEvent citizen if it didn't have a true
353 event-based API. 364 event-based API.
384 395
385 $cv->recv; 396 $cv->recv;
386 397
387 While the blocking methods "croak" on errors, the callback-based ones 398 While the blocking methods "croak" on errors, the callback-based ones
388 all pass two values to the callback, $status and $res, where $status is 399 all pass two values to the callback, $status and $res, where $status is
389 the HTTP status code (200 for successful requests, typically 4xx ot 5xx 400 the HTTP status code (200 for successful requests, typically 4xx or 5xx
390 for errors), and $res is the value of the "value" key in the JSON 401 for errors), and $res is the value of the "value" key in the JSON
391 response object. 402 response object.
392 403
393 Other than that, the underscore variants and the blocking variants are 404 Other than that, the underscore variants and the blocking variants are
394 identical. 405 identical.
395 406
396 LOW LEVEL API 407 LOW LEVEL API
397 All the simplfiied API methods are very thin wrappers around WebDriver 408 All the simplified API methods are very thin wrappers around WebDriver
398 commands of the same name. Theyx are all implemented in terms of the 409 commands of the same name. They are all implemented in terms of the
399 low-level methods ("req", "get", "post" and "delete"), which exists in 410 low-level methods ("req", "get", "post" and "delete"), which exists in
400 blocking and callback-based variants ("req_", "get_", "post_" and 411 blocking and callback-based variants ("req_", "get_", "post_" and
401 "delete_"). 412 "delete_").
402 413
403 Examples are after the function descriptions. 414 Examples are after the function descriptions.
440 Example: call "find_elements" to find all "IMG" elements, stripping the 451 Example: call "find_elements" to find all "IMG" elements, stripping the
441 returned element objects to only return the element ID strings: 452 returned element objects to only return the element ID strings:
442 453
443 my $elems = $wd->post (elements => { using => "css selector", value => "img" }); 454 my $elems = $wd->post (elements => { using => "css selector", value => "img" });
444 455
445 # yes, the W3C found an interetsing way around the typelessness of JSON 456 # yes, the W3C found an interesting way around the typelessness of JSON
446 $_ = $_->{"element-6066-11e4-a52e-4f735466cecf"} 457 $_ = $_->{"element-6066-11e4-a52e-4f735466cecf"}
447 for @$elems; 458 for @$elems;
448 459
449HISTORY 460HISTORY
450 This module was unintentionally created (it started inside some quickly 461 This module was unintentionally created (it started inside some quickly

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines