Skip to content

Commit

Permalink
feat(executor/web): statement to manage browser history actions (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinramage authored May 11, 2020
1 parent 0d2ed76 commit 24e4e6c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
36 changes: 36 additions & 0 deletions executors/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,42 @@ testcases:
ConfirmPopup: true
```
History actions allow you to manipulate browser history actions. The following action are available:
* back
* refresh
* forward
Example:
```yaml
name: TestSuiteNavigationHistory
testcases:
- name: TestCaseNavigationHistory
context:
type: web
driver: chrome
debug: true
steps:
- action:
navigate:
url: https://www.google.com
- action:
fill:
- find: input[name='q']
text: ovh venom github
screenshot: search.png
- action:
click:
find: div[jsname='VlcLAe'] input[name='btnK']
wait: 2
- action:
historyAction: back
- action:
historyAction: refresh
- action:
historyAction: forward
```
## Output
* result.url
Expand Down
31 changes: 16 additions & 15 deletions executors/web/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package web

// Action represents what can be done with web executor
type Action struct {
Click *Click `yaml:"click,omitempty"`
Fill []Fill `yaml:"fill,omitempty"`
Find string `yaml:"find,omitempty"`
Navigate *Navigate `yaml:"navigate,omitempty"`
Wait int64 `yaml:"wait,omitempty"`
ConfirmPopup bool `yaml:"confirmPopup,omitempty"`
CancelPopup bool `yaml:"cancelPopup,omitempty"`
Select *Select `yaml:"select,omitempty"`
UploadFile *UploadFile `yaml:"uploadFile,omitempty"`
SelectFrame *SelectFrame `yaml:"selectFrame,omitempty"`
SelectRootFrame bool `yaml:"selectRootFrame,omitempty"`
NextWindow bool `yaml:"nextWindow,omitempty"`
Click *Click `yaml:"click,omitempty"`
Fill []Fill `yaml:"fill,omitempty"`
Find string `yaml:"find,omitempty"`
Navigate *Navigate `yaml:"navigate,omitempty"`
Wait int64 `yaml:"wait,omitempty"`
ConfirmPopup bool `yaml:"confirmPopup,omitempty"`
CancelPopup bool `yaml:"cancelPopup,omitempty"`
Select *Select `yaml:"select,omitempty"`
UploadFile *UploadFile `yaml:"uploadFile,omitempty"`
SelectFrame *SelectFrame `yaml:"selectFrame,omitempty"`
SelectRootFrame bool `yaml:"selectRootFrame,omitempty"`
NextWindow bool `yaml:"nextWindow,omitempty"`
HistoryAction string `yaml:"historyAction,omitempy"`
}

// Fill represents informations needed to fill input/textarea
Expand Down Expand Up @@ -44,12 +45,12 @@ type Select struct {

// UploadFile represents informations needed to upload files
type UploadFile struct {
Find string `yaml:"find,omitempty"`
Find string `yaml:"find,omitempty"`
Files []string `yaml:"files,omitempty"`
Wait int64 `yaml:"wait,omitempty"`
Wait int64 `yaml:"wait,omitempty"`
}

// SelectFrame represents informations needed to select the frame
type SelectFrame struct {
Find string `yaml:"find,omitempty"`
Find string `yaml:"find,omitempty"`
}
17 changes: 17 additions & 0 deletions executors/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ func (Executor) Run(testCaseContext venom.TestCaseContext, l venom.Logger, step
if err := ctx.Page.NextWindow(); err != nil {
return nil, err
}
} else if e.Action.HistoryAction != "" {
switch strings.ToLower(e.Action.HistoryAction) {
case "back":
if err := ctx.Page.Back(); err != nil {
return nil, err
}
case "refresh":
if err := ctx.Page.Refresh(); err != nil {
return nil, err
}
case "forward":
if err := ctx.Page.Forward(); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("History action '%s' is invalid", e.Action.HistoryAction)
}
}

// take a screenshot
Expand Down

0 comments on commit 24e4e6c

Please sign in to comment.