Skip to content

Commit

Permalink
fix: add wait search for iframe if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
dnitsch committed Nov 11, 2022
1 parent 8cbf00f commit bb9e120
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.uistrategy
.ignore*
**/*.ignore*
.report

# Dependency directories (remove the comment below to include it)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NAME := uistrategy
OWNER := dnitsch
GIT_TAG := "0.1.3"
GIT_TAG := "0.2.0"
VERSION := "v$(GIT_TAG)"
REVISION := $(shell git rev-parse --short HEAD)

Expand Down
17 changes: 12 additions & 5 deletions uistrategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type ViewAction struct {
ElementActions []*ElementAction `yaml:"elementActions" json:"elementActions"`
}

// IframeAction
// IframeAction
type IframeAction struct {
Selector string `yaml:"selector,omitempty" json:"selector,omitempty"`
// WaitEval has to be in the form of a boolean return
Expand Down Expand Up @@ -275,6 +275,10 @@ func (lp *LoggedInPage) navigateHelper(page *rod.Page, action *ViewAction) (*rod
// ensureIframeLoaded returns an instnace of a pointer to a rod.Page
// which is a document tree inside an iframe
func (lp *LoggedInPage) ensureIframeLoaded(page *rod.Page, action *ViewAction) (*rod.Page, error) {
// allow for extremely slow iframe and page loads
// search the page for iframe element and then apply selector
page.MustSearch("iframe")

iframe, err := determinActionElement(lp.log, page, Element{Selector: &action.Iframe.Selector})
if err != nil {
return nil, err
Expand All @@ -284,13 +288,14 @@ func (lp *LoggedInPage) ensureIframeLoaded(page *rod.Page, action *ViewAction) (
action.message = fmt.Sprintf("%s\n%s", action.message, "will perform following actions inside an iframe")

page = iframe.MustFrame()
page.MustWaitLoad()
// page.MustWaitLoad()

page.MustWait(fmt.Sprintf(`() => { console.log("trying to look for elements in iframe page");
page.MustWait(fmt.Sprintf(`() => {
console.log("trying to look for elements in iframe page");
try {
return document.readyState === 'complete' && %s;
} catch (ex) {
console.log("failed eval", ex.message)
console.log("failed wait iframe eval", ex.message)
return false
}
}`, action.Iframe.WaitEval))
Expand Down Expand Up @@ -407,6 +412,7 @@ func (lp *LoggedInPage) DetermineActionType(action *ElementAction, elem *rod.Ele
if elem != nil && action.Assert {
// update report with step found
// item found not performing action
lp.log.Debug("assert only returning early")
return nil
}
// if Value is present on the actionElement then always give preference
Expand All @@ -419,8 +425,9 @@ func (lp *LoggedInPage) DetermineActionType(action *ElementAction, elem *rod.Ele
// TODO: expand this into a more switch statement type implementation
// allow - double tap/click, swipe, etc..
elem.MustClick()
// action hover

elem.MustWaitLoad() // when clicked we wait for a
// lp.page.MustWaitLoad()

return nil
}
Expand Down

0 comments on commit bb9e120

Please sign in to comment.