webdriver

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 36 Imported by: 0

README

webdriver Runner

webdriver runner opens a web session to run a various action on web driver or web elements.

Service Id Action Description Request Response
webdriver start start standalone webdriver server ServerStartRequest ServerStartResponse
webdriver stop stop standalone webdriver server ServerStopRequest ServerStopResponse
webdriver open open a new browser with session id for further testing OpenSessionRequest OpenSessionResponse
webdriver close close browser session CloseSessionRequest CloseSessionResponse
webdriver call-driver call a method on web driver, i.e wb.GET(url) WebDriverCallRequest ServiceCallResponse
webdriver call-element call a method on a web element, i.e. we.Click() WebElementCallRequest WebElementCallResponse
webdriver run run set of action on a page RunRequest RunResponse
webdriver capture-start start capturing console+network (Chrome/Edge) CaptureStartRequest CaptureStartResponse
webdriver capture-stop stop capturing console+network CaptureStopRequest CaptureStopResponse
webdriver capture-status get capture counters CaptureStatusRequest CaptureStatusResponse
webdriver capture-clear clear capture buffers CaptureClearRequest CaptureClearResponse
webdriver capture-export export buffered capture data CaptureExportRequest CaptureExportResponse

call-driver and call-element actions's method and parameters are proxied to stand along webdriver server via webdriver client

See webdriver selector for more details on how to use xpath, css, id, name, class, tag, link, partial link, dom, and xpath selectors.

webdriver run request defines sequence of action/commands. In case a selector is not specified, call method's caller is a WebDriver, otherwise WebElement defined by selector. Wait provides ability to wait either some time amount or for certain condition to take place, with regexp to extract data

Run request provide commands expression for easy webdriver interaction:

Command syntax:

  [RESULT_KEY=] [(WEB_ELEMENT_SELECTOR).]METHOD_NAME(PARAMETERS)
  
  i.e:
  (#name).sendKeys('dummy 123')
  (xpath://SELECT[@id='typeId']/option[text()='type1']).click()
  get(http://127.0.0.1:8080/form.html)
  

Time wait

    - command: CurrentURL = CurrentURL()
    exit: $CurrentURL:/dummy/
    sleepTimeMs: 1000
    repeat: 10

Inline pipeline tasks

endly -r=test

@run.yaml

pipeline:
  init:
    action: webdriver:start
  test:
    action: webdriver:run
    commands:
      - get(http://play.golang.org/?simple=1)
      - (#code).clear
      - (#code).sendKeys(package main

          import "fmt"

          func main() {
              fmt.Println("Hello Endly!")
          }
        )
      - (#run).click
      - command: stdout = (.stdout).text
        exit: $stdout.Text:/Endly/
        waitTimeMs: 60000
        repeat: 10
      - close
    expect:
      stdout:
        Text: /Hello Endly!/

  defer:
    action: webdriver:stop

Capture console + network (Chrome/Edge only)

Capture uses ChromeDriver "performance" logs (CDP events) and can optionally fetch response bodies via ChromeDriver CDP endpoints. If sinkURL is provided, events are streamed as JSONL using viant/afs (for file:// it appends by default).

@capture.yaml

Navigation guard for Get(url)

webdriver:run can set navigation options to avoid hanging on pages that never finish loading. On timeout it warns/continues and can optionally autoscroll for a short duration to load lazy content.

Documentation

Index

Constants

View Source
const (
	PathKindUndefined = PathKind(iota)
	PathKindSimple
	PathKindComposite
)
View Source
const (
	//ServiceID represents a ServiceID
	ServiceID = "webdriver"

	//SeleniumServer represents name of selenium server
	SeleniumServer = "selenium-server-standalone"
	//GeckoDriver represents name of gecko driver
	GeckoDriver    = "geckodriver"
	ChromeDriver   = "chromedriver"
	ChromeBrowser  = "chrome"
	FirefoxBrowser = "firefox"
	Selenium       = "webdriver"
)

Variables

This section is empty.

Functions

func IsStaleElementError added in v0.73.1

func IsStaleElementError(err error) bool

func New

func New() endly.Service

New creates a new webdriver service

func NewParser

func NewParser() *parser

NewParser creates a new criteria parser

func Sessions

func Sessions(context *endly.Context) map[string]*Session

Types

type Action

type Action struct {
	Key string //optional result key
	PathKind
	Selector *WebElementSelector
	Calls    []*MethodCall
}

Action represents various calls on web element

func NewAction

func NewAction(key, selector string, method string, params ...interface{}) *Action

NewAction creates a new action

type CaptureClearRequest added in v0.84.0

type CaptureClearRequest struct {
	SessionID string
}

type CaptureClearResponse added in v0.84.0

type CaptureClearResponse struct {
	SessionID string
}

type CaptureExportRequest added in v0.84.0

type CaptureExportRequest struct {
	SessionID      string
	MaxEntries     int
	IncludeConsole *bool
	IncludeNetwork *bool
}

type CaptureExportResponse added in v0.84.0

type CaptureExportResponse struct {
	SessionID string
	Summary   *CaptureSummary
	Console   []*ConsoleEntry
	Network   []*NetworkTransaction
}

type CaptureStartRequest added in v0.84.0

type CaptureStartRequest struct {
	SessionID       string
	SinkURL         string `description:"optional AFS URL for JSONL event sink (file://...)"` // proposal C
	FlushIntervalMs int    `description:"optional sink sync interval in ms (file sinks only)"`
	MaxBodyBytes    int
	Redact          *bool
	RedactHeaders   []string
	EnableConsole   *bool
	EnableNetwork   *bool
	IncludeBodies   *bool
}

type CaptureStartResponse added in v0.84.0

type CaptureStartResponse struct {
	SessionID string
	Enabled   bool
	Warning   string
}

type CaptureState added in v0.84.0

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

func (*CaptureState) Clear added in v0.84.0

func (s *CaptureState) Clear()

func (*CaptureState) CloseSink added in v0.84.0

func (s *CaptureState) CloseSink() error

func (*CaptureState) Drain added in v0.84.0

func (s *CaptureState) Drain(sess *Session)

func (*CaptureState) FlushSink added in v0.84.0

func (s *CaptureState) FlushSink() error

func (*CaptureState) Snapshot added in v0.84.0

func (s *CaptureState) Snapshot(maxEntries int, includeConsole, includeNetwork bool) (console []*ConsoleEntry, network []*NetworkTransaction)

func (*CaptureState) StartSink added in v0.84.0

func (s *CaptureState) StartSink(fs afs.Service, sinkURL string, flushIntervalMs int) error

func (*CaptureState) Summary added in v0.84.0

func (s *CaptureState) Summary() *CaptureSummary

type CaptureStatusRequest added in v0.84.0

type CaptureStatusRequest struct {
	SessionID string
}

type CaptureStatusResponse added in v0.84.0

type CaptureStatusResponse struct {
	SessionID string
	Summary   *CaptureSummary
}

type CaptureStopRequest added in v0.84.0

type CaptureStopRequest struct {
	SessionID string
}

type CaptureStopResponse added in v0.84.0

type CaptureStopResponse struct {
	SessionID string
	Summary   *CaptureSummary
}

type CaptureSummary added in v0.84.0

type CaptureSummary struct {
	StartedAt         time.Time
	RequestsInFlight  int
	RequestsCompleted int
	ConsoleEntries    int
	Errors            []string
}

type CapturedBody added in v0.84.0

type CapturedBody struct {
	Encoding  string
	Data      string
	Truncated bool
}

type CloseSessionRequest

type CloseSessionRequest struct {
	SessionID string
}

CloseSessionRequest represents close session request.

func NewCloseSessionRequestFromURL

func NewCloseSessionRequestFromURL(URL string) (*CloseSessionRequest, error)

NewCloseSessionRequestFromURL creates a new close session request from URL

type CloseSessionResponse

type CloseSessionResponse struct {
	SessionID string
}

CloseSessionResponse represents close session response.

type ConsoleEntry added in v0.84.0

type ConsoleEntry struct {
	Timestamp time.Time
	Level     string
	Message   string
}

type MethodCall

type MethodCall struct {
	Wait
	Method     string
	Parameters []interface{}
}

MethodCall represents selenium call.

type NavigationOptions struct {
	TimeoutMs      int `description:"page load timeout for Get(url); on timeout it warns and continues"`
	AutoScrollMs   int `description:"if > 0, scrolls down after nav timeout to load lazy content"`
	ScrollDelayMs  int `description:"delay between scroll steps"`
	StableWindowMs int `description:"stop autoscroll early if scrollHeight stays unchanged for this long"`
	MaxScrollSteps int `description:"max number of scroll steps during autoscroll"`
	IdleThreshold  int `description:"network idle threshold (inflight requests <= threshold)"`
	IdleWindowMs   int `description:"consider network idle only if threshold holds for this long"`
	IdleMaxWaitMs  int `description:"max time to wait for network idle during stabilization (0 uses AutoScrollMs/TimeoutMs)"`
}

type NetworkTransaction added in v0.84.0

type NetworkTransaction struct {
	RequestID string

	URL    string
	Method string

	RequestHeaders  map[string]any
	RequestBody     *CapturedBody
	ResourceType    string
	Initiator       map[string]any
	StartTimestamp  float64
	EndTimestamp    float64
	DurationMs      int64
	ErrorText       string
	WasCanceled     bool
	EncodedDataSize int64

	Status          int
	StatusText      string
	MimeType        string
	ResponseHeaders map[string]any
	ResponseBody    *CapturedBody
}

type OpenSessionRequest

type OpenSessionRequest struct {
	Browser      string
	Capabilities []string
	Remote       string `description:"webdriver server endpoint"`
	SessionID    string `description:"if specified this SessionID will be used for a sessionID"`
}

OpenSessionRequest represents open session request

func NewOpenSessionRequest

func NewOpenSessionRequest(browser string, remote string) *OpenSessionRequest

NewOpenSessionRequest creates a new open session request

func (*OpenSessionRequest) Init

func (r *OpenSessionRequest) Init() error

Init initializes request

type OpenSessionResponse

type OpenSessionResponse struct {
	SessionID string
}

OpenSessionResponse represents open session response.

type PathKind added in v0.73.0

type PathKind int

type RunRequest

type RunRequest struct {
	SessionID      string
	Browser        string
	RemoteSelenium string             //remote selenium resource
	Navigation     *NavigationOptions `description:"optional Get(url) navigation guard options"`
	Actions        []*Action
	ActionDelaysMs int           `description:"slows down action with specified delay"`
	Commands       []interface{} `` /* 130-byte string literal not displayed */
	Expect         interface{}   `description:"If specified it will validated response as actual"`
}

RunRequest represents group of selenium web elements calls

func NewRunRequest

func NewRunRequest(sessionID, browser string, remote string, actions ...*Action) *RunRequest

NewRunRequest creates a new run request

func NewRunRequestFromURL

func NewRunRequestFromURL(URL string) (*RunRequest, error)

NewRunRequestFromURL creates a new request from URL

func (*RunRequest) Init

func (r *RunRequest) Init() error

func (*RunRequest) IsInput

func (r *RunRequest) IsInput() bool

IsInput returns this request (CLI reporter interface)

func (*RunRequest) Messages

func (r *RunRequest) Messages() []*msg.Message

IsInput returns this request (CLI reporter interface)

func (*RunRequest) Validate

func (r *RunRequest) Validate() error

Validate validates run request.

type RunResponse

type RunResponse struct {
	SessionID    string
	Data         map[string]interface{}
	LookupErrors []string
	Assert       *validator.AssertResponse
}

RunResponse represents selenium call response

func (*RunResponse) IsOutput

func (r *RunResponse) IsOutput() bool

IsOutput returns this response (CLI reporter interface)

func (*RunResponse) Messages

func (r *RunResponse) Messages() []*msg.Message

Messages returns messages

type ServiceCallResponse

type ServiceCallResponse struct {
	Result []interface{}
	Data   data.Map
}

ServiceCallResponse represents selenium call response

type Session

type Session struct {
	SessionID string
	Browser   string
	Pid       int
	Server    string
	Remote    string
	Capture   *CaptureState
	Net       *netTracker

	Capabilities []string
	// contains filtered or unexported fields
}

Session represents a selenium session

func (Session) Close

func (s Session) Close()

func (Session) Driver added in v0.74.0

func (s Session) Driver() selenium.WebDriver

type StartRequest

type StartRequest struct {
	Target       *location.Resource
	Driver       string
	Server       string
	Sdk          string
	Capabilities []string
	Port         int
}

StartRequest represents a selenium server start request

func NewStartRequestFromURL

func NewStartRequestFromURL(URL string) (*StartRequest, error)

NewStartRequestFromURL creates a new start request from URL

func (*StartRequest) Init

func (r *StartRequest) Init() error

func (*StartRequest) Validate

func (r *StartRequest) Validate() error

type StartResponse

type StartResponse struct {
	Pid        int
	ServerPath string
	DriverPath string
	SessionID  string
}

StartResponse represents a selenium server stop request

type StopRequest

type StopRequest struct {
	Target *location.Resource
	Port   int
}

StopRequest represents server stop request

func NewStopRequestFromURL

func NewStopRequestFromURL(URL string) (*StopRequest, error)

NewStopRequestFromURL creates a new start request from URL

func (*StopRequest) Init

func (r *StopRequest) Init() error

type StopResponse

type StopResponse struct {
}

StopResponse represents a selenium stop request

type Wait

type Wait struct {
	WaitTimeMs    int
	ThinkTimeMs   int
	IgnoreTimeout bool
	Exit          string
	// contains filtered or unexported fields
}

type WebDriverCallRequest

type WebDriverCallRequest struct {
	SessionID string
	Key       string
	PathKind  PathKind
	Call      *MethodCall
}

WebDriverCallRequest represents selenium call driver request

type WebElementCallRequest

type WebElementCallRequest struct {
	SessionID string
	Selector  *WebElementSelector
	Call      *MethodCall
	PathKind  PathKind
}

WebElementCallRequest represents a web element call reqesut

type WebElementCallResponse

type WebElementCallResponse struct {
	Result      []interface{}
	LookupError string
	Data        map[string]interface{}
}

WebElementCallResponse represents seleniun web element response

type WebElementSelector

type WebElementSelector struct {
	By    string //selector type
	Value string //selector value
	Key   string //optional result key
}

WebElementSelector represents a web element selector

func NewWebElementSelector

func NewWebElementSelector(by, value string) *WebElementSelector

NewWebElementSelector creates a new instance of web element selector

func (*WebElementSelector) Init

func (s *WebElementSelector) Init() error

Validate checks is selector is valid.

func (*WebElementSelector) Validate

func (s *WebElementSelector) Validate() error

Validate checks is selector is valid.

type WebSelector

type WebSelector string

func (WebSelector) ByAndValue

func (s WebSelector) ByAndValue() (by, value string)

Directories

Path Synopsis
extension

Jump to

Keyboard shortcuts

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