From 9a166c8cd0ccc634d0e6a0a2b5e56ec87920648b Mon Sep 17 00:00:00 2001 From: kevinramage Date: Wed, 18 Mar 2020 16:06:23 +0100 Subject: [PATCH] feat(executor/web): add statement to manage select component (#229) * 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 --- executors/web/README.md | 33 +++++++++++++++++++++++++++++++++ executors/web/types.go | 10 +++++++++- executors/web/web.go | 12 ++++++++++-- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/executors/web/README.md b/executors/web/README.md index 793b6456..56dff4fc 100644 --- a/executors/web/README.md +++ b/executors/web/README.md @@ -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 diff --git a/executors/web/types.go b/executors/web/types.go index af24fa17..b68389ef 100644 --- a/executors/web/types.go +++ b/executors/web/types.go @@ -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"` @@ -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"` @@ -42,4 +50,4 @@ type UploadFile struct { // SelectFrame represents informations needed to select the frame type SelectFrame struct { Find string `yaml:"find,omitempty"` -} \ No newline at end of file +} diff --git a/executors/web/web.go b/executors/web/web.go index 2851ba26..d8527587 100644 --- a/executors/web/web.go +++ b/executors/web/web.go @@ -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 {