webdriver

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: Apache-2.0 Imports: 18 Imported by: 6

Documentation

Overview

Package webdriver provides a simple and incomplete WebDriver client for use by web test launcher.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorError

func ErrorError(err error) string

ErrorError returns the WebDriver error for err.

func ErrorFromError

func ErrorFromError(err, message string) error

ErrorFromError constructs a WebDriver error from an W3C error string and message.

func ErrorFromStatus

func ErrorFromStatus(status int, message string) error

ErrorFromStatus constructs a WebDriver error from an OSS status code and message.

func ErrorHTTPStatus

func ErrorHTTPStatus(err error) int

ErrorHTTPStatus returns the HTTP status code that is associated with err.

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage returns the WebDriver value for err.

func ErrorStackTrace

func ErrorStackTrace(err error) interface{}

ErrorStackTrace returns the WebDriver value for err.

func ErrorStatus

func ErrorStatus(err error) int

ErrorStatus returns the WebDriver status for err.

func ErrorValue

func ErrorValue(err error) interface{}

ErrorValue returns the WebDriver value for err.

func IsWebDriverError

func IsWebDriverError(err error) bool

IsWebDriverError returns true if err is a WebDriver Error.

func MarshalError

func MarshalError(err error) ([]byte, error)

MarshalError generates the WebDriver JSON wire protocol HTTP response body for err.

Types

type LogEntry

type LogEntry struct {
	Timestamp float64 `json:"timestamp"`
	Level     string  `json:"level"`
	Message   string  `json:"message"`
}

LogEntry is an entry parsed from the logs retrieved from the remote WebDriver.

type Rectangle

type Rectangle struct {
	X      float64 `json:"x"`
	Y      float64 `json:"y"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

Rectangle represents a window's position and size.

type WebDriver

type WebDriver interface {
	healthreporter.HealthReporter
	// ExecuteScript executes script inside the browser's current execution context.
	ExecuteScript(ctx context.Context, script string, args []interface{}, value interface{}) error
	// ExecuteScriptAsync executes script asynchronously inside the browser's current execution context.
	ExecuteScriptAsync(ctx context.Context, script string, args []interface{}, value interface{}) error
	// ExecuteScriptAsyncWithTimeout executes the script asynchronously, but sets the script timeout to timeout before,
	// and attempts to restore it to its previous value after.
	ExecuteScriptAsyncWithTimeout(ctx context.Context, timeout time.Duration, script string, args []interface{}, value interface{}) error
	// Quit closes the WebDriver session.
	Quit(context.Context) error
	// CommandURL builds a fully resolved URL for the specified end-point.
	CommandURL(endpoint ...string) (*url.URL, error)
	// SetScriptTimeout sets the timeout for the callback of an ExecuteScriptAsync call to be called.
	SetScriptTimeout(context.Context, time.Duration) error
	// Logs gets logs of the specified type from the remote end.
	Logs(ctx context.Context, logType string) ([]LogEntry, error)
	// SessionID returns the id for this session.
	SessionID() string
	// Address returns the base address for this sessions (ending with session/<SessionID>)
	Address() *url.URL
	// Capabilities returns the capabilities returned from the remote end when session was created.
	Capabilities() map[string]interface{}
	// Screenshot takes a screenshot of the current browser window.
	Screenshot(context.Context) (image.Image, error)
	// WindowHandles returns a slice of the current window handles.
	WindowHandles(context.Context) ([]string, error)
	// ElementFromID returns a new WebElement object for the given id.
	ElementFromID(string) WebElement
	// ElementFromMap returns a new WebElement from a map representing a JSON object.
	ElementFromMap(map[string]interface{}) (WebElement, error)
	// GetWindowRect returns the current windows size and location.
	GetWindowRect(context.Context) (Rectangle, error)
	// SetWindowRect sets the current window size and location.
	SetWindowRect(context.Context, Rectangle) error
	// SetWindowSize sets the current window size.
	SetWindowSize(ctx context.Context, width, height float64) error
	// SetWindowPosition sest the current window position.
	SetWindowPosition(ctx context.Context, x, y float64) error
	// W3C return true iff connected to a W3C compliant remote end.
	W3C() bool
	// CurrentURL returns the URL that the current browser window is looking at.
	CurrentURL(context.Context) (*url.URL, error)
	// PageSource returns the source of the current browsing context active document.
	PageSource(context.Context) (string, error)
	// NavigateTo navigates the controlled browser to the specified URL.
	NavigateTo(context.Context, *url.URL) error
}

WebDriver provides access to a running WebDriver session

func CreateSession

func CreateSession(ctx context.Context, addr string, attempts int, requestedCaps *capabilities.Capabilities) (WebDriver, error)

CreateSession creates a new WebDriver session with desired capabilities from server at addr and ensures that the browser connection is working. It retries up to attempts - 1 times.

type WebElement

type WebElement interface {
	// ID returns the WebDriver element id.
	ID() string
	// ToMap returns a Map representation of a WebElement suitable for use in other WebDriver commands.
	ToMap() map[string]string
	// ScrollIntoView scrolls a WebElement to the top of the browsers viewport.
	ScrollIntoView(ctx context.Context) error
	// Bounds returns the bounds of the WebElement within the viewport.
	// This will not scroll the element into the viewport first.
	// Will return an error if the element is not in the viewport.
	Bounds(ctx context.Context) (image.Rectangle, error)
}

WebElement provides access to a specific DOM element in a WebDriver session.

Jump to

Keyboard shortcuts

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