Skip to content

Commit

Permalink
Merge pull request #5 from atotto/feature/wait-for-enabled-element
Browse files Browse the repository at this point in the history
add function wait for enabled or disabled state of element
  • Loading branch information
atotto committed Jun 14, 2023
2 parents 38ae516 + df1c2cd commit 4ae23d7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ jobs:
keys:
- go-mod-v1-{{ checksum "go.sum" }}
- run:
name: Install Dependencies
name: go mod download
command: go mod download
- save_cache:
key: go-mod-v1-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run:
name: Chack gofmt
name: check gofmt
command: |
test -z `gofmt -l ./ | tee /dev/stderr | head -n 1`
- run:
name: Chack code
name: check go vet
command: |
go vet ./...
- run:
name: Run tests
name: run tests
command: |
go test -v ./...
36 changes: 36 additions & 0 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,39 @@ func (e *Element) VerifyText(fn func(string, string) bool, expect string) *Eleme
}
return e
}

func (e *Element) WaitForEnabled() *Element {
e.Helper()

var enabled bool
var err error
ok := wait(func() bool {
enabled, err = e.elem.IsEnabled()
if err != nil {
e.Fatal(err)
}
return enabled
})
if !ok {
e.Fatal(err)
}
return e
}

func (e *Element) WaitForDisabled() *Element {
e.Helper()

var enabled bool
var err error
ok := wait(func() bool {
enabled, err = e.elem.IsEnabled()
if err != nil {
e.Fatal(err)
}
return !enabled
})
if !ok {
e.Fatal(err)
}
return e
}
5 changes: 1 addition & 4 deletions example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestSimple(tt *testing.T) {
d := t.OpenBrowser()
d.SetPageLoadTimeout(4 * time.Second)

d.VisitTo("https://tour.golang.org/welcome/1")
d.VisitTo("https://go.dev/tour/welcome/1")
// ngのレンダリングを待たなければrunの結果が出てこない
d.TakeSource("./before.html")
time.Sleep(2 * time.Second)
Expand All @@ -38,9 +38,6 @@ func TestSimple(tt *testing.T) {

d.WaitFor("class:stdout")
d.MustFindElement("class:stdout").VerifyText(strings.Contains, "Hello")

d.MustFindElement("class:next-page").Click()
d.ExpectTransitTo("/welcome/2").TakeScreenshot("page2.png")
}

var code = `
Expand Down

0 comments on commit 4ae23d7

Please sign in to comment.