Skip to content

Commit

Permalink
add tests for rod
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Jul 29, 2020
1 parent fd53549 commit 8ae7405
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ func (s *S) TestMonitor() {
host := b.ServeMonitor("127.0.0.1:0", true).Listener.Addr().String()

page := s.page.Navigate("http://" + host)
s.Contains(page.WaitLoad().Element("#targets").HTML(), string(p.TargetID))
s.Contains(page.Element("#targets a").Parent().HTML(), string(p.TargetID))

page.Navigate("http://" + host + "/page/" + string(p.TargetID))
s.Contains(page.Eval(`document.title`).Str, p.TargetID)

s.Equal(400, kit.Req("http://"+host+"/api/page/test").MustResponse().StatusCode)
}

func (s *S) TestRemoteLaunch() {
Expand Down
7 changes: 2 additions & 5 deletions page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,8 @@ func (s *S) TestPageWaitEvent() {
func (s *S) TestAlert() {
page := s.page.Navigate(srcFile("fixtures/alert.html"))

wait := page.HandleDialog(true, "")

go page.Element("button").Click()

wait()
go page.HandleDialog(true, "")()
page.Element("button").Click()
}

func (s *S) TestMouse() {
Expand Down
5 changes: 5 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package rod_test

import (
"errors"

"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/defaults"
)
Expand Down Expand Up @@ -56,6 +58,9 @@ func (s *S) TestSearch() {
el := p.Search("click me")
s.Equal("click me", el.Text())
s.True(el.Click().Matches("[a=ok]"))

_, err := p.SearchE(nil, []string{"not-exists"}, 0, 1)
s.True(errors.Is(err, rod.ErrElementNotFound))
}

func (s *S) TestSearchIframes() {
Expand Down
2 changes: 2 additions & 0 deletions sugar.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ func (p *Page) Close() {
}

// HandleDialog accepts or dismisses next JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload)
// Because alert will block js, usually you have to run the wait function inside a goroutine. Check the unit test
// for it for more information.
func (p *Page) HandleDialog(accept bool, promptText string) (wait func()) {
w := p.HandleDialogE(accept, promptText)
return func() {
Expand Down

0 comments on commit 8ae7405

Please sign in to comment.