├── test ├── test.txt ├── chrome-bug.scm~ └── driver.scm ├── .gitignore ├── makefile ├── install.sh ├── TODO ├── web ├── driver │ └── key.scm └── driver.scm ├── readme.md └── LICENSE /test/test.txt: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .tested 2 | libs 3 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | default: .tested 2 | 3 | GUILE ?= guile 4 | 5 | .tested: web/*.scm test/*.scm 6 | hdt 7 | touch $@ 8 | 9 | clean: 10 | rm -rf .tested 11 | 12 | GUILE_SITE_DIR ?= $(shell $(GUILE) -c "(display (%site-dir)) (newline)") 13 | 14 | install: 15 | install -D --target-directory=$(GUILE_SITE_DIR)/web web/*.scm 16 | install -D --target-directory=$(GUILE_SITE_DIR)/web/driver web/driver/*.scm 17 | 18 | uninstall: 19 | rm -rf $(GUILE_SITE_DIR)/web/driver 20 | rm -rf $(GUILE_SITE_DIR)/web/driver.scm 21 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -x 4 | set -e 5 | 6 | export GUILE=guile 7 | 8 | if pacman --version; then 9 | sudo pacman -Syu --needed wget atool guile chromium rust firefox 10 | fi 11 | if dnf --version; then 12 | sudo dnf install wget atool guile22 chromium chromedriver cargo firefox 13 | export GUILE=guile2.2 14 | echo *** To use guile-web-driver with fedora, use command guile2.2 instead of guile! *** 15 | fi 16 | mkdir -p libs 17 | GUILE_JSON_VERSION=4.7.3 18 | GECKODRIVER_VERSION=0.30.0 19 | cd libs 20 | wget https://download.savannah.gnu.org/releases/guile-json/guile-json-$GUILE_JSON_VERSION.tar.gz 21 | aunpack guile-json-$GUILE_JSON_VERSION.tar.gz 22 | cd guile-json-$GUILE_JSON_VERSION 23 | ./configure --prefix=/usr 24 | make 25 | sudo make install 26 | cd .. 27 | wget https://github.com/mozilla/geckodriver/archive/refs/tags/v$GECKODRIVER_VERSION.tar.gz \ 28 | --output-document=geckodriver-$GECKODRIVER_VERSION.tar.gz 29 | aunpack geckodriver-$GECKODRIVER_VERSION.tar.gz 30 | cd geckodriver-$GECKODRIVER_VERSION 31 | cargo install --path . 32 | cd .. 33 | export PATH=$PATH:~/.cargo/bin 34 | echo *** Make sure ~/.cargo/bin is in your path to use geckodriver! *** 35 | cd .. 36 | 37 | make clean 38 | make 39 | sudo make GUILE=$GUILE install 40 | 41 | -------------------------------------------------------------------------------- /test/chrome-bug.scm~: -------------------------------------------------------------------------------- 1 | (define-module (test chrome-bug)) 2 | 3 | (use-modules 4 | (hdt hdt) 5 | (ice-9 match) 6 | (web driver) (web uri) (web request)) 7 | 8 | (test chrome-bug 9 | (set-web-handler! 10 | (lambda (request body) 11 | (match (uri-path (request-uri request)) 12 | ("/a.html" 13 | (values 14 | '((content-type . (text/html))) 15 | " 16 | 17 | b 18 | ")) 19 | ("/b.html" 20 | (values 21 | '((content-type . (text/html))) 22 | " 23 | 24 | a 25 | ")) 26 | ; this works 27 | ; ("/style.css" (values '((content-type . (text/css)) (cache-control . ((max-age . 300)))) "")) 28 | ("/style.css" (values '((content-type . (text/css))) "body { color: red; }")) 29 | (else (values '() "not found"))))) 30 | (navigate-to "http://localhost:8080/a.html") 31 | (click (element-by-link-text "b")) 32 | (click (element-by-link-text "a")) 33 | (click (element-by-link-text "b")) 34 | (click (element-by-link-text "a")) 35 | (assert (equal? "http://localhost:8080/a.html" (current-url)))) 36 | 37 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - extract api reference from readme, add a quick start to the readme 2 | - add (selected? text) helper 3 | - appium, so i can test touch events finally 4 | - Complete all commands from specification 5 | - with-web-driver should also accept arguments, or maybe just one, the driver? 6 | - test-web-handler method, that installs the web server and navigates to it 7 | - check if these bug are also present in the current chromedriver? 8 | - report the bug to chromedriver: 9 | 10 | POST /session/6b2acd62d23a0e24dd925bd796305385/actions HTTP/1.1 11 | Content-Length: 174 12 | Host: localhost:53999 13 | Connection: close 14 | 15 | {"actions" : [{"id" : "keyboard0","type" : "key","actions" : []}, {"id" : "mouse0","type" : "pointer","actions" : [{"button" : 0,"type" : "pointerDown","x" : 10,"y" : 20}]}]} 16 | 17 | crashes chromedriver 18 | 19 | - report the bug to chromedriver 20 | 21 | POST /session/0b91e2565a5276a5740920bf1cf5fdbe/actions HTTP/1.1 22 | Content-Length: 327 23 | Host: localhost:33355 24 | Connection: close 25 | 26 | {"actions" : [{"id" : "keyboard0","type" : "key","actions" : [{"type" : "keyDown","value" : "a"}, {"type" : "pause","duration" : 100}, {"type" : "keyUp","value" : "a"}]}, {"id" : "mouse0","type" : "pointer","actions" : [{"type" : "pause","duration" : 0}, {"type" : "pause","duration" : 0}, {"type" : "pause","duration" : 0}]}]} 27 | 28 | The pause between the keyDown and the keyUp event takes double the time, 200 milliseconds. 29 | 30 | - potential bug: can *attribute* or *property* return an element, or an object? 31 | - wish: get-line should accept no argument to read from current input port 32 | - wish: map should accept vector in place of a list 33 | -------------------------------------------------------------------------------- /web/driver/key.scm: -------------------------------------------------------------------------------- 1 | (define-module (web driver key)) 2 | 3 | (use-modules 4 | (ice-9 match) 5 | (srfi srfi-1)) 6 | 7 | (define-public (key->unicode-char code) 8 | (if (equal? 1 (string-length code)) 9 | code 10 | (first 11 | (find 12 | (match-lambda ((char key-code) (string-ci=? key-code code))) 13 | char-key-codes)))) 14 | 15 | ; Mappings between single unicode character and keyevent codes 16 | ; Copy Pasted from the specification page 17 | ; ttps://w3c.github.io/webdriver/ 18 | 19 | (define char-key-codes 20 | ; normalized key value table 21 | '(("\uE001" "Cancel") 22 | ("\uE002" "Help") 23 | ("\uE003" "Backspace") 24 | ("\uE004" "Tab") 25 | ("\uE005" "Clear") 26 | ("\uE006" "Return") 27 | ("\uE007" "Enter") 28 | ("\uE008" "Shift") 29 | ("\uE009" "Control") 30 | ("\uE00A" "Alt") 31 | ("\uE00B" "Pause") 32 | ("\uE00C" "Escape") 33 | ("\uE00D" " ") 34 | ("\uE00E" "PageUp") 35 | ("\uE00F" "PageDown") 36 | ("\uE010" "End") 37 | ("\uE011" "Home") 38 | ("\uE012" "ArrowLeft") 39 | ("\uE013" "ArrowUp") 40 | ("\uE014" "ArrowRight") 41 | ("\uE015" "ArrowDown") 42 | ("\uE016" "Insert") 43 | ("\uE017" "Delete") 44 | ("\uE018" ";") 45 | ("\uE019" "=") 46 | ("\uE01A" "0") 47 | ("\uE01B" "1") 48 | ("\uE01C" "2") 49 | ("\uE01D" "3") 50 | ("\uE01E" "4") 51 | ("\uE01F" "5") 52 | ("\uE020" "6") 53 | ("\uE021" "7") 54 | ("\uE022" "8") 55 | ("\uE023" "9") 56 | ("\uE024" "*") 57 | ("\uE025" "+") 58 | ("\uE026" ",") 59 | ("\uE027" "-") 60 | ("\uE028" ".") 61 | ("\uE029" "/") 62 | ("\uE031" "F1") 63 | ("\uE032" "F2") 64 | ("\uE033" "F3") 65 | ("\uE034" "F4") 66 | ("\uE035" "F5") 67 | ("\uE036" "F6") 68 | ("\uE037" "F7") 69 | ("\uE038" "F8") 70 | ("\uE039" "F9") 71 | ("\uE03A" "F10") 72 | ("\uE03B" "F11") 73 | ("\uE03C" "F12") 74 | ("\uE03D" "Meta") 75 | ("\uE040" "ZenkakuHankaku") 76 | ("\uE050" "Shift") 77 | ("\uE051" "Control") 78 | ("\uE052" "Alt") 79 | ("\uE053" "Meta") 80 | ("\uE054" "PageUp") 81 | ("\uE055" "PageDown") 82 | ("\uE056" "End") 83 | ("\uE057" "Home") 84 | ("\uE058" "ArrowLeft") 85 | ("\uE059" "ArrowUp") 86 | ("\uE05A" "ArrowRight") 87 | ("\uE05B" "ArrowDown") 88 | ("\uE05C" "Insert") 89 | ("\uE05D" "Delete") 90 | 91 | ; Shifted character table 92 | ("`" "Backquote") 93 | ("\\" "Backslash") 94 | ("\uE003" "Backspace") 95 | ("[" "BracketLeft") 96 | ("]" "BracketRight") 97 | ("," "Comma") 98 | ("0" "Digit0") 99 | ("1" "Digit1") 100 | ("2" "Digit2") 101 | ("3" "Digit3") 102 | ("4" "Digit4") 103 | ("5" "Digit5") 104 | ("6" "Digit6") 105 | ("7" "Digit7") 106 | ("8" "Digit8") 107 | ("9" "Digit9") 108 | ("=" "Equal") 109 | ("<" "IntlBackslash") 110 | ("a" "KeyA") 111 | ("b" "KeyB") 112 | ("c" "KeyC") 113 | ("d" "KeyD") 114 | ("e" "KeyE") 115 | ("f" "KeyF") 116 | ("g" "KeyG") 117 | ("h" "KeyH") 118 | ("i" "KeyI") 119 | ("j" "KeyJ") 120 | ("k" "KeyK") 121 | ("l" "KeyL") 122 | ("m" "KeyM") 123 | ("n" "KeyN") 124 | ("o" "KeyO") 125 | ("p" "KeyP") 126 | ("q" "KeyQ") 127 | ("r" "KeyR") 128 | ("s" "KeyS") 129 | ("t" "KeyT") 130 | ("u" "KeyU") 131 | ("v" "KeyV") 132 | ("w" "KeyW") 133 | ("x" "KeyX") 134 | ("y" "KeyY") 135 | ("z" "KeyZ") 136 | ("-" "Minus") 137 | ("." "Period") 138 | ("'" "Quote") 139 | (";" "Semicolon") 140 | ("/" "Slash") 141 | ("\uE00A" "AltLeft") 142 | ("\uE052" "AltRight") 143 | ("\uE009" "ControlLeft") 144 | ("\uE051" "ControlRight") 145 | ("\uE006" "Enter") 146 | ("\uE03D" "OSLeft") 147 | ("\uE053" "OSRight") 148 | ("\uE008" "ShiftLeft") 149 | ("\uE050" "ShiftRight") 150 | (" " "Space") 151 | ("\uE004" "Tab") 152 | ("\uE017" "Delete") 153 | ("\uE010" "End") 154 | ("\uE002" "Help") 155 | ("\uE011" "Home") 156 | ("\uE016" "Insert") 157 | ("\uE00F" "PageDown") 158 | ("\uE00E" "PageUp") 159 | ("\uE015" "ArrowDown") 160 | ("\uE012" "ArrowLeft") 161 | ("\uE014" "ArrowRight") 162 | ("\uE013" "ArrowUp") 163 | ("\uE00C" "Escape") 164 | ("\uE031" "F1") 165 | ("\uE032" "F2") 166 | ("\uE033" "F3") 167 | ("\uE034" "F4") 168 | ("\uE035" "F5") 169 | ("\uE036" "F6") 170 | ("\uE037" "F7") 171 | ("\uE038" "F8") 172 | ("\uE039" "F9") 173 | ("\uE03A" "F10") 174 | ("\uE03B" "F11") 175 | ("\uE03C" "F12") 176 | ("\uE01A" "Numpad0") 177 | ("\uE01B" "Numpad1") 178 | ("\uE01C" "Numpad2") 179 | ("\uE01D" "Numpad3") 180 | ("\uE01E" "Numpad4") 181 | ("\uE01F" "Numpad5") 182 | ("\uE020" "Numpad6") 183 | ("\uE021" "Numpad7") 184 | ("\uE022" "Numpad8") 185 | ("\uE023" "Numpad9") 186 | ("\uE025" "NumpadAdd") 187 | ("\uE026" "NumpadComma") 188 | ("\uE028" "NumpadDecimal") 189 | ("\uE029" "NumpadDivide") 190 | ("\uE007" "NumpadEnter") 191 | ("\uE024" "NumpadMultiply") 192 | ("\uE027" "NumpadSubtract"))) 193 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## guile-web-driver 2 | 3 | This is a web-driver, or selenium 2, client. 4 | It's purpose is to automate browsers, specifically for automatic web server testing. 5 | Chrome or Firefox can be used as the automated browsers, 6 | or it can connect to arbitrary server providing webdriver interface. 7 | The client implements most of the webdriver [specification](https://www.w3.org/TR/webdriver2/). 8 | 9 | ### Requirements 10 | 11 | - guile version 2.2 12 | - guile-json library from http://download.savannah.gnu.org/releases/guile-json/guile-json-4.7.3.tar.gz 13 | - Optional chromedriver command and either chrome or chromium browser. 14 | Some distribution (arch) install chromedriver as part of chromium package, 15 | some others (debian) provide a separate package (chromium-driver). 16 | Required for unit tests. 17 | - Optional [geckodriver](https://github.com/mozilla/geckodriver/) and mozilla firefox browser. 18 | Required for unit tests. 19 | - Optionally for unit testing, hdt library is required from https://github.com/her01n/hdt 20 | 21 | ### Licence 22 | 23 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 24 | 25 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 26 | 27 | You should have received a copy of the GNU General Public License along with this program. If not, see . 28 | 29 | ### Usage 30 | 31 | ```guile 32 | (use-modules (web driver)) 33 | ``` 34 | 35 | ### Sessions 36 | 37 | Following procedures open and close web driver sessions. 38 | Most procedures takes the web driver session as an optional argument. 39 | Implicit session would be open on first call of such a procedure, 40 | so for most use cases it is not necessary to call *open-web-driver*, 41 | only to call *close-web-driver* without argument when done. 42 | 43 | - **open-web-driver [#:browser 'browser] [#:url url] [#:headless #t] [#:capabilities capabilities]** 44 | 45 | Start a new web driver session. 46 | 47 | *browser* argument should be a symbol, one of the following: 48 | 49 | - 'chrome, 'chromium or 'chromedriver 50 | Launch *chromedriver* command, open a chrome or chromium browser. 51 | The command should be in *PATH*. This is the default. 52 | - 'firefox or 'geckodriver 53 | Launch *geckodriver* command, open a firefox browser. 54 | The command should be in *PATH*. 55 | - 'headless-firefox 56 | Launch *geckodriver* command and open headless firefox. 57 | Deprecated, use *#:browser firefox #:headless #t*. 58 | 59 | If url argument is given, connect to remote webdriver server at the url, 60 | and start a new web driver session there. 61 | *url* should start with "http://". 62 | *browser* must not be specified. 63 | 64 | With *#:headless* option set to *#t*, opens the browser in headless mode. 65 | The page and user interface is not visible, but does not require a window system. 66 | This only works with geckodriver. 67 | 68 | Desired *capabilities* may be requested. 69 | The capabilities are submitted in "alwaysMatch" property. 70 | *capabilities* parameter should be an association list or a hash-table. 71 | To pass an object as a value, it must be specified as a hash-table. 72 | For example: 73 | 74 | ``` 75 | (open-web-driver 76 | #:browser 'geckodriver 77 | #:capabilities 78 | `(("browserName" . "firefox") 79 | ("moz:firefoxOptions" . ,(alist->hash-table `(("args" . ("-headless"))))))) 80 | ``` 81 | 82 | The caller may use *json* macro from *(json)* package to build the hash tables conveniently. 83 | 84 | The new driver would become the default driver in case there is no default driver open yet. 85 | 86 | - **web-driver? object** 87 | 88 | Checks if the object is an instance of web driver, as returned by open-web-driver. 89 | 90 | - **close-web-driver [driver]** 91 | 92 | Closes the web driver. 93 | If the argument is not specified, closes the implicitly open web driver session. 94 | Does nothing if the argument is not specified and the session was not yet imlicitly started. 95 | 96 | - **call-with-web-driver proc** 97 | 98 | Start a web driver session, and call *proc* with the resulting session object. 99 | This new session would be used as default for procedures taking optional session argument. 100 | Closes the session after the proc returns or throws an exception. 101 | Returns the value that the *proc* returned. 102 | 103 | ### Timeouts 104 | 105 | - **set-script-timeout [driver] [milliseconds|#:never]** 106 | 107 | Sets the timeout for executing scripts 108 | with methods **execute-javascript** and **execute-javascript-async**. 109 | Special value **#:never** allows the script to run indefinitely. 110 | Calling without arguments sets the timeout to the default value, 30 seconds. 111 | 112 | - **get-script-timeout [driver]** 113 | 114 | Returns the current script timeout in milliseconds, or **#:never**. 115 | 116 | - **set-page-load-timeout [driver] [milliseconds]** 117 | 118 | Sets the timeout for page loading, for example with **navigate-to** method. 119 | Calling without arguments sets the timeout to the default value, 5 minutes. 120 | 121 | - **get-page-load-timeout [driver]** 122 | 123 | Returns the current page load timeout in milliseconds. 124 | 125 | - **set-implicit-timeout [driver] [milliseconds]** 126 | 127 | Sets the timeout for element location, for example with **element-by-id** method. 128 | Calling without arguments sets the timeout to the default value, 0 milliseconds. 129 | 130 | - **get-implicit-timeout [driver]** 131 | 132 | Returns the current implicit timeout in milliseconds. 133 | 134 | ### Navigation 135 | 136 | - **navigate-to [driver] url** 137 | 138 | Navigates the browser to given url. 139 | Should be the same as user entering the url in the address bar. 140 | In python bindings the analogous method is called 'get'. 141 | 142 | - **current-url [driver]** 143 | 144 | Returns the current url, as shown in the address bar. 145 | 146 | - **back [driver]** 147 | 148 | Navigates to previous page. Does nothing if the browser is already at the start of history list. 149 | 150 | - **forward [driver]** 151 | 152 | Navigates to next page in history list. Does nothing if the browser is at the most recent page. 153 | 154 | - **refresh [driver]** 155 | 156 | Reloads current page. 157 | 158 | - **title [driver]** 159 | 160 | Returns the title of the current page as string. 161 | Returns empty string if the page did not set a title. 162 | 163 | ### Windows 164 | 165 | Let's define **window** as a browser window, tab or a similar concept, 166 | capable of independent navigation. 167 | In the specification, the window is also called **top-level browsing context**. 168 | There is always one *current* window, that would receive navigation calls. 169 | One window is created and made current implicitly at the session opening. 170 | 171 | - **current-window [driver]** 172 | 173 | Returns the current window. 174 | 175 | - **close-window [driver]** 176 | 177 | Close the current window. 178 | The driver may close this session and all subsequent method calls would fail. 179 | 180 | > TODO optionally accept window argument 181 | 182 | - **all-windows [driver]** 183 | 184 | Returns the list of all windows of this session. 185 | 186 | - **open-new-window [driver]** 187 | 188 | Open a new window. 189 | Return the new window. 190 | If the browser does not support windows, open a new tab instead. 191 | 192 | - **open-new-tab [driver]** 193 | 194 | Open a new browser tab. 195 | Return the new window. 196 | If the browser does not support browser tabs, open a new window instead. 197 | 198 | - **switch-to window** 199 | 200 | Makes the window current. 201 | 202 | ### Browsing Context 203 | 204 | **Browsing context** is either the window or a **\**, **\** element. 205 | There is always one **current browsing context**, that recieves content calls, 206 | for example **element-by-...** methods. 207 | The current window is selected as current browsing context at session start, 208 | after navigation step, switching to a different window or similar. 209 | 210 | - **switch-to frame** 211 | 212 | Makes the frame the current browsing context. 213 | **frame** must be a **\** or **\** element. 214 | The frame must be a direct child of the current browser context. 215 | 216 | > TODO allow switching to any frame, not only to the direct child. 217 | 218 | - **switch-to [driver] n** 219 | 220 | Makes the **n**-th child frame of the current browsing context the current browsing context. 221 | **n** is a zero-based integer. 222 | 223 | - **switch-to-parent [driver]** 224 | 225 | If the current browsing context is a frame, 226 | switch to it's parent frame, or to the window if there is no parent frame. 227 | Does nothing if the current browsing context is a window. 228 | 229 | - **switch-to-window [driver]** 230 | 231 | Makes the current window the current browsing context. 232 | 233 | ### Rectangle Record 234 | 235 | We define **\** record type to be used for all screen geometry methods. 236 | It contains four fields: *x*, *y*, *width* and *height*. 237 | All values are integers. 238 | 239 | - **make-rect x y width height** 240 | 241 | Returns new rectangle. 242 | 243 | - **rect? object** 244 | 245 | Checks if object is a **rect**. 246 | 247 | - **rect-x rect** 248 | - **rect-y rect** 249 | - **rect-width rect** 250 | - **rect-height rect** 251 | 252 | Gets a field value. 253 | 254 | ### Resizing and Positioning Windows 255 | 256 | - **window-rect [driver]** 257 | 258 | Returns a screen position and dimension of the current window. 259 | 260 | - **set-window-position [driver] x y** 261 | - **set-window-size [driver] width height** 262 | - **set-window-rect [driver] rect** 263 | 264 | Sets the screen position and/or dimension of the current window. 265 | This implicitly restores the window state to normal. 266 | It may not be possible to honor the new position exactly, 267 | in this case the window is moved and resized to the nearest possible position and dimension. 268 | Returns the new actual window position and dimension. 269 | 270 | - **minimize [driver]** 271 | 272 | Minimize (iconify) the current window. 273 | Does nothing if this is not supported by the window manager. 274 | 275 | - **maximize [driver]** 276 | 277 | Maximize the current window. 278 | If this is not supported by the window manager, 279 | resize the window to the maximum possible size without going full screen. 280 | 281 | - **full-screen [driver]** 282 | 283 | Makes the current window full screen. 284 | If this is not supported by the window manager, maximize the window. 285 | 286 | - **restore [driver]** 287 | 288 | Restores the window to normal, not maximized, full screen or minimized. 289 | 290 | > TODO all these methods may accept window as an argument 291 | 292 | ### Finding Elements 293 | 294 | - **element-by-css-selector [driver] selector [#:from element]** 295 | 296 | Finds the first element that matches css selector. 297 | If there is no such element, throws an exception. 298 | If from element is specified, consider only elements below this element. 299 | 300 | - **elements-by-css-selector [driver] selector [#:from element]** 301 | 302 | Finds all the elements that matches css selector. 303 | Returns empty list in case there is no such element. 304 | If from element is specified, consider only elements below this element. 305 | 306 | - **element-by-id [driver] id [#:from element]** 307 | 308 | Finds the first element with the given id. 309 | If there is no such element, throws an exception. 310 | If from element is specified, consider only elements below this element. 311 | 312 | - **elements-by-id [driver] id [#:from element]** 313 | 314 | Finds all the element with the given id. 315 | Returns empty list in case there is no such element. 316 | If from element is specified, consider only elements below this element. 317 | 318 | - **element-by-class-name [driver] class-name [#:from element]** 319 | 320 | Finds the first element of the class. 321 | If there is no such element, throws an exception. 322 | If from element is specified, consider only elements below this element. 323 | 324 | - **elements-by-class-name [driver] class-name [#:from element]** 325 | 326 | Finds all the element of the class. 327 | Returns empty list in case there is no such element. 328 | If from element is specified, consider only elements below this element. 329 | 330 | - **element-by-link-text [driver] link-text [#:from element]** 331 | 332 | Finds an *a* element that have the rendered text equal to *link-text*. 333 | If there is no such element, throws an exception. 334 | If from element is specified, consider only elements below this element. 335 | 336 | - **elements-by-link-text [driver] link-text [#:from element]** 337 | 338 | Finds all ** elements that have the rendered text equal to *link-text*. 339 | Returns empty list in case there is no such element. 340 | If from element is specified, consider only elements below this element. 341 | 342 | - **element-by-partial-link-text [driver] link-text [#:from element]** 343 | 344 | Finds an ** element where *link-text* is a substring of rendered text. 345 | If there is no such element, throws an exception. 346 | If from element is specified, consider only elements below this element. 347 | 348 | - **elements-by-partial-link-text [driver] link-text [#:from element]** 349 | 350 | Finds all *a* elements where *link-text* is a substring of rendered text. 351 | Returns empty list in case there is no such element. 352 | If from element is specified, consider only elements below this element. 353 | 354 | - **element-by-tag-name [driver] tag [#:from element]** 355 | 356 | Finds the first element with the tag. 357 | If there is no such element, throws an exception. 358 | If from element is specified, consider only elements below this element. 359 | 360 | - **elements-by-tag-name [driver] tag [#:from element]** 361 | 362 | Finds all the elements with the tag. 363 | Returns empty list in case there is no such element. 364 | If from element is specified, consider only elements below this element. 365 | 366 | - **element-by-xpath [driver] xpath [#:from element]** 367 | 368 | Finds the element matching the XPath. 369 | If there is no such element, throws an exception. 370 | If from element is specified, consider only elements below this element. 371 | 372 | - **elements-by-xpath [driver] xpath [#:from element]** 373 | 374 | Finds all the the elements matching the XPath. 375 | Returns empty list in case there is no such element. 376 | If from element is specified, consider only elements below this element. 377 | 378 | - **element-by-label-text [driver] text [#:from element]** 379 | 380 | Finds an **\** element, that has related **\** element 381 | with the specified *text*. 382 | If there is no such element, throws an exception. 383 | If from element is specified, consider only elements below this element. 384 | 385 | - **element-by-partial-label-text [driver] text [#:from element]** 386 | 387 | Finds an **\** element, that has related **\** element 388 | containing *text*. 389 | If there is no such element, throws an exception. 390 | If from element is specified, consider only elements below this element. 391 | 392 | - **active-element [driver]** 393 | 394 | Returns the current active element. 395 | Throws exception if there is no such element. 396 | 397 | ### Element State 398 | 399 | - **selected? element** 400 | 401 | Returns *#t* if the check box or radio box is checked, 402 | or if **\** element is selected. 403 | Throws an exception if the element is not selectable. 404 | 405 | - **attribute element name** 406 | 407 | Gets the value of the element's attribute. 408 | Returns *#f* if the attribute is undefined. 409 | 410 | - **property element name** 411 | 412 | Gets the value of element's javascript property. 413 | Returns *#f* if the property is undefined. 414 | 415 | - **css-value element name** 416 | 417 | Returns the computed value from element's style declarations. 418 | 419 | - **text element** 420 | 421 | Gets the text content of the element. 422 | 423 | - **text [driver]** 424 | 425 | Without an element argument, get the text of the whole page. 426 | 427 | - **tag-name element** 428 | 429 | Returns the tag name of the element. 430 | 431 | - **rect element** 432 | 433 | Returns position and dimension of the element relative to the document element. 434 | 435 | > TODO implement 436 | 437 | - **enabled? element** 438 | 439 | Checks if the form control is enabled. 440 | 441 | ### Element Interaction 442 | 443 | - **click element** 444 | 445 | Simulates user clicking the element, 446 | For example ** element or form control. 447 | 448 | - **click [driver] text** 449 | 450 | If *text* is a string, find an element with the text and click it. 451 | The element may be: 452 | 453 | - An *anchor* with the given link text. 454 | 455 | text 456 | 457 | - A *button* with the given text content. 458 | 459 | 460 | 461 | - An *input* of type *button*, *submit* or *reset* with the text *value*. 462 | 463 | 464 | 465 | - Any *input* that have an associated *label* that contains the text. 466 | 467 | 468 | 469 | 470 | - **clear element** 471 | 472 | Clears all content of content editable element. 473 | Resets the state of File Upload form control. 474 | 475 | - **send-keys element text** 476 | 477 | Simulates user typing the text with the focus on the element. 478 | 479 | The procedure could be used to choose a file for *input* of type *file*. 480 | *text* should be an absolute path to the selected file. 481 | See also *choose-file*. 482 | 483 | - **send-keys [driver] label text** 484 | 485 | Find a label with the text content equal *label*. 486 | Simulates use typing the text into the associated input. 487 | 488 | - **choose-file element path** 489 | 490 | Choose a file for *input* of type *file*. 491 | **path** may be relative or absolute, the file should exist. 492 | 493 | ### Document 494 | 495 | - **page-source [driver]** 496 | 497 | Gets the *html* source of the current browser context (window or frame). 498 | 499 | - **execute-javascript [driver] body [arguments ...]** 500 | 501 | Execute javascript in the current browsing context. 502 | **body** is a string, it may be a single statement or multiple statements separated by ";". 503 | If a statement returns a value with **return**, this value is returned by this method. 504 | Element objects are returned as interchangable with objects returned by **element-by-...* methods. 505 | Other javascript objects are returned as **hash-table**s. 506 | Otherwise return **#nil**. 507 | Arguments are passed as a function arguments. 508 | They can be accessed through *arguments* Array-like variable. 509 | This allows passing elemented returned by **element-by-...** methods to javascript. 510 | It may be practical to pass strings this way to avoid escaping issues. 511 | 512 | Examples: 513 | 514 | ```scheme 515 | (execute-javascript "return 3 + 4") => 7 516 | (execute-javascript "return arguments[0] * 2;" 2) => 4 517 | (execute-javasctipt "arguments[0].innerHTML = 'text'; return 1;" (element-by-id "id")) 518 | (text (execute-javascript "return document.getElementById('id');")) => "text" 519 | ``` 520 | 521 | - **execute-javascript-async [driver] body [arguments ...]** 522 | 523 | Executes javascript and waits for the callback. 524 | Calllback function is appended to the **arguments** variable. 525 | This method returns when this function is called. 526 | The first argument of the function call is the return value. 527 | This method is still subject to configured timeout. 528 | 529 | Example: 530 | 531 | ```scheme 532 | (execute-javascript-async 533 | "callback = arguments[0]; 534 | window.setTimeout(function() { callback(42); }, 1);") => 42 535 | ``` 536 | 537 | ### Cookies 538 | 539 | - **cookie-name cookie** 540 | 541 | The name of the cookie. 542 | 543 | - **cookie-value cookie** 544 | 545 | The cookie value. 546 | 547 | - **cookie-path cookie** 548 | 549 | The cookie path. For example "/". Attribute "Path". 550 | 551 | - **cookie-domain cookie** 552 | 553 | The domain the cookie is visible to. Attribute "Domain". 554 | 555 | - **cookie-secure cookie** 556 | 557 | Whether the cookie is a secure cookie. Attribute "Secure". 558 | 559 | - **cookie-http-only cookie** 560 | 561 | Whether the cookie is an HTTP only cookie. Attribute "HttpOnly". 562 | 563 | - **cookie-expiry cookie** 564 | 565 | When the cookie expires, specified in seconds since Unix Epoch. 566 | Calculated from the value of attribute "Max-Age". 567 | May be *#f* for a session cookie. 568 | 569 | - **cookie-same-site cookie** 570 | 571 | Same Site policy value. May be "Lax", "Strict", or *#f*. 572 | 573 | - **get-all-cookies [driver]** 574 | 575 | List of cookies associated with the current browsing context (domain and path). 576 | 577 | - **get-named-cookie [driver] name** 578 | 579 | Get the cookie with the given name, associated with the current browsing contenxt. 580 | Throws an exception if there is no such cookie. 581 | 582 | - **add-cookie [driver] #:name name #:value value [#:path path] [#:domain domain]** 583 | **[#:secure secure] [#:http-only http-only] [#:expiry expiry] [#:same-site same-site]** 584 | 585 | Add a cookie. 586 | The path defaults to "/". 587 | The domain defaults to current browser domain. 588 | The expiry defaults to a session cookie. 589 | 590 | - **delete-named-cookie [driver] name** 591 | 592 | Delete the named cookie associated with the current browsing context. 593 | If the cookie does not exist, does nothing. 594 | 595 | - **delete-all-cookies [driver]** 596 | 597 | Deletes all cookies associated with the current browsing context. 598 | 599 | ### Actions 600 | 601 | This is a low level interface to generate fine grained input events. 602 | See [Element Interaction](#element-interaction) for higher level interface. 603 | 604 | - **key-down key** 605 | 606 | Simulates user pressing a key on a keyboard. 607 | Key repetition does not apply, 608 | only one **keydown** event would be fired, even if the key stays pressed for long time. 609 | **key** is a string representing the key, it may be: 610 | 611 | - Control character associated with the key. For example "\uE003", "\uE009". 612 | - Single unicode character that results from pressing the key on US keyboard layout. 613 | For example "a", " ", "[". 614 | - [KeyboardEvent.code](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values) value. 615 | For example: "KeyA", "Digit0", "Keypad0", "ControlLeft", "Space", "F4", "ArrowDown". 616 | Code is case insensitive, for example "f4" is accepted. 617 | 618 | - **key-up key** 619 | 620 | Simulates user releasing a key on a keyboard. 621 | The key must match key previouly pressed with **key-down**, 622 | if not the action is silently ignored. 623 | 624 | - **mouse-move x y [duration]** 625 | 626 | Simulate user moving mouse pointer to a location. 627 | **x**, **y** are coordinates relative to the current viewport. 628 | Simulate the cursor movement for the given duration in milliseconds if given. 629 | Multiple intermediate events may be fired in this case. 630 | 631 | - **mouse-down button** 632 | 633 | Simulates user pressing a mouse button. 634 | **button** is either integer index of the button (0 for the left button), 635 | or symbol **#:left**, **#:middle**, **#:right**. 636 | 637 | - **mouse-up button** 638 | 639 | Simulates user releasing a mouse button. 640 | **button** should match button previously pressed with **mouse-down**, 641 | otherwise the action is silently ignored. 642 | 643 | - **wait time** 644 | 645 | Warning: Because of a bug, this does not work correctly with chromedriver. 646 | 647 | Wait before performing following actions. 648 | **time** is given in milliseconds. 649 | 650 | ```scheme 651 | (perform (key-down "KeyA") (wait 20) (key-up "KeyA"))) 652 | ``` 653 | 654 | is roughly equivalent to 655 | 656 | ```scheme 657 | (perform (key-down "KeyA")) 658 | (usleep (* 20 1000)) 659 | (perform (key-up "KeyA")) 660 | ``` 661 | 662 | but potentionaly much more precise. 663 | 664 | Note: In specification, this action is called *pause*. 665 | We use *wait* because *pause* is a core binding in Guile. 666 | 667 | - **release-all** 668 | 669 | Simulates user releasing all currently pressed keys and buttons. 670 | 671 | - **perform [driver] action ...** 672 | 673 | Perform the given actions. 674 | Returns when all the corresponding events were dispatched. 675 | 676 | Examples: 677 | 678 | ```scheme 679 | (perform 680 | (key-down "ShiftRight") (wait 10) (key-down "a") (wait 10) (key-up "a") (wait 10) 681 | (key-up "ShiftRight") 682 | (perform 683 | (mouse-move 1 1) (key-down "ControlLeft") (mouse-down #:left) 684 | (mouse-move 100 100 1000) (release-all)) 685 | ``` 686 | 687 | -------------------------------------------------------------------------------- /web/driver.scm: -------------------------------------------------------------------------------- 1 | (define-module (web driver)) 2 | 3 | (use-modules 4 | (ice-9 hash-table) (ice-9 iconv) (ice-9 match) (ice-9 popen) (ice-9 threads) 5 | (json) 6 | (srfi srfi-1) (srfi srfi-9) (srfi srfi-27) 7 | (web client) (web request) (web response) (web server)) 8 | 9 | (define web-server #f) 10 | (define current-handler #f) 11 | 12 | (define-public (set-web-handler! handler) 13 | "Sets the current handler for the testing web server listening on localhost:8080." 14 | (set! current-handler handler) 15 | (if (not web-server) 16 | ; Start listening in calling thread, so the client can connect as soon as this procedure returns 17 | (let ((server-socket (socket PF_INET SOCK_STREAM 0))) 18 | (setsockopt server-socket SOL_SOCKET SO_REUSEADDR 1) 19 | (bind server-socket AF_INET INADDR_LOOPBACK 8080) 20 | (listen server-socket 16) 21 | (set! web-server #t) 22 | (call-with-new-thread 23 | (lambda () 24 | (run-server 25 | (lambda (request body) (current-handler request body)) 26 | 'http 27 | (list #:socket server-socket))))))) 28 | 29 | (define (request method uri body-scm) 30 | (define body-string (scm->json-string body-scm)) 31 | (define body-bytevector (and body-scm (string->bytevector body-string "utf-8"))) 32 | (call-with-values 33 | (lambda () 34 | (http-request uri #:method method #:body body-bytevector)) 35 | (lambda (response body) 36 | (let ((value (assoc-ref (json-string->scm (bytevector->string body "utf-8")) "value"))) 37 | (if (equal? 200 (response-code response)) 38 | value 39 | (let ((error (assoc-ref value "error")) 40 | (message (assoc-ref value "message"))) 41 | (throw 'web-driver-error 42 | (format #f "~a ~a.\nRequest: ~a ~a\nBody: ~a\nError: ~a\nMessage: ~a\n" 43 | (response-code response) (response-reason-phrase response) 44 | method uri body-string error message)))))))) 45 | 46 | (define (close-driver-pipe pipe) 47 | (kill (hashq-ref port/pid-table pipe) SIGTERM) 48 | (close-pipe pipe)) 49 | 50 | (define (hash-table->alist hash) 51 | (hash-fold (lambda (key value alist) (cons (cons key value) alist)) (list) hash)) 52 | 53 | (define (to-assoc-list scm) 54 | (match scm 55 | ((? list? list) list) 56 | ((? hash-table? hash) (hash-table->alist hash)) 57 | (#f (list)))) 58 | 59 | (define (capabilities->parameters capabilities) 60 | `(("capabilities" . 61 | (("firstMatch" . #(())) 62 | ("alwaysMatch" . ,(to-assoc-list capabilities)))))) 63 | 64 | (define (open* driver-uri finalizer capabilities) 65 | ; wait until the new process starts listening 66 | (find 67 | (lambda (try) 68 | (catch #t 69 | (lambda () (request 'GET (format #f "~a/status" driver-uri) #f) #t) 70 | (lambda (key . args) (usleep (* 10 1000)) #f))) 71 | (iota 100)) 72 | ; start a new session 73 | (catch #t 74 | (lambda () 75 | (let* ((uri (format #f "~a/session" driver-uri)) 76 | (parameters (capabilities->parameters capabilities)) 77 | (response (request 'POST uri parameters)) 78 | (session-id (assoc-ref response "sessionId"))) 79 | (list 'web-driver driver-uri session-id finalizer))) 80 | (lambda (key . args) 81 | (finalizer) 82 | (apply throw key args)))) 83 | 84 | (define (free-listen-port) 85 | "Find an unused port for server to listen on it" 86 | (define s (socket PF_INET SOCK_STREAM 0)) 87 | (listen s 1) 88 | (let ((port (array-ref (getsockname s) 2))) 89 | (close-port s) 90 | port)) 91 | 92 | (define (launch-and-open command args capabilities) 93 | (let* ((port (free-listen-port)) 94 | (pipe (apply open-pipe* OPEN_WRITE command (format #f "--port=~a" port) args)) 95 | (uri (format #f "http://localhost:~a" port))) 96 | (open* uri (lambda () (close-driver-pipe pipe)) capabilities))) 97 | 98 | (define (open-chromedriver capabilities) 99 | (launch-and-open "chromedriver" '("--silent") capabilities)) 100 | 101 | (define (open-geckodriver capabilities) 102 | (launch-and-open "geckodriver" '("--log" "fatal") capabilities)) 103 | 104 | (set! *random-state* (random-state-from-platform)) 105 | 106 | (define (add-firefox-headless capabilities) 107 | (define capabilities' (or capabilities '())) 108 | (define firefox-options (or (assoc-ref "moz:firefoxOptions" capabilities') '())) 109 | (define args (or (assoc-ref "args" firefox-options) #())) 110 | (define args' (list->vector (append (vector->list args) (list "-headless")))) 111 | (define firefox-options' (assoc-set! firefox-options "args" args')) 112 | (assoc-set! capabilities' "moz:firefoxOptions" firefox-options')) 113 | 114 | (define *default-driver* (make-thread-local-fluid)) 115 | 116 | (define-public open-web-driver 117 | (lambda* (#:key browser url headless capabilities) 118 | (define driver 119 | (match (list browser url) 120 | ((#f (? identity url)) 121 | (if (not headless) 122 | (open* url (const #f) capabilities) 123 | (throw 'not-implemented "#:headless not supported when connecting to an url."))) 124 | (((or #f 'chrome 'chromium 'chromedriver) #f) 125 | (if (not headless) 126 | (open-chromedriver capabilities) 127 | (throw 'not-implemented "#:headless not supported for chromedriver."))) 128 | (((or 'firefox 'geckodriver) #f) 129 | (open-geckodriver (if headless (add-firefox-headless capabilities) capabilities))) 130 | (('headless-firefox #f) 131 | (open-web-driver #:browser 'firefox #:headless #t #:capabilities capabilities)) 132 | (((? identity browser) (? identity url)) 133 | (throw 'invalid-arguments "Only one of #:browser and #:url may be specified")) 134 | ((browser #f) 135 | (throw 'unknown-browser (format #f "The browser ~a is not supported." browser))))) 136 | (if (not (fluid-ref *default-driver*)) 137 | (fluid-set! *default-driver* driver)) 138 | driver)) 139 | 140 | (define-public (web-driver? object) 141 | (match object 142 | (('web-driver driver-uri session-id finalizer) #t) 143 | (else #f))) 144 | 145 | (define-public (web-driver-open? driver) 146 | (match driver 147 | (('web-driver driver-uri session-id finalizer) 148 | (catch #t 149 | (lambda () (request 'GET (format #f "~a/status" driver-uri) #f) #t) 150 | (lambda (key . args) #f))))) 151 | 152 | (define* (session-command driver method path #:optional (body-scm '())) 153 | (match driver 154 | (('web-driver driver-uri session-id finalizer) 155 | (request method (format #f "~a/session/~a~a" driver-uri session-id path) body-scm)))) 156 | 157 | (define (close driver) 158 | (match driver 159 | (('web-driver driver-uri session-id finalizer) 160 | (session-command driver 'DELETE "") 161 | (finalizer)))) 162 | 163 | (define-public (close-web-driver . args) 164 | (define driver (if (null? args) (fluid-ref *default-driver*) (car args))) 165 | (if driver (close driver)) 166 | (if (equal? driver (fluid-ref *default-driver*)) 167 | (fluid-set! *default-driver* #f))) 168 | 169 | (define-public (call-with-web-driver proc) 170 | (define driver (open-web-driver)) 171 | (catch #t 172 | (lambda () 173 | (let ((r (with-fluid* *default-driver* driver (lambda () (proc driver))))) 174 | (close-web-driver driver) r)) 175 | (lambda args 176 | (close-web-driver driver) (apply throw args)))) 177 | 178 | (define-public (get-default-driver) 179 | (if (not (fluid-ref *default-driver*)) 180 | (fluid-set! *default-driver* (open-web-driver))) 181 | (fluid-ref *default-driver*)) 182 | 183 | (define-syntax define-public-with-driver 184 | (syntax-rules () 185 | ((define-public-with-driver (proc-name driver args* ...) body* ...) 186 | (define-public (proc-name . args) 187 | (let ((proc (lambda* (driver args* ...) body* ...))) 188 | (if (and (pair? args) (web-driver? (car args))) 189 | (apply proc args) 190 | (apply proc (get-default-driver) args))))))) 191 | 192 | ;;; Timeouts 193 | 194 | (define-public-with-driver (set-script-timeout driver #:optional timeout) 195 | (let ((value (match timeout ((? number? n) n) (#f 30000) (#:never 'null)))) 196 | (session-command driver 'POST "/timeouts" `(("script" . ,value))))) 197 | 198 | (define-public-with-driver (get-script-timeout driver) 199 | (match (assoc-ref (session-command driver 'GET "/timeouts" #f) "script") 200 | ((? number? n) n) 201 | (#nil #:never) 202 | ('null #:never))) 203 | 204 | (define-public-with-driver (set-page-load-timeout driver #:optional (timeout 300000)) 205 | (session-command driver 'POST "/timeouts" `(("pageLoad" . ,timeout)))) 206 | 207 | (define-public-with-driver (get-page-load-timeout driver) 208 | (assoc-ref (session-command driver 'GET "/timeouts" #f) "pageLoad")) 209 | 210 | (define-public-with-driver (set-implicit-timeout driver #:optional (timeout 0)) 211 | (session-command driver 'POST "/timeouts" `(("implicit" . ,timeout)))) 212 | 213 | (define-public-with-driver (get-implicit-timeout driver) 214 | (assoc-ref (session-command driver 'GET "/timeouts" #f) "implicit")) 215 | 216 | ;;; Navigation 217 | 218 | (define-public-with-driver (navigate-to driver url) 219 | (session-command driver 'POST "/url" `(("url" . ,url)))) 220 | 221 | (define-public-with-driver (current-url driver) 222 | (session-command driver 'GET "/url")) 223 | 224 | (define-public-with-driver (back driver) 225 | (session-command driver 'POST "/back")) 226 | 227 | (define-public-with-driver (forward driver) 228 | (session-command driver 'POST "/forward")) 229 | 230 | (define-public-with-driver (refresh driver) 231 | (session-command driver 'POST "/refresh")) 232 | 233 | (define-public-with-driver (title driver) 234 | (session-command driver 'GET "/title")) 235 | 236 | ;;; Windows 237 | 238 | (define (web-driver-window driver window-object) 239 | (list 'web-driver-window driver window-object)) 240 | 241 | (define-public-with-driver (current-window driver) 242 | (web-driver-window driver 243 | (session-command driver 'GET "/window"))) 244 | 245 | (define-public-with-driver (close-window driver) 246 | (session-command driver 'DELETE "/window" '()) 247 | ; XXX chromedriver would keep the deleted window currect, 248 | ; causing all following navigation calls to fail. 249 | (switch-to (first (all-windows driver)))) 250 | 251 | (define-public-with-driver (all-windows driver) 252 | (map 253 | (lambda (window-object) (web-driver-window driver window-object)) 254 | (vector->list (session-command driver 'GET "/window/handles")))) 255 | 256 | (define (new-window driver type) 257 | (web-driver-window 258 | driver 259 | (assoc-ref 260 | (session-command driver 'POST "/window/new" `(("type" . ,type))) 261 | "handle"))) 262 | 263 | (define-public-with-driver (open-new-window driver) 264 | (new-window driver "window")) 265 | 266 | (define-public-with-driver (open-new-tab driver) 267 | (new-window driver "tab")) 268 | 269 | (define-public-with-driver (switch-to driver target) 270 | (match target 271 | (('web-driver-window driver handle) 272 | (session-command driver 'POST "/window" `(("handle" . ,handle)))) 273 | (('web-driver-element driver element) 274 | (session-command driver 'POST "/frame" 275 | `(("id" . (("element-6066-11e4-a52e-4f735466cecf" . ,element)))))) 276 | ((? number? n) 277 | (session-command driver 'POST "/frame" `(("id" . ,n)))))) 278 | 279 | ;;; Browsing Context 280 | 281 | (define-public-with-driver (switch-to-parent driver) 282 | (session-command driver 'POST "/frame/parent")) 283 | 284 | (define-public-with-driver (switch-to-window driver) 285 | (session-command driver 'POST "/frame" '(("id" . null)))) 286 | 287 | ;;; Rectangle Record 288 | 289 | (define-record-type 290 | (make-rect x y width height) 291 | rect? 292 | (x rect-x) 293 | (y rect-y) 294 | (width rect-width) 295 | (height rect-height)) 296 | 297 | (export make-rect rect? rect-x rect-y rect-width rect-height) 298 | 299 | ;;; Resizing and Positioning Windows 300 | 301 | (define (result->rect result) 302 | (let* ((x (assoc-ref result "x")) 303 | (y (assoc-ref result "y")) 304 | (width (assoc-ref result "width")) 305 | (height (assoc-ref result "height"))) 306 | (make-rect x y width height))) 307 | 308 | (define-public-with-driver (window-rect driver) 309 | (result->rect (session-command driver 'GET "/window/rect"))) 310 | 311 | (define-public-with-driver (set-window-position driver x y) 312 | (set-window-rect driver x y 'null 'null)) 313 | 314 | (define-public-with-driver (set-window-size driver width height) 315 | (set-window-rect driver 'null 'null width height)) 316 | 317 | (define-public-with-driver (set-window-rect driver #:rest args) 318 | (match args 319 | ((x y width height) 320 | (result->rect 321 | (session-command driver 'POST "/window/rect" 322 | `(("x" . ,x) ("y" . ,y) ("width" . ,width) ("height" . ,height))))) 323 | ((($ x y width height)) 324 | (set-window-rect driver x y width height)))) 325 | 326 | (define-public-with-driver (minimize driver) 327 | (session-command driver 'POST "/window/minimize")) 328 | 329 | (define-public-with-driver (maximize driver) 330 | (session-command driver 'POST "/window/maximize")) 331 | 332 | (define-public-with-driver (full-screen driver) 333 | (session-command driver 'POST "/window/fullscreen")) 334 | 335 | (define-public-with-driver (restore driver) 336 | (set-window-rect driver 'null 'null 'null 'null)) 337 | 338 | ;;; Elements 339 | 340 | ; XXX elements are returned as a json object with a single weird key 341 | ; with value of the actual element id/reference 342 | (define (web-driver-element driver element-object) 343 | (list 344 | 'web-driver-element driver 345 | (assoc-ref element-object "element-6066-11e4-a52e-4f735466cecf"))) 346 | 347 | (define (element? value) 348 | (match value 349 | (('web-driver-element driver element) #t) 350 | (_ #f))) 351 | 352 | (define (element-object? element-object) 353 | (and 354 | (list? element-object) 355 | (assoc-ref element-object "element-6066-11e4-a52e-4f735466cecf"))) 356 | 357 | (define (element-command element method path body-scm) 358 | (match element 359 | (('web-driver-element driver element) 360 | (session-command driver method (format #f "/element/~a~a" element path) body-scm)))) 361 | 362 | ;;; Finding Elements 363 | 364 | (define (find-element driver using value) 365 | (web-driver-element driver 366 | (session-command driver 367 | 'POST "/element" 368 | `(("using" . ,using) ("value" . ,value))))) 369 | 370 | (define (find-element-from driver from using value) 371 | (web-driver-element driver 372 | (element-command from 373 | 'POST "/element" 374 | `(("using" . ,using) ("value" . ,value))))) 375 | 376 | (define (find-elements driver using value) 377 | (map 378 | (lambda (element-object) (web-driver-element driver element-object)) 379 | (vector->list 380 | (session-command driver 381 | 'POST "/elements" 382 | `(("using" . ,using) ("value" . ,value)))))) 383 | 384 | (define (find-elements-from driver from using value) 385 | (map 386 | (lambda (element-object) (web-driver-element driver element-object)) 387 | (vector->list 388 | (element-command from 389 | 'POST "/elements" 390 | `(("using" . ,using) ("value" . ,value)))))) 391 | 392 | (define-syntax define-finder 393 | (syntax-rules () 394 | ((define-finder element-by elements-by using filter) 395 | (begin 396 | (define-public-with-driver (element-by driver value #:key (from #f)) 397 | (if from 398 | (find-element-from driver from using (filter value)) 399 | (find-element driver using (filter value)))) 400 | (define-public-with-driver (elements-by driver value #:key (from #f)) 401 | (if from 402 | (find-elements-from driver from using (filter value)) 403 | (find-elements driver using (filter value)))))) 404 | ((define-finder element-by elements-by using) 405 | (define-finder element-by elements-by using identity)))) 406 | 407 | (define-finder element-by-css-selector elements-by-css-selector "css selector") 408 | 409 | ; TODO check that the id and class name are valid 410 | ; They should be at least one character and not contain any space characters 411 | 412 | (define-finder element-by-id elements-by-id 413 | "css selector" (lambda (id) (string-append "#" id))) 414 | 415 | (define-finder element-by-class-name elements-by-class-name 416 | "css selector" (lambda (class-name) (string-append "." class-name))) 417 | 418 | (define-finder element-by-tag-name elements-by-tag-name "tag name") 419 | 420 | (define-finder element-by-link-text elements-by-link-text "link text") 421 | 422 | (define-finder element-by-partial-link-text elements-by-partial-link-text "partial link text") 423 | 424 | (define-finder element-by-xpath elements-by-xpath "xpath") 425 | 426 | (define-public-with-driver (element-by-label-text driver text #:key from) 427 | (element-by-xpath driver 428 | (format #f 429 | "//input[@id = //label[normalize-space(text())=normalize-space(~s)]/@for] | 430 | //textarea[@id = //label[normalize-space(text())=normalize-space(~s)]/@for] | 431 | //label[normalize-space(text())=normalize-space(~s)]//input | 432 | //label[normalize-space(text())=normalize-space(~s)]//textarea" 433 | text text text text) 434 | #:from from)) 435 | 436 | (define-public-with-driver (element-by-partial-label-text driver text #:key from) 437 | (element-by-xpath driver 438 | (format #f 439 | "//input[@id = //label[contains(normalize-space(text()), normalize-space(~s))]/@for] | 440 | //textarea[@id = //label[contains(normalize-space(text()), normalize-space(~s))]/@for] | 441 | //label[contains(normalize-space(text()), normalize-space(~s))]//input | 442 | //label[contains(normalize-space(text()), normalize-space(~s))]//textarea" 443 | text text text text) 444 | #:from from)) 445 | 446 | (define-public-with-driver (active-element driver) 447 | (web-driver-element driver (session-command driver 'GET "/element/active"))) 448 | 449 | ;;; Element State 450 | 451 | (define-public (selected? element) 452 | (element-command element 'GET "/selected" #f)) 453 | 454 | (define (fold-null json) 455 | (match json 456 | ('null #f) 457 | (x x))) 458 | 459 | (define-public (attribute element name) 460 | (fold-null (element-command element 'GET (format #f "/attribute/~a" name) #f))) 461 | 462 | (define-public (property element name) 463 | (fold-null (element-command element 'GET (format #f "/property/~a" name) #f))) 464 | 465 | (define-public (css-value element name) 466 | (element-command element 'GET (format #f "/css/~a" name) #f)) 467 | 468 | (define-public-with-driver (text driver #:optional element) 469 | (element-command (or element (element-by-tag-name "body")) 'GET "/text" #f)) 470 | 471 | (define-public (tag-name element) 472 | (element-command element 'GET "/name" #f)) 473 | 474 | (define-public (rect element) 475 | (result->rect 476 | (element-command element 'GET "/rect" #f))) 477 | 478 | (define-public (enabled? element) 479 | (element-command element 'GET "/enabled" #f)) 480 | 481 | ;;; Interacting with elements 482 | 483 | (define (click-xpath text) 484 | (format #f 485 | "//a[normalize-space(text())=normalize-space(~s)] | 486 | //button[normalize-space(text())=normalize-space(~s)] | 487 | //input[(@type='button' or @type='submit' or @type='reset') and @value=~s] | 488 | //input[@id = //label[normalize-space(text())=normalize-space(~s)]/@for] | 489 | //label[normalize-space(text())=normalize-space(~s)]//input" 490 | text text text text text)) 491 | 492 | (define-public-with-driver (click driver target) 493 | (define (execute-click element) (element-command element 'POST "/click" '())) 494 | (cond 495 | ((element? target) (execute-click target)) 496 | ((string? target) (execute-click (element-by-xpath driver (click-xpath target)))))) 497 | 498 | (define-public (clear element) 499 | (element-command element 'POST "/clear" '())) 500 | 501 | (define-public-with-driver (send-keys driver target text) 502 | (element-command 503 | (cond 504 | ((element? target) target) 505 | ((string? target) (element-by-label-text driver target)) 506 | (else (throw 'illegal-argument "target of send-keys must be either element or string: ~a" target))) 507 | 'POST "/value" `(("text" . ,text)))) 508 | 509 | (define-public-with-driver (choose-file driver target path) 510 | (send-keys driver target (canonicalize-path path))) 511 | 512 | ;;; Document 513 | 514 | (define-public-with-driver (page-source driver) 515 | (session-command driver 'GET "/source")) 516 | 517 | (define (scm->javascript value) 518 | (match value 519 | (#t #t) 520 | (#f #f) 521 | (#nil 'null) 522 | ((? number? n) n) 523 | ((? string? s) s) 524 | (('web-driver-element driver handle) 525 | `(("element-6066-11e4-a52e-4f735466cecf" . ,handle))) 526 | ((? list? l) (list->vector (map scm->javascript l))))) 527 | 528 | (define (javascript->scm driver value) 529 | (match value 530 | (#t #t) 531 | (#f #f) 532 | (#nil #nil) 533 | ('null #nil) 534 | ((? number? n) n) 535 | ((? string? s) s) 536 | ((? element-object? r) (web-driver-element driver r)) 537 | ((? vector? v) (map (lambda (value) (javascript->scm driver value)) (vector->list v))) 538 | ((? list? l) (alist->hash-table (map (lambda (key . value) (cons key (javascript->scm driver value))) l))))) 539 | 540 | (define (execute driver path body arguments) 541 | (let ((js-args (map scm->javascript arguments))) 542 | (javascript->scm driver 543 | (session-command 544 | driver 'POST path 545 | `(("script" . ,body) ("args" . ,(list->vector js-args))))))) 546 | 547 | (define-public-with-driver (execute-javascript driver body #:rest arguments) 548 | (execute driver "/execute/sync" body arguments)) 549 | 550 | (define-public-with-driver (execute-javascript-async driver body #:rest arguments) 551 | (execute driver "/execute/async" body arguments)) 552 | 553 | ;;; Cookies 554 | 555 | (define-record-type 556 | (make-cookie name value path domain secure http-only expiry same-site) 557 | cookie? 558 | (name cookie-name) 559 | (value cookie-value) 560 | (path cookie-path) 561 | (domain cookie-domain) 562 | (secure cookie-secure) 563 | (http-only cookie-http-only) 564 | (expiry cookie-expire) 565 | (same-site cookie-same-site)) 566 | 567 | (export 568 | cookie-name cookie-value cookie-path cookie-domain cookie-secure 569 | cookie-http-only cookie-expire cookie-same-site) 570 | 571 | (define (parse-cookie hash) 572 | (make-cookie 573 | (assoc-ref hash "name") 574 | (assoc-ref hash "value") 575 | (or (assoc-ref hash "path") "/") 576 | (assoc-ref hash "domain") 577 | (assoc-ref hash "secure") 578 | (assoc-ref hash "httpOnly") 579 | (assoc-ref hash "expiry") 580 | (assoc-ref hash "samesite"))) 581 | 582 | (define-public-with-driver (get-all-cookies driver) 583 | (map 584 | parse-cookie 585 | (vector->list (session-command driver 'GET "/cookie")))) 586 | 587 | (define-public-with-driver (get-named-cookie driver name) 588 | (parse-cookie (session-command driver 'GET (format #f "/cookie/~a" name)))) 589 | 590 | (define-public-with-driver 591 | (add-cookie driver #:key name value path domain secure http-only expiry same-site) 592 | (let* ((add (lambda (key value) (if value (list (cons key value)) '()))) 593 | (args 594 | (append 595 | (add "name" name) (add "value" value) (add "path" path) (add "domain" domain) 596 | (add "secure" secure) (add "httpOnly" http-only) (add "expiry" expiry) 597 | (add "samesite" same-site))) 598 | (cookie `(("cookie" . ,args)))) 599 | (session-command driver 'POST "/cookie" cookie))) 600 | 601 | (define-public-with-driver (delete-named-cookie driver name) 602 | (session-command driver 'DELETE (format #f "/cookie/~a" name))) 603 | 604 | (define-public-with-driver (delete-all-cookies driver) 605 | (session-command driver 'DELETE "/cookie")) 606 | 607 | ;;; Actions 608 | 609 | (use-modules (web driver key)) 610 | 611 | (define-public (key-down key) (list 'key-down (key->unicode-char key))) 612 | 613 | (define-public (key-up key) (list 'key-up (key->unicode-char key))) 614 | 615 | (define-public mouse-move 616 | (lambda* (x y #:optional duration) (list 'mouse-move x y duration))) 617 | 618 | (define (button-index button) 619 | (match button 620 | (#:left 0) 621 | (#:middle 1) 622 | (#:right 2) 623 | ((? number? n) n))) 624 | 625 | (define-public (mouse-down button) (list 'mouse-down (button-index button))) 626 | 627 | (define-public (mouse-up button) (list 'mouse-up (button-index button))) 628 | 629 | (define-public (wait duration) (list 'wait duration)) 630 | 631 | (define-public (release-all) (list 'release-all)) 632 | 633 | (define pause-action `(("type" . "pause"))) 634 | 635 | (define-public-with-driver (perform driver #:rest actions) 636 | (define (send-actions key-actions mouse-actions) 637 | (session-command 638 | driver 'POST "/actions" 639 | `(("actions" . 640 | #((("type" . "key") 641 | ("id" . "keyboard0") 642 | ("actions" . ,(list->vector key-actions))) 643 | (("type" . "pointer") 644 | ("id" . "mouse0") 645 | ("actions" . ,(list->vector mouse-actions)))))))) 646 | (define (release-actions) 647 | (session-command driver 'DELETE "/actions")) 648 | (define (perform-actions key-actions mouse-actions actions) 649 | (define (key-action action) 650 | (perform-actions 651 | (cons action key-actions) (cons pause-action mouse-actions) (cdr actions))) 652 | (define (mouse-action action) 653 | (perform-actions 654 | (cons pause-action key-actions) (cons action mouse-actions) (cdr actions))) 655 | (if 656 | (null? actions) 657 | (send-actions (reverse key-actions) (reverse mouse-actions)) 658 | (match (car actions) 659 | (('key-down unicode-char) 660 | (key-action `(("type" . "keyDown") ("value" . ,unicode-char)))) 661 | (('key-up unicode-char) 662 | (key-action `(("type" . "keyUp") ("value" . ,unicode-char)))) 663 | (('mouse-down button) 664 | (mouse-action `(("type" . "pointerDown") ("button" . ,button)))) 665 | (('mouse-up button) 666 | (mouse-action `(("type" . "pointerUp") ("button" . ,button)))) 667 | (('mouse-move x y duration) 668 | (mouse-action 669 | `(("type" . "pointerMove") ("x" . ,x) ("y" . ,y) ("origin" . "viewport") 670 | ("duration" . ,(or duration 0))))) 671 | (('wait duration) 672 | (key-action `(("type" . "pause") ("duration" . ,duration)))) 673 | (('release-all) 674 | (perform-actions key-actions mouse-actions '()) 675 | (release-actions) 676 | (apply perform driver (cdr actions)))))) 677 | (if (not (null? actions)) (perform-actions '() '() actions))) 678 | 679 | -------------------------------------------------------------------------------- /test/driver.scm: -------------------------------------------------------------------------------- 1 | (define-module (test driver)) 2 | 3 | (use-modules 4 | (ice-9 hash-table) (ice-9 iconv) (ice-9 match) (ice-9 popen) (ice-9 textual-ports) (ice-9 threads) 5 | (hdt hdt) 6 | (srfi srfi-1) 7 | (web client) (web request) (web response) (web server) (web uri)) 8 | 9 | (use-modules 10 | (web driver)) 11 | 12 | (test set-web-handler! 13 | (set-web-handler! (lambda (request body) (values '() "test"))) 14 | (call-with-values 15 | (lambda () (http-get "http://localhost:8080/")) 16 | (lambda (response body) 17 | (assert (equal? 200 (response-code response))) 18 | (assert (equal? "test" body))))) 19 | 20 | (test call-with-web-driver 21 | (define closed #f) 22 | (assert 23 | (equal? 42 24 | (call-with-web-driver 25 | (lambda (driver) 26 | (assert (web-driver? driver)) 27 | (assert (web-driver-open? driver)) 28 | (assert (equal? driver (get-default-driver))) 29 | (set! closed driver) 30 | 42)))) 31 | (assert (not (web-driver-open? closed)))) 32 | 33 | ; XXX is there a better way? 34 | (define (kill-pipe pipe) (kill (hashq-ref port/pid-table pipe) SIGTERM)) 35 | 36 | (test open-remote-driver 37 | (define pipe (open-pipe* OPEN_WRITE "chromedriver" "--port=4567")) 38 | (sleep 1) 39 | (hook (kill-pipe pipe) (close-pipe pipe)) 40 | (define driver (open-web-driver #:url "http://localhost:4567")) 41 | (hook (close-web-driver driver)) 42 | (navigate-to driver "http://localhost:8080") 43 | (assert (equal? "http://localhost:8080/" (current-url driver)))) 44 | 45 | (test open-geckodriver 46 | (define driver (open-web-driver #:browser 'firefox)) 47 | (assert driver) 48 | (close-web-driver driver)) 49 | 50 | (test headless 51 | (hook (close-web-driver)) 52 | (assert (open-web-driver #:browser 'firefox #:headless #t))) 53 | 54 | (test open-headless-firefox 55 | (define driver (open-web-driver #:browser 'headless-firefox)) 56 | (assert driver) 57 | (close-web-driver driver)) 58 | 59 | (test capabilities 60 | (hook (close-web-driver)) 61 | (test alist 62 | (assert (open-web-driver #:browser 'geckodriver #:capabilities '(("browserName" . "firefox"))))) 63 | (test hash-table 64 | (assert 65 | (open-web-driver 66 | #:browser 'geckodriver 67 | #:capabilities (alist->hash-table '(("browserName" . "firefox"))))))) 68 | 69 | ; Use only one driver, default, to speed up the tests 70 | (hook (close-web-driver)) 71 | 72 | (test timeouts 73 | (test script-timeout 74 | (test milliseconds 75 | (set-script-timeout 20000) 76 | (assert (equal? 20000 (get-script-timeout)))) 77 | (test never 78 | (set-script-timeout #:never) 79 | (assert (equal? #:never (get-script-timeout)))) 80 | (test default 81 | (set-script-timeout) 82 | (assert (equal? 30000 (get-script-timeout))))) 83 | (test page-load-timeout 84 | (test milliseconds 85 | (set-page-load-timeout 60000) 86 | (assert (equal? 60000 (get-page-load-timeout)))) 87 | (test default) 88 | (set-page-load-timeout) 89 | (assert (equal? 300000 (get-page-load-timeout)))) 90 | (test implicit-timeout 91 | (test milliseconds 92 | (set-implicit-timeout 1000) 93 | (assert (equal? 1000 (get-implicit-timeout)))) 94 | (test default 95 | (set-implicit-timeout) 96 | (assert (equal? 0 (get-implicit-timeout))))) 97 | (test independent 98 | (set-script-timeout 10000) 99 | (set-page-load-timeout 20000) 100 | (assert (equal? 10000 (get-script-timeout))))) 101 | 102 | (define (const-html html) 103 | (lambda (request body) (values '((content-type . (text/html))) html))) 104 | 105 | (test navigation 106 | (test navigate-to 107 | ; To get current url we do not really need to run a web server 108 | (navigate-to "http://localhost:8080") 109 | (assert (equal? "http://localhost:8080/" (current-url)))) 110 | (test back-forward 111 | (set-web-handler! (const-html "")) 112 | (navigate-to "http://localhost:8080/a") 113 | (navigate-to "http://localhost:8080/b") 114 | (back) 115 | (assert (equal? "http://localhost:8080/a" (current-url))) 116 | (forward) 117 | (assert (equal? "http://localhost:8080/b" (current-url)))) 118 | (test refresh 119 | (set-web-handler! (const-html "")) 120 | (navigate-to "http://localhost:8080") 121 | (set-web-handler! (const-html "
")) 122 | (refresh) 123 | (assert (element-by-id "theid"))) 124 | (test title 125 | (set-web-handler! (const-html "the title")) 126 | (navigate-to "http://localhost:8080/") 127 | (assert (equal? "the title" (title))))) 128 | 129 | (test windows 130 | (set-web-handler! (const-html "test")) 131 | (test open-close-windows 132 | (assert (equal? 1 (length (all-windows)))) 133 | (open-new-window) 134 | (assert (equal? 2 (length (all-windows)))) 135 | (close-window) 136 | (assert (equal? 1 (length (all-windows))))) 137 | (hook 138 | (define (close-other-windows) 139 | (when (> (length (all-windows)) 1) 140 | (close-window) 141 | (close-other-windows))) 142 | (close-other-windows)) 143 | (test open-new-window 144 | (let ((window (open-new-window))) 145 | (assert (member window (all-windows))))) 146 | (test open-new-tab 147 | (let ((window (open-new-tab))) 148 | (assert (member window (all-windows))))) 149 | (test switch-to-window 150 | (open-new-window) 151 | (match-let (((one two) (all-windows))) 152 | (assert (not (equal? one two))) 153 | (switch-to one) 154 | (assert (equal? one (current-window))) 155 | (switch-to two) 156 | (assert (equal? two (current-window))))) 157 | (test independent-navigation 158 | (open-new-window) 159 | (match-let (((one two) (all-windows))) 160 | (switch-to one) 161 | (navigate-to "http://localhost:8080/one") 162 | (switch-to two) 163 | (navigate-to "http://localhost:8080/two") 164 | (switch-to one) 165 | (assert (equal? "http://localhost:8080/one" (current-url)))))) 166 | 167 | (test browsing-context 168 | (set-web-handler! 169 | (lambda (request body) 170 | (values 171 | '((content-type . (text/html))) 172 | (match (uri-path (request-uri request)) 173 | ("/" "

top

") 174 | ("/inner.html" "

inner

") 175 | (_ "

not found

"))))) 176 | (navigate-to "http://localhost:8080") 177 | (test switch-to-frame 178 | (switch-to (element-by-tag-name "iframe")) 179 | (assert (equal? "inner" (text (element-by-tag-name "p"))))) 180 | (test switch-to-nth 181 | (switch-to 0) 182 | (assert (equal? "inner" (text (element-by-tag-name "p"))))) 183 | (test switch-to-parent 184 | (switch-to (element-by-tag-name "iframe")) 185 | (switch-to-parent) 186 | (assert (equal? "top" (text (element-by-tag-name "p"))))) 187 | (test switch-to-window 188 | (switch-to (element-by-tag-name "iframe")) 189 | (switch-to-window) 190 | (assert (equal? "top" (text (element-by-tag-name "p")))))) 191 | 192 | (test resizing-and-positioning-windows 193 | (test set-window-position 194 | (set-window-position 20 30) 195 | (let ((rect (window-rect))) 196 | (assert (equal? 20 (rect-x rect))) 197 | (assert (equal? 30 (rect-y rect))))) 198 | (test set-window-size 199 | (set-window-size 640 480) 200 | (let ((rect (window-rect))) 201 | (assert (equal? 640 (rect-width rect))) 202 | (assert (equal? 480 (rect-height rect))))) 203 | (test set-window-rect-xywh 204 | (set-window-rect 30 40 800 600) 205 | (assert (equal? (make-rect 30 40 800 600) (window-rect)))) 206 | (test set-window-rect-rect 207 | (set-window-rect (make-rect 40 50 888 666)) 208 | (assert (equal? (make-rect 40 50 888 666) (window-rect)))) 209 | (hook (restore)) 210 | (test minimize 211 | ; do not how to test this, 212 | ; just check it does not throw 213 | (minimize)) 214 | (test maximize 215 | (maximize) 216 | (let ((rect (window-rect))) 217 | (assert (equal? 0 (rect-x rect))) 218 | (assert (>= (rect-width rect) 1280)))) 219 | (test full-screen 220 | (full-screen) 221 | (let ((rect (window-rect))) 222 | (assert (equal? 0 (rect-x rect))) 223 | (assert (equal? 0 (rect-y rect))) 224 | (assert (>= (rect-width rect) 1280)))) 225 | (test restore 226 | (set-window-position 20 30) 227 | (maximize) 228 | (restore) 229 | (let ((rect (window-rect))) 230 | (assert (equal? 20 (rect-x rect))) 231 | (assert (equal? 30 (rect-y rect)))))) 232 | 233 | (test finding-elements 234 | (test element-by-css-selector 235 | (set-web-handler! (const-html "
content
")) 236 | (navigate-to "http://localhost:8080") 237 | (assert (element-by-css-selector "div[type='text']")) 238 | (assert (throws-exception (element-by-css-selector "div[type='image']")))) 239 | (test element-by-id 240 | (set-web-handler! (const-html "
content
")) 241 | (navigate-to "http://localhost:8080") 242 | (assert (element-by-id "theid")) 243 | (assert (throws-exception (element-by-id "missing")))) 244 | (test element-by-class-name 245 | (set-web-handler! (const-html "
xxx
")) 246 | (navigate-to "http://localhost:8080") 247 | (assert (element-by-class-name "clazz")) 248 | (assert (throws-exception (element-by-class-name "missing")))) 249 | (test element-by-link-text 250 | (set-web-handler! (const-html "link text")) 251 | (navigate-to "http://localhost:8080") 252 | (assert (element-by-link-text "link text")) 253 | (assert (throws-exception (element-by-link-text "text"))) 254 | (assert (element-by-partial-link-text "link")) 255 | (assert (throws-exception (element-by-partial-link-text "xxx")))) 256 | (test element-by-tag-name 257 | (set-web-handler! (const-html "link text")) 258 | (navigate-to "http://localhost:8080") 259 | (assert (element-by-tag-name "a")) 260 | (assert (throws-exception (element-by-tag-name "b")))) 261 | (test element-by-xpath 262 | (set-web-handler! (const-html "
content
")) 263 | (navigate-to "http://localhost:8080") 264 | (assert (element-by-xpath "//body/div")) 265 | (assert (throws-exception (element-by-xpath "//div/div")))) 266 | (test elements-by-class-name 267 | (set-web-handler! 268 | (const-html 269 | "
one
two
")) 270 | (navigate-to "http://localhost:8080") 271 | (let ((divs (elements-by-class-name "clazz"))) 272 | (assert (list? divs)) 273 | (assert (equal? 2 (length divs))) 274 | (assert (equal? "one" (text (car divs)))) 275 | (assert (equal? "two" (text (cadr divs)))))) 276 | (test element-from 277 | (set-web-handler! 278 | (const-html "

in

")) 279 | (navigate-to "http://localhost:8080") 280 | (assert (element-by-tag-name "p" #:from (element-by-class-name "full"))) 281 | (assert 282 | (throws-exception (element-by-tag-name "p" #:from (element-by-class-name "empty"))))) 283 | (test element-by-label-text 284 | (test by-id 285 | (set-web-handler! 286 | (const-html 287 | "
")) 288 | (navigate-to "http://localhost:8080") 289 | (define input (element-by-label-text "label text")) 290 | (assert input) 291 | (assert (equal? "text" (attribute input "type"))) 292 | (test partial 293 | (assert (equal? input (element-by-partial-label-text "label"))))) 294 | (test nested 295 | (set-web-handler! 296 | (const-html 297 | "
")) 298 | (navigate-to "http://localhost:8080") 299 | (define input (element-by-label-text "label text")) 300 | (assert input) 301 | (assert (equal? "checkbox" (attribute input "type")))))) 302 | 303 | (test element-state 304 | (test selected? 305 | (set-web-handler! 306 | (const-html 307 | "
308 | 309 | 310 |
")) 311 | (navigate-to "http://localhost:8080") 312 | (assert (selected? (element-by-css-selector "input[name='checked']"))) 313 | (assert (not (selected? (element-by-css-selector "input[name='unchecked'"))))) 314 | (test property 315 | (set-web-handler! 316 | (const-html "content")) 317 | (navigate-to "http://localhost:8080") 318 | (assert (equal? "BODY" (property (element-by-tag-name "body") "tagName")))) 319 | (test attribute 320 | (set-web-handler! (const-html "
")) 321 | (navigate-to "http://localhost:8080") 322 | (assert (equal? "value" (attribute (element-by-tag-name "div") "key"))) 323 | (assert (not (attribute (element-by-tag-name "div") "xxx")))) 324 | (test css-value 325 | (set-web-handler! (const-html "
content
")) 326 | (navigate-to "http://localhost:8080") 327 | (assert (equal? "11px" (css-value (element-by-tag-name "div") "font-size")))) 328 | (test text 329 | (set-web-handler! (const-html "outer
text
")) 330 | (navigate-to "http://localhost:8080") 331 | (assert (equal? "text" (text (element-by-id "theid")))) 332 | (assert (equal? "outer\ntext" (text)))) 333 | (test tag 334 | (set-web-handler! (const-html "
content
")) 335 | (navigate-to "http://localhost:8080") 336 | (assert (equal? "div" (tag-name (element-by-tag-name "div"))))) 337 | (test rect 338 | (set-web-handler! 339 | (const-html 340 | " 341 | 342 |
343 |
344 | 345 | ")) 346 | (navigate-to "http://localhost:8080") 347 | (assert 348 | (equal? 349 | (make-rect 1 2 3 4) 350 | (rect (element-by-tag-name "div"))))) 351 | (test enabled? 352 | (set-web-handler! 353 | (const-html 354 | "
")) 355 | (navigate-to "http://localhost:8080") 356 | (assert (enabled? (element-by-css-selector "input[name='enabled']"))) 357 | (assert (not (enabled? (element-by-css-selector "input[name='disabled']")))))) 358 | 359 | (test element-interaction 360 | (test click 361 | (set-web-handler! 362 | (lambda (request body) 363 | (values 364 | '((content-type . (text/html))) 365 | (match (uri-path (request-uri request)) 366 | ("/" "one") 367 | ("/one/" "one") 368 | (else ""))))) 369 | (navigate-to "http://localhost:8080") 370 | (click (element-by-id "one")) 371 | (assert (equal? "http://localhost:8080/one" (current-url)))) 372 | (test click-string 373 | (test anchor 374 | (set-web-handler! (const-html "anchor text")) 375 | (navigate-to "http://localhost:8080") 376 | (click "anchor text") 377 | (assert (equal? "http://localhost:8080/target.html" (current-url)))) 378 | (test button 379 | (set-web-handler! (const-html "
")) 380 | (navigate-to "http://localhost:8080") 381 | (click "button text") 382 | (assert (string-prefix? "http://localhost:8080/action" (current-url)))) 383 | (test input-button 384 | (set-web-handler! 385 | (const-html "
")) 386 | (navigate-to "http://localhost:8080") 387 | (click "button text") 388 | (assert (string-prefix? "http://localhost:8080/action" (current-url)))) 389 | (test input-with-label-by-id 390 | (set-web-handler! 391 | (const-html 392 | "
")) 393 | (navigate-to "http://localhost:8080") 394 | (click "label text") 395 | (assert (selected? (element-by-id "alpha")))) 396 | (test input-with-label-nested 397 | (set-web-handler! 398 | (const-html 399 | "
")) 400 | (navigate-to "http://localhost:8080") 401 | (click "label text") 402 | (assert (selected? (element-by-tag-name "input"))))) 403 | (test clear 404 | (set-web-handler! (const-html "
")) 405 | (navigate-to "http://localhost:8080") 406 | (clear (element-by-tag-name "input")) 407 | (assert (equal? "" (property (element-by-tag-name "input") "value")))) 408 | (test send-keys 409 | (set-web-handler! 410 | (const-html 411 | "
412 | 413 | 414 | 415 |
")) 416 | (navigate-to "http://localhost:8080") 417 | (test element 418 | (send-keys (element-by-id "text") "keys") 419 | (click (element-by-id "submit")) 420 | (assert (equal? "http://localhost:8080/submit?text=keys" (current-url)))) 421 | (test label 422 | (send-keys "label text" "keys") 423 | (click (element-by-id "submit")) 424 | (assert (equal? "http://localhost:8080/submit?text=keys" (current-url)))))) 425 | 426 | (test send-keys-to-textarea 427 | (set-web-handler! 428 | (const-html 429 | "
430 | 431 | 432 | 433 |
")) 434 | (navigate-to "http://localhost:8080") 435 | (send-keys "label text" "keys") 436 | (click "submit") 437 | (assert (equal? "http://localhost:8080/submit?text=keys" (current-url)))) 438 | 439 | (define (test-file-choosen) 440 | (equal? 441 | "test\n" 442 | (execute-javascript "return document.getElementById('file').files[0].text()"))) 443 | 444 | (test choose-file 445 | (set-web-handler! 446 | (const-html 447 | " 448 | 449 |
450 | 451 | 452 |
453 | 454 | ")) 455 | (navigate-to "http://localhost:8080") 456 | (test element 457 | (choose-file (element-by-id "file") "test/test.txt") 458 | (assert (test-file-choosen))) 459 | (test label 460 | (choose-file "file label" "test/test.txt") 461 | (assert (test-file-choosen)))) 462 | 463 | (test document 464 | (test page-source 465 | (set-web-handler! (const-html "hello")) 466 | (navigate-to "http://localhost:8080") 467 | (assert (equal? "hello" (page-source)))) 468 | (test execute-javascript 469 | (set-web-handler! (const-html "
content
")) 470 | (navigate-to "http://localhost:8080") 471 | (test execute 472 | (execute-javascript "window.location.href = 'http://localhost:1234/'") 473 | (assert (equal? "http://localhost:1234/" (current-url)))) 474 | (test return-value 475 | (assert (equal? 7 (execute-javascript "return 3 + 4")))) 476 | (test pass-parameters 477 | (assert (equal? 7 (execute-javascript "return arguments[0] + arguments[1]" 3 4)))) 478 | ; TODO pass list 479 | (test pass-element 480 | (let ((div (element-by-id "d"))) 481 | (execute-javascript "arguments[0].innerHTML = 'updated'" div) 482 | (assert (equal? "updated" (text div))))) 483 | (test return-element 484 | (let ((div (execute-javascript "return document.getElementById('d')"))) 485 | (assert (equal? "content" (text div))))) 486 | (test return-list 487 | (assert (equal? (list 1 2) (execute-javascript "return [1, 2]")))) 488 | (test return-object 489 | (let ((table (execute-javascript "var r = new Object(); r.key0 = 'value0'; return r;"))) 490 | (assert (hash-table? table)) 491 | (assert (equal? "value0") (hash-ref table "key0"))))) 492 | (test callback 493 | (set-web-handler! (const-html "hello")) 494 | (navigate-to "http://localhost:8080/") 495 | (assert 496 | (equal? 497 | 42 498 | (execute-javascript-async 499 | "callback = arguments[0]; 500 | window.setTimeout(function () { callback(42); }, 1);"))))) 501 | 502 | (test cookies 503 | (set-web-handler! 504 | (lambda (request body) 505 | (values '((set-cookie . "name=value")) "ok"))) 506 | (navigate-to "http://localhost:8080") 507 | (test get-all-cookies 508 | (let ((cookies (get-all-cookies))) 509 | (assert (equal? 1 (length cookies))) 510 | (assert (equal? "name" (cookie-name (first cookies)))) 511 | (assert (equal? "value" (cookie-value (first cookies)))))) 512 | (test get-named-cookie 513 | (let ((cookie (get-named-cookie "name"))) 514 | (assert (equal? "name" (cookie-name cookie))) 515 | (assert (equal? "value" (cookie-value cookie))))) 516 | (test add-cookie 517 | (navigate-to "http://localhost:8080/path/component/test.html") 518 | (add-cookie #:name "session" #:value "77" #:path "/path") 519 | (let ((cookie (get-named-cookie "session"))) 520 | (assert cookie) 521 | (assert (equal? "77" (cookie-value cookie))) 522 | (assert (equal? "/path" (cookie-path cookie))))) 523 | (test delete-named-cookie 524 | (add-cookie #:name "session" #:value "77") 525 | (delete-named-cookie "name") 526 | (let ((cookies (get-all-cookies))) 527 | (assert (equal? 1 (length cookies))) 528 | (assert (equal? "session" (cookie-name (first cookies)))))) 529 | (test delete-all-cookies 530 | (delete-all-cookies) 531 | (assert (null? (get-all-cookies))))) 532 | 533 | (define events-test-web-handler 534 | (const-html 535 | "

536 |

537 | ")) 569 | 570 | (test actions 571 | (set-web-handler! events-test-web-handler) 572 | (navigate-to "http://localhost:8080") 573 | ; the events handler would also log mouse moves 574 | ; "mouse move" event can creep in the log, 575 | ; it is enough if the mouse cursor os located above the automated chrome window 576 | ; we use string-contains instead of equal? for comparing logs 577 | (test keys 578 | (test key-down-up 579 | (perform (key-down "KeyA") (key-up "KeyA")) 580 | (assert (string-contains (text (element-by-id "log")) "KeyA down, KeyA up"))) 581 | (test shift 582 | (perform (key-down "shift") (key-down "KeyA") (key-up "KeyA") (key-up "shift")) 583 | (assert 584 | (string-contains 585 | (text (element-by-id "log")) 586 | "shift ShiftLeft down, shift KeyA down, shift KeyA up, ShiftLeft up"))) 587 | (test control-character 588 | (perform (key-down "\uE00C") (key-up "\uE00C")) 589 | (assert (string-contains (text (element-by-id "log")) "Escape down, Escape up"))) 590 | (test single-character 591 | (perform (key-down "b") (key-up "b")) 592 | (assert (string-contains (text (element-by-id "log")) "KeyB down, KeyB up,"))) 593 | (test separate-calls 594 | (perform (key-down "c")) 595 | (perform (key-up "c")) 596 | (assert (string-contains (text (element-by-id "log")) "KeyC down, KeyC up,")))) 597 | (test mouse 598 | (test dragndrop 599 | (perform (mouse-move 10 20) (mouse-down #:left) (mouse-move 30 40) (mouse-up #:left)) 600 | (assert 601 | (string-contains 602 | (text (element-by-id "log")) 603 | "mouse move (10, 20), mouse 0 down (10, 20), mouse move (30, 40), mouse 0 up (30, 40),"))) 604 | (test right-click 605 | (perform (mouse-move 50 60) (mouse-down #:right) (mouse-up #:right)) 606 | (assert 607 | (string-contains 608 | (text (element-by-id "log")) 609 | "mouse move (50, 60), mouse 2 down (50, 60), mouse 2 up (50, 60),"))) 610 | (test separate-calls 611 | (perform (mouse-move 70 80)) 612 | (perform (mouse-down #:left) (mouse-up #:left)) 613 | (assert 614 | (string-contains 615 | (text (element-by-id "log")) 616 | "mouse move (70, 80), mouse 0 down (70, 80), mouse 0 up (70, 80),")))) 617 | (test key-mouse 618 | (test mask 619 | (perform 620 | (key-down "ShiftLeft") (mouse-move 70 80) (mouse-down #:left) (mouse-up #:left) 621 | (key-up "ShiftLeft")) 622 | (assert 623 | (string-contains 624 | (text (element-by-id "log")) 625 | "shift ShiftLeft down, shift mouse move (70, 80), shift mouse 0 down (70, 80), shift mouse 0 up (70, 80), ShiftLeft up,"))) 626 | (test order 627 | (perform 628 | (mouse-move 90 100) (mouse-down #:left) (key-down "KeyC") (key-up "KeyC") 629 | (mouse-up #:left)) 630 | (assert 631 | (string-contains 632 | (text (element-by-id "log")) 633 | "mouse move (90, 100), mouse 0 down (90, 100), KeyC down, KeyC up, mouse 0 up (90, 100),")))) 634 | ; TODO chromedriver has bug with the wait, test on firefox 635 | ;(test wait 636 | ; (perform (key-down "[") (wait 100) (key-up "[")) 637 | ; (let ((duration (string->number (text (element-by-id "duration"))))) 638 | ; (format #t "duration = ~a\n" duration) 639 | ; (assert (< (abs (- duration 100)) 20))))) 640 | (test mouse-move-with-duration 641 | (perform (mouse-move 0 0) (key-down "t") (mouse-move 100 100 100) (key-up "t")) 642 | ; (get-line (current-input-port)) 643 | (let ((duration (string->number (text (element-by-id "duration"))))) 644 | (assert (< (abs (- duration 100)) 20)))) 645 | (test release-all 646 | (test key-mouse 647 | (perform (mouse-move 10 10) (mouse-down #:left) (key-down "x") (release-all)) 648 | (assert 649 | (string-contains 650 | (text (element-by-id "log")) 651 | "mouse move (10, 10), mouse 0 down (10, 10), KeyX down, KeyX up, mouse 0 up (10, 10),"))) 652 | (test separate-call 653 | (perform (mouse-move 10 10) (mouse-down #:left)) 654 | (perform (key-down "q")) 655 | (perform (release-all)) 656 | (assert 657 | (string-contains 658 | (text (element-by-id "log")) 659 | "mouse move (10, 10), mouse 0 down (10, 10), KeyQ down, KeyQ up, mouse 0 up (10, 10),"))))) 660 | 661 | #! 662 | (test seo 663 | (navigate-to "http://duckduckgo.com") 664 | (send-keys (element-by-id "search_form_input_homepage") "guile webdriver selenium") 665 | (click (element-by-id "search_button_homepage")) 666 | (assert (element-by-css-selector "a[href='https://github.com/her01n/guile-web-driver']"))) 667 | !# 668 | 669 | 670 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------