Skip to content

Commit

Permalink
add takesource for debug
Browse files Browse the repository at this point in the history
- 表示画面外にある検証したいデータを見るためにsourceの書き出しを追加
  • Loading branch information
uzuna committed Jul 12, 2019
1 parent 6df0ed8 commit bafcbaf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
14 changes: 14 additions & 0 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ func (b *Browser) TakeScreenshot(name string) *Browser {
return b
}

func (b *Browser) TakeSource(name string) *Browser {
b.Helper()
str, err := b.session.Source()
if err != nil {
b.Fatal(err)
}

err = ioutil.WriteFile(name, []byte(str), 0644)
if err != nil {
b.Fatal(err)
}
return b
}

func (b *Browser) ExpectTransitTo(rawurl string) *Browser {
b.Helper()
expect, err := url.Parse(rawurl)
Expand Down
23 changes: 15 additions & 8 deletions example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ func TestSimple(tt *testing.T) {
defer t.TearDown()

d := t.OpenBrowser()
d.SetPageLoadTimeout(10 * time.Second)
d.SetPageLoadTimeout(4 * time.Second)

d.VisitTo("https://tour.golang.org/welcome/1")
// ngのレンダリングを待たなければrunの結果が出てこない
d.TakeSource("./before.html")
time.Sleep(2 * time.Second)
d.TakeSource("./after.html")

d.WaitFor("id:run")
d.MustFindElement("id:run").Click()

d.VisitTo("https://tour.golang.org/")
d.WaitFor("id:run").Element().Click()
d.WaitFor("class:stdout")
d.MustFindElement("class:stdout").VerifyText(strings.Contains, "Hello")
//d.MustFindElements("class:stdout").Verify(func(e *Element) {
// strings.Contains("Hello")
//})

d.MustFindElement("class:next-page").Click()
d.ExpectTransitTo("/welcome/2").TakeScreenshot("page2.png")
Expand All @@ -47,7 +51,7 @@ import (
)
func main() {
fmt.Println("Hello, 世界!")
fmt.Println("Hello, go世界!")
}
`

Expand All @@ -56,7 +60,7 @@ func TestPlayground(t *testing.T) {
defer ts.TearDown()

b := ts.OpenBrowser()
b.SetPageLoadTimeout(10 * time.Second)
b.SetPageLoadTimeout(2 * time.Second)

b.VisitTo("https://play.golang.org/")
b.WaitFor("id:code").Element().Clear().Input(code)
Expand All @@ -70,4 +74,7 @@ func TestPlayground(t *testing.T) {
text, _ := e.WebElement().Text()
fmt.Printf("%+v\n", text)
}

b.TakeScreenshot("./screenshot.png")
b.TakeSource("./source.html")
}

0 comments on commit bafcbaf

Please sign in to comment.