Skip to content

Commit

Permalink
feat(context/web): add prefs for chromedriver (#257)
Browse files Browse the repository at this point in the history
Signed-off-by: reno-xjb <23520255+reno-xjb@users.noreply.github.com>
  • Loading branch information
reno-xjb committed Jul 8, 2020
1 parent 55f457d commit c5b7536
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
22 changes: 16 additions & 6 deletions context/webctx/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
Height = "height"
Driver = "driver" // Possible values: chrome, phantomjs, gecko
Args = "args"
Prefs = "prefs"
Timeout = "timeout"
Debug = "debug"
)
Expand Down Expand Up @@ -55,15 +56,24 @@ func (tcc *WebTestCaseContext) Init() error {
}
}
}
prefs := map[string]interface{}{}
if _, ok := tcc.TestCase.Context[Prefs]; ok {
switch tcc.TestCase.Context[Prefs].(type) {
case map[interface{}]interface{}:
for k, v := range tcc.TestCase.Context[Prefs].(map[interface{}]interface{}) {
prefs[k.(string)] = v
}
default:
return fmt.Errorf("%s are not a map[string]interface{}: %v (%T)", Prefs, tcc.TestCase.Context[Prefs], tcc.TestCase.Context[Prefs])
}
}

switch driver {
case "chrome":
tcc.wd = agouti.ChromeDriver(agouti.Desired(
agouti.Capabilities{
"chromeOptions": map[string][]string{
"args": args,
},
}))
tcc.wd = agouti.ChromeDriver(
agouti.ChromeOptions("args", args),
agouti.ChromeOptions("prefs", prefs),
)
case "gecko":
tcc.wd = agouti.GeckoDriver()
default:
Expand Down
14 changes: 13 additions & 1 deletion executors/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ Venom allows you to navigate into it and execute actions.
* Action (https://github.com/ovh/venom/tree/master/executors/web/types.go)
* Format

Parameters `debug` (default: false) and `timeout` (default: 180 seconds) are optional.
Web context allows you to configure the browser used for navigation. All parameters are optional:
* width: Width of the browser page
* height: Height of the browser page
* driver: `chrome`, `gecko` or `phantomjs` (default: `phantomjs`)
* args: List of arguments for `chrome` driver (see [here](https://peter.sh/experiments/chromium-command-line-switches/))
* prefs: List of user preferences for `chrome` driver, using dot notation (see [here](http://www.chromium.org/administrators/configuring-other-preferences) and [here](https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup))
* timeout: Timeout in seconds (default: 180)
* debug: Boolean enabling the debug mode of the web driver (default: false)

```yaml
name: TestSuite Web
Expand All @@ -21,6 +28,11 @@ testcases:
width: 1920
height: 1080
driver: phantomjs
args:
- 'browser-test'
prefs:
profile.default_content_settings.popups: 0
profile.default_content_setting_values.notifications: 1
timeout: 60
debug: true
steps:
Expand Down

0 comments on commit c5b7536

Please sign in to comment.