Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - GUI - Add statement to upload file #232

Merged
merged 4 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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