Skip to content

Commit

Permalink
feat(executor/web): add statement to upload file (#232)
Browse files Browse the repository at this point in the history
* Add gecko web driver

* Add new feature to upload file

* Add documentation and example
  • Loading branch information
kevinramage authored Mar 18, 2020
1 parent 07c6ecd commit 9d5460b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
26 changes: 26 additions & 0 deletions executors/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ testcases:
- result.url ShouldStartWith https://www.google.com
```
Upload file actiow allow you to upload file with file input web component
Example:
```yaml
name: TestSuiteUploadFile
testcases:
- name: TestCaseUploadFile
context:
type: web
driver: chrome
debug: true
steps:
- action:
navigate:
url: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_file
- action:
selectFrame:
find: iframe[id='iframeResult']
- action:
uploadFile:
find: form:nth-child(3) input#myfile
files:
- myFile.png
screenshot: "result.png"
```
## Output
* result.url
Expand Down
10 changes: 10 additions & 0 deletions 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"`
UploadFile *UploadFile `yaml:"uploadFile,omitempty"`
SelectFrame *SelectFrame `yaml:"selectFrame,omitempty"`
SelectRootFrame bool `yaml:"selectRootFrame,omitempty"`
NextWindow bool `yaml:"nextWindow,omitempty"`
Expand All @@ -19,16 +20,25 @@ type Fill struct {
Key *string `yaml:"key,omitempty"`
}

// Click represents informations needed to click on web components
type Click struct {
Find string `yaml:"find,omitempty"`
Wait int64 `yaml:"wait"`
}

// Navigate represents informations needed to navigate on defined url
type Navigate struct {
Url string `yaml:"url,omitempty"`
Reset bool `yaml:"reset,omitempty"`
}

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

// SelectFrame represents informations needed to select the frame
type SelectFrame struct {
Find string `yaml:"find,omitempty"`
Expand Down
14 changes: 14 additions & 0 deletions executors/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ 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.UploadFile != nil {
s, err := find(ctx.Page, e.Action.UploadFile.Find, r)
if err != nil {
return nil, err
}
for _, f := range e.Action.UploadFile.Files {
if err := s.UploadFile(f); err != nil {
return nil, err
}
}
if e.Action.UploadFile.Wait != 0 {
time.Sleep(time.Duration(e.Action.UploadFile.Wait) * time.Second)

} else if e.Action.SelectFrame != nil {
s, err := findOne(ctx.Page, e.Action.SelectFrame.Find, r)
Expand Down

0 comments on commit 9d5460b

Please sign in to comment.