Skip to content

Commit

Permalink
feat(executor/web): add statement to manage select component (#229)
Browse files Browse the repository at this point in the history
* Add gecko web driver

* Add a new statement to manage select component

* Rename value parameter to text parameter to avoid confusion + Add documentation and example
  • Loading branch information
kevinramage authored Mar 18, 2020
1 parent 9d5460b commit 9a166c8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
33 changes: 33 additions & 0 deletions executors/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,39 @@ testcases:
screenshot: "result.png"
```
Select statement allow to manipulate select web element
Select statement have 3 parameters
* find: CSS selector to identify the select web element
* text: Text to use to selection the option
* wait: optionnal parameter to wait after the statement (in seconds)
Example
```yaml
name: TestSuite Select
testcases:
- name: TestCase Select
context:
type: web
driver: phantomjs
debug: true
steps:
- action:
navigate:
url: https://html.com/tags/select/
- action:
select:
find: article[id='post-289'] select
text: 'Andean flamingo'
wait: 1
screenshot: selectAndean.png
- action:
select:
find: article[id='post-289'] select
text: 'American flamingo'
screenshot: selectAmerican.png
```
## Output
* result.url
Expand Down
10 changes: 9 additions & 1 deletion executors/web/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Action struct {
Find string `yaml:"find,omitempty"`
Navigate *Navigate `yaml:"navigate,omitempty"`
Wait int64 `yaml:"wait,omitempty"`
Select *Select `yaml:"select,omitempty"`
UploadFile *UploadFile `yaml:"uploadFile,omitempty"`
SelectFrame *SelectFrame `yaml:"selectFrame,omitempty"`
SelectRootFrame bool `yaml:"selectRootFrame,omitempty"`
Expand All @@ -32,6 +33,13 @@ type Navigate struct {
Reset bool `yaml:"reset,omitempty"`
}

// Select represents informations needed to select an option
type Select struct {
Find string `yaml:"find,omitempty"`
Text string `yaml:"text,omitempty"`
Wait int64 `yaml:"wait,omitempty"`
}

// UploadFile represents informations needed to upload files
type UploadFile struct {
Find string `yaml:"find,omitempty"`
Expand All @@ -42,4 +50,4 @@ type UploadFile struct {
// SelectFrame represents informations needed to select the frame
type SelectFrame struct {
Find string `yaml:"find,omitempty"`
}
}
12 changes: 10 additions & 2 deletions executors/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,16 @@ func (Executor) Run(testCaseContext venom.TestCaseContext, l venom.Logger, step
}
} else if e.Action.Wait != 0 {
time.Sleep(time.Duration(e.Action.Wait) * time.Second)

// Upload files
} else if e.Action.Select != nil {
s, err := findOne(ctx.Page, e.Action.Select.Find, r)
if err != nil {
return nil, err
}
if err := s.Select(e.Action.Select.Text); err != nil {
return nil, err
}
if e.Action.Select.Wait != 0 {
time.Sleep(time.Duration(e.Action.Select.Wait) * time.Second)
} else if e.Action.UploadFile != nil {
s, err := find(ctx.Page, e.Action.UploadFile.Find, r)
if err != nil {
Expand Down

0 comments on commit 9a166c8

Please sign in to comment.