web

package
v1.1.0-beta.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2022 License: Apache-2.0 Imports: 10 Imported by: 5

README

Venom - Executor Web

Navigate within a web application

Use case: You have a web application and you want to check some behaviors.

The web executor allows you to navigate into your web application and execute actions.

Input

You can define parameters to configure the browser used during the test suite. All parameters are optional:

  • width: Width of the browser page
  • height: Height of the browser page
  • driver (default: phantomjs):
    • phantomjs (the phantomjs binary must be installed - see here)
    • gecko (the geckodriver binary must be installed - see here)
    • chrome (the chromedriver binary must be installed - see here)
  • args: List of arguments for chrome driver (see here)
  • prefs: List of user preferences for chrome driver, using dot notation (see here and here)
  • timeout: Timeout in seconds (default: 180)
  • debug: Boolean, enabling/disabling the debug mode of the web driver (default: false)
name: TestSuite Web
vars:
  web:
    driver: chrome
    width: 1920
    height: 1080
    args:
    - 'browser-test'
    prefs:
      profile.default_content_settings.popups: 0
      profile.default_content_setting_values.notifications: 1
    timeout: 60
    debug: true
testcases:
- name: TestCase Google search
  steps:
  - type: web
    action:
      navigate:
        url: https://www.google.fr
    assertions:
    - result.title ShouldEqual Google
    - result.url ShouldEqual https://www.google.fr
  - type: web
    action:
      find: input[name="q"]
    assertions:
     - result.find ShouldEqual 1
  - type: web
    action:
      fill:
      - find: input[name="q"]
        text: "venom ovh"
  - type: web
    action:
      click:
        find: input[value="Recherche Google"]
        wait: 1
    screenshot: googlesearch.png

The selectFrame and selectRootFrame actions allow to navigate into the different frames of the web page. After the frame selection, you can manipulate web elements present in this frame.

selectFrame has one parameter (find) to select the frame with its CSS selector.

selectRootFrame has one boolean parameter which must be set to true to activate the action.

Example:

name: TestSuite SelectFrame
vars:
  web:
    driver: phantomjs
    debug: true
testcases:
- name: TestCase SelectFrame 
  steps:
  - type: web
    action:
      navigate:
        url: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open
  - type: web
    action:
      selectFrame:
        find: iframe[id='iframeResult']
  - type: web
    action:
      find: body > button
    assertions:
    - result.find ShouldEqual 1
  - type: web
    action:
      find: a#tryhome
    assertions:
    - result.find ShouldEqual 0
  - type: web
    action:
      selectRootFrame: true
  - type: web
    action:
      find: body > button
    assertions:
    - result.find ShouldEqual 0
  - type: web
    action:
      find: a#tryhome
    assertions:
    - result.find ShouldEqual 1

The nextWindow action allows to change the current window. This action has one boolean parameter which must be set to true to activate the action.

Example:

name: TestSuite NextWindow
vars:
  web:
    driver: chrome
    debug: true
testcases:
- name: TestCase NextWindow 
  steps:
  - type: web
    action:
      navigate:
        url: https://javascript.info/popup-windows
  - type: web
    action:
      click:
        find: article > div:nth-child(3) > div:nth-child(17) a[data-action='run']
        wait: 4
    screenshot: beforeNextWindow.png
  - type: web
    action:
      nextWindow: true
    screenshot: resultNextWindow.png
    assertions:
      - result.url ShouldStartWith https://www.google.com

The uploadFile action allows to upload a file into a web page.

Example:

name: TestSuiteUploadFile
vars:
  web:
    driver: chrome
    debug: true
testcases:
- name: TestCaseUploadFile
  steps:
  - type: web
    action:
      navigate:
        url: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_file
  - type: web
    action:
      selectFrame:
        find: iframe[id='iframeResult']
  - type: web
    action:
      uploadFile:
        find: form:nth-child(3) input#myfile
        files:
        - myFile.png
    screenshot: result.png

The select action allows to select an item into a list (a select web element) in a web page.

This action has 3 parameters:

  • find: the CSS selector to identify the select web element
  • text: the item to select in the list
  • wait: (optional) pause after the selection is made

Example:

name: TestSuite Select
vars:
  web:
    driver: phantomjs
    debug: true
testcases:
- name: TestCase Select 
  steps:
  - type: web
    action:
      navigate:
        url: https://html.com/tags/select/
  - type: web
    action:
      select:
        find: article[id='post-289'] select
        text: 'Andean flamingo'
        wait: 1
    screenshot: selectAndean.png
  - type: web
    action:
      select:
        find: article[id='post-289'] select
        text: 'American flamingo'
    screenshot: selectAmerican.png

The confirmPopup and cancelPopup actions allow to manipulate modal dialog boxes displayed by the alert and the confirm javascript statements.

Both actions have one boolean parameter which must be set to true to activate the action.

Warning: These actions are not compatible with the phantomJS driver.

Example:

name: TestSuite Popup
vars:
  web:
    driver: chrome
    debug: true
testcases:
- name: TestCase Popup 
  steps:
  - type: web
    action:
      navigate:
        url: https://javascript.info/alert-prompt-confirm
  - type: web
    action:
      click:
        find: article > div:nth-child(3) > div:nth-child(8) a[data-action='run']
        wait: 1
  - type: web
    action:
      ConfirmPopup: true
  - type: web
    action:
      click:
        find: article > div:nth-child(3) > div:nth-child(26) a[data-action='run']
        wait: 1
  - type: web
    action:
      ConfirmPopup: true
  - type: web
    action:
      ConfirmPopup: true
  - type: web
    action:
      click:
        find: article > div:nth-child(3) > div:nth-child(26) a[data-action='run']
        wait: 1
  - type: web
    action:
      CancelPopup: true
  - type: web
    action:
      ConfirmPopup: true

The historyAction action is provided to manage the browser history.

This action has three possible values:

  • back
  • refresh
  • forward

Example:

name: TestSuiteNavigationHistory
vars:
  web:
    driver: chrome
    debug: true
testcases:
- name: TestCaseNavigationHistory
  steps:
  - type: web
    action:
      navigate:
        url: https://www.google.com
  - type: web
    action:
        fill:
        - find: input[name='q']
          text: ovh venom github
    screenshot: search.png
  - type: web
    action:
        click:
            find: div[jsname='VlcLAe'] input[name='btnK']
            wait: 2
  - type: web
    action:
        historyAction: back
  - type: web
    action:
        historyAction: refresh
  - type: web
    action:
        historyAction: forward

Output

  • result.url: URL of the current page
  • result.timeseconds: duration of the action execution
  • result.title: title of the current page
  • result.find: equals to 1 if the requested web element has been found

Chrome

This section describes some features specific to the Chrome browser.

CI

If you want to include some Chrome Driver tests in your integration pipeline, you must execute Chrome in headless mode.

Example

name: TestSuite Web
vars:
  web:
    width: 1920
    height: 1080
    driver: chrome
    args:
    - 'headless'
    timeout: 60
    debug: true
testcases:
- name: Test disable same site security
  steps:
  - type: web
    action:
      navigate:
        url: https://www.google.fr
Flags

In the Chrome browser, you can turn experimental features on or off to test the behavior of upcoming features (check the chrome://flags url).

In the web executor, to enable a feature, use the enable-features argument.

To disable a feature, use the disable-features argument.

Example

name: TestSuite Web
vars:
  web:
    driver: chrome
    args:
    - 'disable-features=SameSiteByDefaultCookies'
    - 'enable-features=CookiesWithoutSameSiteMustBeSecure'
testcases:
- name: Test disable same site security
  steps:
  - type: web
    action:
      navigate:
        url: https://samesite-sandbox.glitch.me/
  - type: web
    action:
      wait: 5

Documentation

Index

Constants

View Source
const (
	Name       = "web"
	ContextKey = venom.ContextKey("webContext")
)

Key of context element in testsuite file

Variables

View Source
var Keys = map[string]string{
	"NULL":            "\uE000",
	"CANCEL":          "\uE001",
	"HELP":            "\uE002",
	"BACK_SPACE":      "\uE003",
	"TAB":             "\uE004",
	"CLEAR":           "\uE005",
	"RETURN":          "\uE006",
	"ENTER":           "\uE007",
	"SHIFT":           "\uE008",
	"LEFT_SHIFT":      "\uE008",
	"CONTROL":         "\uE009",
	"LEFT_CONTROL":    "\uE009",
	"ALT":             "\uE00A",
	"LEFT_ALT":        "\uE00A",
	"PAUSE":           "\uE00B",
	"ESCAPE":          "\uE00C",
	"SPACE":           "\uE00D",
	"PAGE_UP":         "\uE00E",
	"PAGE_DOWN":       "\uE00F",
	"END":             "\uE010",
	"HOME":            "\uE011",
	"LEFT":            "\uE012",
	"ARROW_LEFT":      "\uE012",
	"UP":              "\uE013",
	"ARROW_UP":        "\uE013",
	"RIGHT":           "\uE014",
	"ARROW_RIGHT":     "\uE014",
	"DOWN":            "\uE015",
	"ARROW_DOWN":      "\uE015",
	"INSERT":          "\uE016",
	"DELETE":          "\uE017",
	"SEMICOLON":       "\uE018",
	"EQUALS":          "\uE019",
	"NUMPAD0":         "\uE01A",
	"NUMPAD1":         "\uE01B",
	"NUMPAD2":         "\uE01C",
	"NUMPAD3":         "\uE01D",
	"NUMPAD4":         "\uE01E",
	"NUMPAD5":         "\uE01F",
	"NUMPAD6":         "\uE020",
	"NUMPAD7":         "\uE021",
	"NUMPAD8":         "\uE022",
	"NUMPAD9":         "\uE023",
	"MULTIPLY":        "\uE024",
	"ADD":             "\uE025",
	"SEPARATOR":       "\uE026",
	"SUBTRACT":        "\uE027",
	"DECIMAL":         "\uE028",
	"DIVIDE":          "\uE029",
	"F1":              "\uE031",
	"F2":              "\uE032",
	"F3":              "\uE033",
	"F4":              "\uE034",
	"F5":              "\uE035",
	"F6":              "\uE036",
	"F7":              "\uE037",
	"F8":              "\uE038",
	"F9":              "\uE039",
	"F10":             "\uE03A",
	"F11":             "\uE03B",
	"F12":             "\uE03C",
	"META":            "\uE03D",
	"COMMAND":         "\uE03D",
	"ZENKAKU_HANKAKU": "\uE040",
}

Keys map returning key code by its name

Functions

func New

func New() venom.Executor

New returns a new Executor

Types

type Action

type Action struct {
	Click           *Click       `yaml:"click,omitempty"`
	Fill            []Fill       `yaml:"fill,omitempty"`
	Find            string       `yaml:"find,omitempty"`
	Navigate        *Navigate    `yaml:"navigate,omitempty"`
	Wait            int64        `yaml:"wait,omitempty"`
	ConfirmPopup    bool         `yaml:"confirmPopup,omitempty"`
	CancelPopup     bool         `yaml:"cancelPopup,omitempty"`
	Select          *Select      `yaml:"select,omitempty"`
	UploadFile      *UploadFile  `yaml:"uploadFile,omitempty"`
	SelectFrame     *SelectFrame `yaml:"selectFrame,omitempty"`
	SelectRootFrame bool         `yaml:"selectRootFrame,omitempty"`
	NextWindow      bool         `yaml:"nextWindow,omitempty"`
	HistoryAction   string       `yaml:"historyAction,omitempy"`
}

Action represents what can be done with web executor

type Click added in v0.0.4

type Click struct {
	Find string `yaml:"find,omitempty"`
	Wait int64  `yaml:"wait"`
}

Click represents informations needed to click on web components

type Executor

type Executor struct {
	Action     Action `json:"action,omitempty" yaml:"action"`
	Screenshot string `json:"screenshot,omitempty" yaml:"screenshot"`
}

Executor struct

func (Executor) Run

func (Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, error)

Run execute TestStep

func (Executor) Setup added in v1.0.0

func (Executor) Setup(ctx context.Context, vars venom.H) (context.Context, error)

func (Executor) TearDown added in v1.0.0

func (Executor) TearDown(ctx context.Context) error

func (Executor) ZeroValueResult added in v0.17.0

func (Executor) ZeroValueResult() interface{}

ZeroValueResult return an empty implementation of this executor result

type Fill

type Fill struct {
	Find string  `yaml:"find,omitempty"`
	Text string  `yaml:"text,omitempty"`
	Key  *string `yaml:"key,omitempty"`
}

Fill represents informations needed to fill input/textarea

type Navigate struct {
	URL   string `yaml:"url,omitempty"`
	Reset bool   `yaml:"reset,omitempty"`
}

Navigate represents informations needed to navigate on defined url

type Result

type Result struct {
	Find        int     `json:"find,omitempty" yaml:"find,omitempty"`
	HTML        string  `json:"html,omitempty" yaml:"html,omitempty"`
	TimeSeconds float64 `json:"timeseconds,omitempty" yaml:"timeseconds,omitempty"`
	Title       string  `json:"title,omitempty" yaml:"title,omitempty"`
	URL         string  `json:"url,omitempty" yaml:"url,omitempty"`
	Text        string  `json:"text,omitempty" yaml:"text,omitempty"`
	Value       string  `json:"value,omitempty" yaml:"value,omitempty"`
}

Result represents a step result

type Select added in v0.28.0

type Select struct {
	Find string `yaml:"find,omitempty"`
	Text string `yaml:"text,omitempty"`
	Wait int64  `yaml:"wait,omitempty"`
}

Select represents informations needed to select an option

type SelectFrame added in v0.28.0

type SelectFrame struct {
	Find string `yaml:"find,omitempty"`
}

SelectFrame represents informations needed to select the frame

type UploadFile added in v0.28.0

type UploadFile struct {
	Find  string   `yaml:"find,omitempty"`
	Files []string `yaml:"files,omitempty"`
	Wait  int64    `yaml:"wait,omitempty"`
}

UploadFile represents informations needed to upload files

type WebContext added in v1.0.0

type WebContext struct {
	Page *agouti.Page
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL