Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Element.Disabled() and Element.MustDisabled() #799

Merged
merged 1 commit into from Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions element.go
Expand Up @@ -365,6 +365,15 @@ func (el *Element) Property(name string) (gson.JSON, error) {
return prop.Value, nil
}

// Disabled checks if the element is disabled.
func (el *Element) Disabled() (bool, error) {
prop, err := el.Property("disabled")
if err != nil {
return false, err
}
return prop.Bool(), nil
}

// SetFiles of the current file input element
func (el *Element) SetFiles(paths []string) error {
absPaths := utils.AbsolutePaths(paths)
Expand Down
15 changes: 15 additions & 0 deletions element_test.go
Expand Up @@ -490,6 +490,21 @@ func TestProperty(t *testing.T) {
})
}

func TestDisabled(t *testing.T) {
g := setup(t)

p := g.page.MustNavigate(g.srcFile("fixtures/input.html"))

g.False(p.MustElement("#EnabledButton").MustDisabled())
g.True(p.MustElement("#DisabledButton").MustDisabled())

g.Panic(func() {
el := p.MustElement("#EnabledButton")
g.mc.stubErr(1, proto.RuntimeCallFunctionOn{})
el.MustDisabled()
})
}

func TestSetFiles(t *testing.T) {
g := setup(t)

Expand Down
8 changes: 8 additions & 0 deletions fixtures/input.html
Expand Up @@ -66,6 +66,14 @@

<hr />

<button type="button" id="EnabledButton">Enabled Button</button>

<button type="button" id="DisabledButton" disabled>
Disabled Button
</button>

<hr />

<input type="submit" value="submit" />
</form>
</body>
Expand Down
7 changes: 7 additions & 0 deletions must.go
Expand Up @@ -834,6 +834,13 @@ func (el *Element) MustProperty(name string) gson.JSON {
return prop
}

// MustDisabled is similar to Element.Disabled
func (el *Element) MustDisabled() bool {
disabled, err := el.Disabled()
el.e(err)
return disabled
}

// MustContainsElement is similar to Element.ContainsElement
func (el *Element) MustContainsElement(target *Element) bool {
contains, err := el.ContainsElement(target)
Expand Down