diff --git a/executors/web/README.md b/executors/web/README.md index ca7177a6..793b6456 100644 --- a/executors/web/README.md +++ b/executors/web/README.md @@ -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 diff --git a/executors/web/types.go b/executors/web/types.go index e9db1e38..af24fa17 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"` + UploadFile *UploadFile `yaml:"uploadFile,omitempty"` SelectFrame *SelectFrame `yaml:"selectFrame,omitempty"` SelectRootFrame bool `yaml:"selectRootFrame,omitempty"` NextWindow bool `yaml:"nextWindow,omitempty"` @@ -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"` diff --git a/executors/web/web.go b/executors/web/web.go index ecce1ff8..2851ba26 100644 --- a/executors/web/web.go +++ b/executors/web/web.go @@ -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)