web

package
v1.2.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: Apache-2.0 Imports: 11 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.

Web driver

Web driver allow to manipulate a browser.

To use firefox browser, geckodriver binary must be installed - see here To use chrome browser, chromedriver binary must be installed - see here

Firefox

List of arguments List of preferences

Chrome

List of arguments

Variables

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: chrome): Driver to use, severals values possibles:
    • chrome: Use chrome driver
    • gecko: Use gecko driver (firefox)
  • args: Web driver arguments
  • prefs: Web driver preferences
  • timeout (default: 180): Timeout in seconds
  • debug (default: false): Boolean, enabling/disabling the debug mode of the web driver (Deprecated - use logLevel instead)
  • proxy: Proxy to use to query web site (Format: [server]:[port])
  • headless (default: false): Boolean, enabling/disabling the headless mode of the web driver. Usefull to integrate tool in CI/CD pipeline
  • detach (default: false): Boolean, enabling/disabling the detach mode of the web driver
  • logLevel (default: false): Define log level of client, severals values possibles:
    • ERROR: In this mode, you can see errors
    • WARN: In this mode, you can see warning
    • INFO: In this mode, you can see all methods called
    • DEBUG: In this mode, you can see all interactions between web driver and browser
  • binaryPath: Binary path of browser, if path is not defined, use default path
  • driverPath: Driver path, if path is not defined, use current directory
  • driverPort: Port to run driver, if port is not defined, use driver default port

Action

Action allow to manipulate browser

List of output values available:

  • result.url: URL of the current page
  • result.timeseconds: duration of the action execution
  • result.title: title of the current page
Navigate

Navigate to a specific URL

Input
  • URL: Url to navigate
  • Reset: Reset browser state
Example
  - type: web
    action:
      navigate:
        url: https://www.google.fr
Find

Search an element from a selector

Link for CSS selector tutorial Link for XPATH selector tutorial

Input
  • Selector: Expression to use to identify web element
  • Locator: Locator to use to search element (CSS or XPATH)
Output
  • result.find: return number of object identified
Example
  - type: web
    action:
      find: 
        selector: .gsfi
        locator: CSS
    assertions:
    - result.find ShouldEqual 2

  - type: web
    action:
      find:
        selector: //div[@class='FPdoLc lJ9FBc']/center/input[@value='Recherche Google']
        locator: XPATH
    assertions:
    - result.find ShouldEqual 1
    - result.value ShouldEqual Recherche Google
Click

Click on an element from a selector

Input
  • Find: Element to find (More informations in find section)
  • Wait: Time to wait after click (in seconds)
  • SyncTimeout: Option to enable element synchronization (wait until element appear in page). SyncTimeout allow to define maximum time to wait for synchronization
Example
  - type: web
    action:
      click:
        find:
          selector: button
          locator: CSS
Fill

Fill an element (input or textarea) with a text

Input

Array of structured input:

  • Find: Element to find (More informations in find section)
  • Text: Update element value with text
  • Key: Update element value with key
  • SyncTimeout: Option to enable element synchronization (wait until element appear in page). SyncTimeout allow to define maximum time to wait for synchronization
Example
  - type: web
    action:
      fill:
      - find:
          selector: input
          locator: CSS
        text: userName
Select

Select an option of a web element

Input
  • Find: Element to find (More informations in find section)
  • Text: Option to select
  • Wait: Time to wait after click (in seconds)
  • SyncTimeout: Option to enable element synchronization (wait until element appear in page). SyncTimeout allow to define maximum time to wait for synchronization
Example
  - type: web
    action:
      select:
        find:
          selector: select
          locator: CSS
        text: Option 1
Upload file

Upload file on a web element

Input
  • Find: Element to find (More informations in find section)
  • Files: String array to define files to upload
  • Wait: Time to wait after click (in seconds)
  • SyncTimeout: Option to enable element synchronization (wait until element appear in page). SyncTimeout allow to define maximum time to wait for synchronization
Example
  - type: web
    action:
      uploadFile:
        find:
          selector: input
          locator: CSS
        files: 
        - toUpload.csv
Wait

Wait time An integer value to define number of seconds to wait

Example
  - type: web
    action:
      wait: 1
Select frame

Select a frame presents in the current page

Input
  • Find: Frame to find (More informations in find section)
  • SyncTimeout: Option to enable element synchronization (wait until element appear in page). SyncTimeout allow to define maximum time to wait for synchronization
Example
  - type: web
    action:
      selectFrame:
        find:
          selector: "#iframeResult"
          locator: CSS
Select root frame

Select root frame presents in the current page A boolean value to set to true to select root frame

Example
  - type: web
    action:
      selectRootFrame: true
Next window

Select the next window A boolean value to set to true to select next window

Example
  - type: web
    action:
      nextWindow: true
Back

Back to previous page A boolean value to set to true to back to previous page

Example
  - type: web
    action:
      historyAction: back
    assertions:
    - result.title ShouldStartWith GitHub
    - result.url ShouldEqual https://github.com/
Forward

Foward to next page A boolean value to set to true to forward page

Example
  - type: web
    action:
      historyAction: forward
    assertions:
    - result.title ShouldStartWith GitHub
    - result.url ShouldEqual https://github.com/team
Refresh

Refresh page A boolean value to set to true to refresh page

Example
  - type: web
    action:
      historyAction: refresh
    assertions:
    - result.title ShouldStartWith GitHub
    - result.url ShouldEqual https://github.com/team
Confirm popup

Confirm popup dialog (confirm dialog box and alert dialog box) A boolean value to set to true to confirm popup dialog

Example
  - type: web
    action:
      confirmPopup: true
Cancel popup

Cancel popup dialog A boolean value to set to true to cancel popup dialog

Example
  - type: web
    action:
      cancelPopup: true
Execute javascript

Execute javascript code

Input
  • Command: Javascript code to execute
  • Args: String array to define javascript arguments
Example
  - type: web
    action:
      execute:
        command: "window.editor.setValue(\"<!DOCTYPE html> <html></html>\"); window.editor.save();"

More informations about actions (https://github.com/ovh/venom/tree/master/executors/web/types.go) For an action, you can take screenshot of browser with following command: screenshot: [fileName].png

Example

A global example

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

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            interface{}  `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"`
	Execute         *Execute     `yaml:"execute,omitempy"`
}

Action represents what can be done with web executor

type Click added in v0.0.4

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

Click represents informations needed to click on web components

type Execute added in v1.2.0

type Execute struct {
	Command string   `yaml:"command,omitempty"`
	Args    []string `yaml:"args,omitempty"`
}

Execute represents informations required to execute Javascript

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        interface{} `yaml:"find,omitempty"`
	Text        string      `yaml:"text,omitempty"`
	Key         *string     `yaml:"key,omitempty"`
	SyncTimeout int64       `yaml:"syncTimeout"`
}

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        interface{} `yaml:"find,omitempty"`
	Text        string      `yaml:"text,omitempty"`
	Wait        int64       `yaml:"wait,omitempty"`
	SyncTimeout int64       `yaml:"syncTimeout"`
}

Select represents informations needed to select an option

type SelectFrame added in v0.28.0

type SelectFrame struct {
	Find        interface{} `yaml:"find,omitempty"`
	SyncTimeout int64       `yaml:"syncTimeout"`
}

SelectFrame represents informations needed to select the frame

type UploadFile added in v0.28.0

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

UploadFile represents informations needed to upload files

type WebContext added in v1.0.0

type WebContext struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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