Skip to content

Commit

Permalink
page: add page-switch-to-{parent-,}frame!
Browse files Browse the repository at this point in the history
Closes #9
  • Loading branch information
Bogdanp committed May 12, 2024
1 parent 80423bd commit a1621cf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/frame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>
<title>iFrame example</title>
</head>
<body>
<iframe src="https://example.com"></iframe>
</body>
</html>
15 changes: 15 additions & 0 deletions examples/frame.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#lang racket/base

(require marionette
racket/runtime-path)

(define-runtime-path frame.html
"frame.html")

(call-with-marionette/browser/page!
(lambda (p)
(page-goto! p (format "file:///~a" frame.html))
(page-switch-to-frame! p (page-query-selector! p "iframe"))
(eprintf "frame h1: ~s~n" (element-text (page-query-selector! p "h1")))
(page-switch-to-parent-frame! p)
(eprintf "outer h1: ~s~n" (page-query-selector! p "h1"))))
14 changes: 14 additions & 0 deletions marionette-doc/scribblings/marionette.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ separately.
@deftogether[
(@defproc[(page-title [p page?]) string?]
@defproc[(page-url [p page?]) url?])]{

Accessors for @racket[p]'s title and url, respectively.
}

Expand Down Expand Up @@ -338,6 +339,7 @@ separately.
@defproc[(page-delete-cookie! [p page?] [name string?]) void?]
)]{

Accessors and modifiers for a @racket[page]'s cookies.
}

@deftogether[
Expand All @@ -352,6 +354,18 @@ separately.
behavior in your @tech{capabilities}.
}

@defproc[(page-switch-to-frame! [p page?]
[e element?]) void?]{

Switch @racket[p]'s context to the given HTML frame element.
}

@defproc[(page-switch-to-parent-frame! [p page?]) void?]{

Switch @racket[p]'s context to the parent of the current frame. Does
nothing if the current frame is the root frame.
}

@defproc[(call-with-page-pdf! [page page?]
[proc (-> bytes? any)]) any]{

Expand Down
2 changes: 1 addition & 1 deletion marionette-lib/info.rkt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#lang info

(define license 'BSD-3-Clause)
(define version "1.2.1")
(define version "1.3")
(define collection "marionette")
(define deps
'("base"
Expand Down
12 changes: 11 additions & 1 deletion marionette-lib/page.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
[page-alert-accept! (-> page? void?)]
[page-alert-dismiss! (-> page? void?)]
[page-alert-type! (-> page? string? void?)]
[page-switch-to-frame! (->* [page? element?]
[boolean?]
void?)]
[page-switch-to-parent-frame! (-> page? void?)]
[call-with-page-pdf! (-> page? (-> bytes? any) any)]
[call-with-page-screenshot! (->* [page? (-> bytes? any)]
[#:full? boolean?]
Expand All @@ -79,7 +83,7 @@
(define (page-focused? p)
(browser-current-page=? (page-browser p) p))

(define (call-with-page p proc)
(define (call-with-page p proc) ;; noqa
(dynamic-wind
(λ () (unless (page-focused? p)
(sync/enable-break (marionette-switch-to-window! (page-marionette p) (page-id p)))
Expand Down Expand Up @@ -276,6 +280,12 @@
(define (page-alert-type! p text)
(syncv (marionette-send-alert-text! (page-marionette p) text)))

(define (page-switch-to-frame! p e [focus? #t])
(syncv (marionette-switch-to-frame! (page-marionette p) (element-handle e) focus?)))

(define (page-switch-to-parent-frame! p)
(syncv (marionette-switch-to-parent-frame! (page-marionette p))))

(define (call-with-page-pdf! p proc)
(with-page p
(proc
Expand Down

0 comments on commit a1621cf

Please sign in to comment.