start working on session
parent
69754ba545
commit
e0bf4848ff
|
@ -1,12 +1,9 @@
|
|||
USING: kernel http http.client http.server io.streams.byte-array io.pathnames io.encodings.binary io.encodings.string io.encodings.utf8 io.launcher accessors urls parser effects.parser words arrays sequences quotations json.reader json.writer formatting assocs namespaces present hashtables words.symbol combinators lexer calendar prettyprint.backend base64 images.png ;
|
||||
USING: kernel http http.client http.server io.sockets io.streams.byte-array io.pathnames io.encodings.binary io.encodings.string io.encodings.utf8 io.launcher accessors urls parser effects.parser words arrays sequences quotations json.reader json.writer formatting assocs namespaces present hashtables words.symbol combinators lexer calendar prettyprint.backend base64 images.png destructors math.parser threads ;
|
||||
USING: prettyprint ;
|
||||
|
||||
IN: web-driver
|
||||
|
||||
|
||||
|
||||
SYMBOL: current-session-id
|
||||
SYMBOL: current-remote-host
|
||||
SYMBOL: current-web-driver-session
|
||||
|
||||
! https://www.w3.org/TR/webdriver/#elements
|
||||
CONSTANT: web-element-identifier "element-6066-11e4-a52e-4f735466cecf"
|
||||
|
@ -17,20 +14,27 @@ CONSTANT: partial-link-text-location-strategy "partial link text"
|
|||
CONSTANT: tag-name-location-strategy "tag name"
|
||||
CONSTANT: xpath-location-strategy "xpath"
|
||||
|
||||
TUPLE: web-driver uri session-id process ;
|
||||
TUPLE: web-driver-session remote-url session-id capabilities ;
|
||||
TUPLE: session-status message ready? ;
|
||||
|
||||
: current-web-driver-session> ( -- session )
|
||||
current-web-driver-session get ;
|
||||
: >current-web-driver-session ( session -- )
|
||||
current-web-driver-session set ;
|
||||
|
||||
: current-session-id ( -- session-id )
|
||||
current-web-driver-session> session-id>> ;
|
||||
: current-remote-url ( -- remote-url )
|
||||
current-web-driver-session> remote-url>> ;
|
||||
|
||||
: current-session-relative-url ( -- url )
|
||||
"session" current-session-id get append-path >url ;
|
||||
|
||||
: current-base-url ( -- url )
|
||||
current-remote-host get >url ;
|
||||
|
||||
: current-session-url ( -- url )
|
||||
current-base-url current-session-relative-url derive-url ;
|
||||
current-remote-url current-session-relative-url derive-url ;
|
||||
|
||||
: <web-driver-url> ( path -- url )
|
||||
[ current-base-url ] dip >url derive-url ;
|
||||
[ current-remote-url ] dip >url derive-url ;
|
||||
|
||||
: <web-driver-session-url> ( path -- url )
|
||||
[ current-session-url present ] dip append-path >url ;
|
||||
|
@ -81,6 +85,12 @@ TUPLE: capabilities { always-match hashtable } { first-match hashtable } ;
|
|||
[ always-match>> ] [ first-match>> ] bi
|
||||
'H{ { "alwaysMatch" _ } { "firstMatch" _ } } 'H{ { "capabilities" _ } } ;
|
||||
|
||||
: <headless-firefox-capabilities> ( -- hash )
|
||||
H{
|
||||
{ "browserName" "firefox" }
|
||||
{ "moz:firefoxOptions" { "args" { "-headless" } } }
|
||||
} ;
|
||||
|
||||
! Sessions
|
||||
! https://www.w3.org/TR/webdriver/#sessions
|
||||
|
||||
|
@ -316,12 +326,31 @@ TUPLE: rect x y width height ;
|
|||
: take-element-screenshot ( element -- loading-png )
|
||||
"screenshot" <element-get-request> http-web-driver-request base64> binary <byte-reader> load-png ;
|
||||
|
||||
! TODO: Actions
|
||||
|
||||
! TODO: handle driver processes better
|
||||
|
||||
: <chrome-driver-stream> ( url capabilities -- stream )
|
||||
2drop
|
||||
: get-free-listen-port ( -- port )
|
||||
<any-port-local-inet4> utf8 <server>
|
||||
[ addr>> port>> ] [ dispose ] bi number>string ;
|
||||
|
||||
: <chrome-driver-process> ( capabilities -- process )
|
||||
drop
|
||||
"chromedriver --silent --port 4444" utf8 <process-stream> ;
|
||||
|
||||
: <gecko-driver-stream> ( url capabilities -- stream )
|
||||
2drop
|
||||
"geckodriver --port 4444" utf8 <process-stream> ;
|
||||
: <gecko-driver-process> ( host port -- process )
|
||||
'{ "geckodriver" "--host" _ "--port" _ } utf8 <process-reader> ;
|
||||
|
||||
: <web-driver-session> ( -- )
|
||||
"127.0.0.1" get-free-listen-port
|
||||
[ ":" prepend append "http://" prepend "/" append >url ]
|
||||
[ <gecko-driver-process> ] 2bi
|
||||
f f web-driver-session boa
|
||||
>current-web-driver-session ;
|
||||
|
||||
! [ ready?>> ] [ status 1 seconds sleep ] do until
|
||||
!
|
||||
! new-session [ "sessionId" of ] [ "capabilities" of ] bi
|
||||
!
|
||||
! current-web-driver-session> swap >>capabilities swap >>session-id
|
||||
! >current-web-driver-session ;
|
||||
|
|
Loading…
Reference in New Issue