Skip to content

Commit

Permalink
add parent accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Sep 12, 2021
1 parent fed494f commit a7722e5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func (el *Element) String() string {
return fmt.Sprintf("<%s>", el.Object.Description)
}

// Page of the element
func (el *Element) Page() *Page {
return el.page
}

// Focus sets focus on the specified element.
// Before the action, it will try to scroll to the element.
func (el *Element) Focus() error {
Expand Down
5 changes: 5 additions & 0 deletions element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import (
"github.com/ysmood/gson"
)

func (t T) GetElementPage() {
el := t.page.MustNavigate(t.blank()).MustElement("html")
t.Eq(el.Page().SessionID, t.page.SessionID)
}

func (t T) Click() {
p := t.page.MustNavigate(t.srcFile("fixtures/click.html"))
el := p.MustElement("button")
Expand Down
5 changes: 5 additions & 0 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func (p *Page) GetSessionID() proto.TargetSessionID {
return p.SessionID
}

// Browser of the page
func (p *Page) Browser() *Browser {
return p.browser
}

// Info of the page, such as the URL or title of the page
func (p *Page) Info() (*proto.TargetTargetInfo, error) {
return p.browser.pageInfo(p.TargetID)
Expand Down
4 changes: 4 additions & 0 deletions page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
"github.com/ysmood/got"
)

func (t T) GetPageBrowser() {
t.Equal(t.page.Browser(), t.browser)
}

func (t T) GetPageURL() {
t.page.MustNavigate(t.srcFile("fixtures/click-iframe.html")).MustWaitLoad()
t.Regex(`/fixtures/click-iframe.html\z`, t.page.MustInfo().URL)
Expand Down

0 comments on commit a7722e5

Please sign in to comment.