Documentation ¶
Overview ¶
Package agouti is a universal WebDriver client for Go. It extends the agouti/api package to provide a feature-rich interface for controlling a Web Browser.
Index ¶
- type Capabilities
- func (c Capabilities) Browser(name string) Capabilities
- func (c Capabilities) JSON() (string, error)
- func (c Capabilities) Platform(platform string) Capabilities
- func (c Capabilities) Version(version string) Capabilities
- func (c Capabilities) With(feature string) Capabilities
- func (c Capabilities) Without(feature string) Capabilities
- type Cookie
- type Log
- type MultiSelection
- func (s *MultiSelection) All(selector string) *MultiSelection
- func (s *MultiSelection) AllByButton(text string) *MultiSelection
- func (s *MultiSelection) AllByLabel(text string) *MultiSelection
- func (s *MultiSelection) AllByLink(text string) *MultiSelection
- func (s *MultiSelection) AllByXPath(selector string) *MultiSelection
- func (s *MultiSelection) At(index int) *Selection
- func (s *MultiSelection) Find(selector string) *Selection
- func (s *MultiSelection) FindByButton(text string) *Selection
- func (s *MultiSelection) FindByLabel(text string) *Selection
- func (s *MultiSelection) FindByLink(text string) *Selection
- func (s *MultiSelection) FindByXPath(selector string) *Selection
- func (s *MultiSelection) First(selector string) *Selection
- func (s *MultiSelection) FirstByButton(text string) *Selection
- func (s *MultiSelection) FirstByLabel(text string) *Selection
- func (s *MultiSelection) FirstByLink(text string) *Selection
- func (s *MultiSelection) FirstByXPath(selector string) *Selection
- type Option
- type Page
- func (s *Page) All(selector string) *MultiSelection
- func (s *Page) AllByButton(text string) *MultiSelection
- func (s *Page) AllByLabel(text string) *MultiSelection
- func (s *Page) AllByLink(text string) *MultiSelection
- func (s *Page) AllByXPath(selector string) *MultiSelection
- func (p *Page) Back() error
- func (p *Page) CancelPopup() error
- func (p *Page) ClearCookies() error
- func (p *Page) CloseWindow() error
- func (p *Page) ConfirmPopup() error
- func (p *Page) DeleteCookie(name string) error
- func (p *Page) Destroy() error
- func (p *Page) EnterPopupText(text string) error
- func (s *Page) Find(selector string) *Selection
- func (s *Page) FindByButton(text string) *Selection
- func (s *Page) FindByLabel(text string) *Selection
- func (s *Page) FindByLink(text string) *Selection
- func (s *Page) FindByXPath(selector string) *Selection
- func (s *Page) First(selector string) *Selection
- func (s *Page) FirstByButton(text string) *Selection
- func (s *Page) FirstByLabel(text string) *Selection
- func (s *Page) FirstByLink(text string) *Selection
- func (s *Page) FirstByXPath(selector string) *Selection
- func (p *Page) Forward() error
- func (p *Page) HTML() (string, error)
- func (p *Page) LogTypes() ([]string, error)
- func (p *Page) Navigate(url string) error
- func (p *Page) NextWindow() error
- func (p *Page) PopupText() (string, error)
- func (p *Page) ReadAllLogs(logType string) ([]Log, error)
- func (p *Page) ReadNewLogs(logType string) ([]Log, error)
- func (p *Page) Refresh() error
- func (p *Page) RunScript(body string, arguments map[string]interface{}, result interface{}) error
- func (p *Page) Screenshot(filename string) error
- func (p *Page) SetCookie(cookie Cookie) error
- func (p *Page) Size(width, height int) error
- func (p *Page) SwitchToParentFrame() error
- func (p *Page) SwitchToRootFrame() error
- func (p *Page) SwitchToWindow(name string) error
- func (p *Page) Title() (string, error)
- func (p *Page) URL() (string, error)
- func (p *Page) WindowCount() (int, error)
- type Selection
- func (s *Selection) Active() (bool, error)
- func (s *Selection) All(selector string) *MultiSelection
- func (s *Selection) AllByButton(text string) *MultiSelection
- func (s *Selection) AllByLabel(text string) *MultiSelection
- func (s *Selection) AllByLink(text string) *MultiSelection
- func (s *Selection) AllByXPath(selector string) *MultiSelection
- func (s *Selection) Attribute(attribute string) (string, error)
- func (s *Selection) CSS(property string) (string, error)
- func (s *Selection) Check() error
- func (s *Selection) Click() error
- func (s *Selection) Count() (int, error)
- func (s *Selection) DoubleClick() error
- func (s *Selection) Enabled() (bool, error)
- func (s *Selection) EqualsElement(other interface{}) (bool, error)
- func (s *Selection) Fill(text string) error
- func (s *Selection) Find(selector string) *Selection
- func (s *Selection) FindByButton(text string) *Selection
- func (s *Selection) FindByLabel(text string) *Selection
- func (s *Selection) FindByLink(text string) *Selection
- func (s *Selection) FindByXPath(selector string) *Selection
- func (s *Selection) First(selector string) *Selection
- func (s *Selection) FirstByButton(text string) *Selection
- func (s *Selection) FirstByLabel(text string) *Selection
- func (s *Selection) FirstByLink(text string) *Selection
- func (s *Selection) FirstByXPath(selector string) *Selection
- func (s *Selection) Select(text string) error
- func (s *Selection) Selected() (bool, error)
- func (s *Selection) String() string
- func (s *Selection) Submit() error
- func (s *Selection) SwitchToFrame() error
- func (s *Selection) Text() (string, error)
- func (s *Selection) Uncheck() error
- func (s *Selection) Visible() (bool, error)
- type WebDriver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Capabilities ¶
type Capabilities map[string]interface{}
A Capabilities instance defines the desired capabilities the WebDriver should use to configure a Page.
For example, to open Firefox with JavaScript disabled:
capabilities := agouti.NewCapabilities().Browser("firefox").Without("javascriptEnabled") driver.NewPage(agouti.Desired(capabilities))
See: https://code.google.com/p/selenium/wiki/DesiredCapabilities
All methods called on this instance will modify the original instance.
func NewCapabilities ¶
func NewCapabilities(features ...string) Capabilities
NewCapabilities returns a Capabilities instance with any provided features enabled.
func (Capabilities) Browser ¶
func (c Capabilities) Browser(name string) Capabilities
Browser sets the desired browser name. Possible values:
{android|chrome|firefox|htmlunit|internet explorer|iPhone|iPad|opera|safari}
func (Capabilities) JSON ¶
func (c Capabilities) JSON() (string, error)
JSON returns a JSON string representing the desired capabilities.
func (Capabilities) Platform ¶
func (c Capabilities) Platform(platform string) Capabilities
Platform sets the desired browser platform. Possible values:
{WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANDROID|ANY}.
func (Capabilities) Version ¶
func (c Capabilities) Version(version string) Capabilities
Version sets the desired browser version (ex. "3.6").
func (Capabilities) With ¶
func (c Capabilities) With(feature string) Capabilities
With enables the provided feature (ex. "trustAllSSLCertificates").
func (Capabilities) Without ¶
func (c Capabilities) Without(feature string) Capabilities
Without disables the provided feature (ex. "javascriptEnabled").
type Cookie ¶
type Cookie map[string]interface{}
Cookie defines a cookie for use with *Page#SetCookie()
func NewCookie ¶
NewCookie returns a Cookie instance with the provided name and value. All methods called on this instance will modify the original instance.
func (Cookie) SetHTTPOnly ¶
SetHTTPOnly marks the cookie as HTTP-only
type Log ¶
type Log struct { // Message is the text of the log message. Message string // Location is the code location of the log message, if present Location string // Level is the log level ("DEBUG", "INFO", "WARNING", or "SEVERE"). Level string // Time is the time the message was logged. Time time.Time }
A Log represents a single log message
type MultiSelection ¶
type MultiSelection struct { // All Selection methods are valid MultiSelection methods. Selection }
A MultiSelection is a Selection that may be indexed using the At() method.
A Selection returned by At() may still refer to multiple elements if any parent of the MultiSelection refers to multiple elements.
Examples:
selection.All("section").All("form").At(1).Submit()
Submits the second form in each section.
selection.All("div").Find("h1").Click()
Clicks one h1 in each div, failing if any div does not contain exactly one h1.
func (*MultiSelection) All ¶
func (s *MultiSelection) All(selector string) *MultiSelection
All finds zero or more elements by CSS selector.
func (*MultiSelection) AllByButton ¶
func (s *MultiSelection) AllByButton(text string) *MultiSelection
AllByButton finds zero or more button elements with the provided text. Supports <button>, <input type="button">, and <input type="submit">.
func (*MultiSelection) AllByLabel ¶
func (s *MultiSelection) AllByLabel(text string) *MultiSelection
AllByLabel finds zero or more elements by associated label text.
func (*MultiSelection) AllByLink ¶
func (s *MultiSelection) AllByLink(text string) *MultiSelection
AllByLink finds zero or more anchor elements by their text content.
func (*MultiSelection) AllByXPath ¶
func (s *MultiSelection) AllByXPath(selector string) *MultiSelection
AllByXPath finds zero or more elements by XPath selector.
func (*MultiSelection) At ¶
func (s *MultiSelection) At(index int) *Selection
At finds an element at the provided index.
func (*MultiSelection) FindByButton ¶
FindByButton finds exactly one button element with the provided text. Supports <button>, <input type="button">, and <input type="submit">.
func (*MultiSelection) FindByLabel ¶
FindByLabel finds exactly one element by associated label text.
func (*MultiSelection) FindByLink ¶
FindByLink finds exactly one anchor element by its text content.
func (*MultiSelection) FindByXPath ¶
FindByXPath finds exactly one element by XPath selector.
func (*MultiSelection) FirstByButton ¶
FirstByButton finds the first button element with the provided text. Supports <button>, <input type="button">, and <input type="submit">.
func (*MultiSelection) FirstByLabel ¶
FirstByLabel finds the first element by associated label text.
func (*MultiSelection) FirstByLink ¶
FirstByLink finds the first anchor element by its text content.
func (*MultiSelection) FirstByXPath ¶
FirstByXPath finds the first element by XPath selector.
type Option ¶
type Option func(*config)
func Desired ¶
func Desired(capabilities Capabilities) Option
Desired provides an option for specifying desired WebDriver capabilities.
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
A Page represents an open browser session. Pages may be created using the *WebDriver#Page() method or by calling the NewPage or SauceLabs functions.
func SauceLabs ¶
SauceLabs opens a Sauce Labs session and returns a *Page. Does not support Sauce Connect.
func (*Page) All ¶
func (s *Page) All(selector string) *MultiSelection
All finds zero or more elements by CSS selector.
func (*Page) AllByButton ¶
func (s *Page) AllByButton(text string) *MultiSelection
AllByButton finds zero or more button elements with the provided text. Supports <button>, <input type="button">, and <input type="submit">.
func (*Page) AllByLabel ¶
func (s *Page) AllByLabel(text string) *MultiSelection
AllByLabel finds zero or more elements by associated label text.
func (*Page) AllByLink ¶
func (s *Page) AllByLink(text string) *MultiSelection
AllByLink finds zero or more anchor elements by their text content.
func (*Page) AllByXPath ¶
func (s *Page) AllByXPath(selector string) *MultiSelection
AllByXPath finds zero or more elements by XPath selector.
func (*Page) CancelPopup ¶
CancelPopup cancels an alert, confirm, or prompt popup.
func (*Page) ClearCookies ¶
ClearCookies deletes all cookies on the page.
func (*Page) ConfirmPopup ¶
ConfirmPopup confirms an alert, confirm, or prompt popup.
func (*Page) DeleteCookie ¶
DeleteCookie deletes a cookie on the page by name.
func (*Page) EnterPopupText ¶
EnterPopupText enters text into an open prompt popup.
func (*Page) FindByButton ¶
FindByButton finds exactly one button element with the provided text. Supports <button>, <input type="button">, and <input type="submit">.
func (*Page) FindByLabel ¶
FindByLabel finds exactly one element by associated label text.
func (*Page) FindByLink ¶
FindByLink finds exactly one anchor element by its text content.
func (*Page) FindByXPath ¶
FindByXPath finds exactly one element by XPath selector.
func (*Page) FirstByButton ¶
FirstByButton finds the first button element with the provided text. Supports <button>, <input type="button">, and <input type="submit">.
func (*Page) FirstByLabel ¶
FirstByLabel finds the first element by associated label text.
func (*Page) FirstByLink ¶
FirstByLink finds the first anchor element by its text content.
func (*Page) FirstByXPath ¶
FirstByXPath finds the first element by XPath selector.
func (*Page) LogTypes ¶
LogTypes returns all of the valid log types that may be used with a LogReader.
func (*Page) NextWindow ¶
NextWindow switches to the next available window.
func (*Page) ReadAllLogs ¶
ReadAllLogs returns all log messages of the provided log type. For example, page.ReadLogs("browser") returns browser console logs, such as JavaScript logs and errors. All logs since the session was created are returned. Valid log types may be obtained using the LogTypes method.
func (*Page) ReadNewLogs ¶
ReadNewLogs returns new log messages of the provided log type. For example, page.ReadNewLogs("browser") returns browser console logs, such as JavaScript logs and errors. Only logs since the last call to ReadNewLogs are returned. Valid log types may be obtained using the LogTypes method.
func (*Page) RunScript ¶
RunScript runs the JavaScript provided in the body. Any keys present in the arguments map will be available as variables in the body. Values provided in arguments are converted into javascript objects. If the body returns a value, it will be unmarshalled into the result argument. Simple example:
var number int page.RunScript("return test;", map[string]interface{}{"test": 100}, &number) fmt.Println(number)
-> 100
func (*Page) Screenshot ¶
Screenshot takes a screenshot and saves it to the provided filename.
func (*Page) SwitchToParentFrame ¶
SwitchToParentFrame focuses on the immediate parent frame of a frame selected by Selection#Frame. After switching, all new and existing selections will refer to the parent frame. All further Page methods will apply to this frame as well.
This method is not supported by PhantomJS. Please use SwitchToRootFrame instead.
func (*Page) SwitchToRootFrame ¶
SwitchToRootFrame focuses on the original, default page frame before any calls to Selection#Frame were made. After switching, all new and existing selections will refer to the root frame. All further Page methods will apply to this frame as well.
func (*Page) SwitchToWindow ¶
SwitchToWindow switches to the first available window with the provided name (JavaScript `window.name` attribute).
func (*Page) WindowCount ¶
WindowCount returns the number of available windows.
type Selection ¶
type Selection struct {
// contains filtered or unexported fields
}
Selection instances refer to a selection of elements. All Selection methods are also MultiSelection methods.
Methods that take selectors apply their selectors to each element in the selection they are called on. If the selection they are called on refers to multiple elements, the resulting selection will refer to at least that many elements.
Examples:
selection.Find("table").All("tr").At(2).First("td input[type=checkbox]").Check()
Checks the first checkbox in the third row of the only table.
selection.Find("table").All("tr").Find("td").All("input[type=checkbox]").Check()
Checks all checkboxes in the first-and-only cell of each row in the only table.
func (*Selection) Active ¶
Active returns true if the single element that the selection refers to is active.
func (*Selection) All ¶
func (s *Selection) All(selector string) *MultiSelection
All finds zero or more elements by CSS selector.
func (*Selection) AllByButton ¶
func (s *Selection) AllByButton(text string) *MultiSelection
AllByButton finds zero or more button elements with the provided text. Supports <button>, <input type="button">, and <input type="submit">.
func (*Selection) AllByLabel ¶
func (s *Selection) AllByLabel(text string) *MultiSelection
AllByLabel finds zero or more elements by associated label text.
func (*Selection) AllByLink ¶
func (s *Selection) AllByLink(text string) *MultiSelection
AllByLink finds zero or more anchor elements by their text content.
func (*Selection) AllByXPath ¶
func (s *Selection) AllByXPath(selector string) *MultiSelection
AllByXPath finds zero or more elements by XPath selector.
func (*Selection) Check ¶
Check checks all of the unchecked checkboxes that the selection refers to.
func (*Selection) DoubleClick ¶
DoubleClick double-clicks on all of the elements that the selection refers to.
func (*Selection) Enabled ¶
Enabled returns true if all of the elements that the selection refers to are enabled.
func (*Selection) EqualsElement ¶
EqualsElement returns whether or not two selections of exactly one element each refer to the same element.
func (*Selection) Fill ¶
Fill fills all of the fields the selection refers to with the provided text.
func (*Selection) FindByButton ¶
FindByButton finds exactly one button element with the provided text. Supports <button>, <input type="button">, and <input type="submit">.
func (*Selection) FindByLabel ¶
FindByLabel finds exactly one element by associated label text.
func (*Selection) FindByLink ¶
FindByLink finds exactly one anchor element by its text content.
func (*Selection) FindByXPath ¶
FindByXPath finds exactly one element by XPath selector.
func (*Selection) FirstByButton ¶
FirstByButton finds the first button element with the provided text. Supports <button>, <input type="button">, and <input type="submit">.
func (*Selection) FirstByLabel ¶
FirstByLabel finds the first element by associated label text.
func (*Selection) FirstByLink ¶
FirstByLink finds the first anchor element by its text content.
func (*Selection) FirstByXPath ¶
FirstByXPath finds the first element by XPath selector.
func (*Selection) Select ¶
Select, when called on some number of <select> elements, will select all <option> elements under those <select> elements that match the provided text.
func (*Selection) Selected ¶
Selected returns true if all of the elements that the selection refers to are selected.
func (*Selection) String ¶
String returns a string representation of the selection, ex.
CSS: .some-class | XPath: //table [3] | Link "click me" [single]
func (*Selection) Submit ¶
Submit submits all selected forms. The selection may refer to a form itself or any input element contained within a form.
func (*Selection) SwitchToFrame ¶
SwitchToFrame focuses on the frame specified by the selection. All new and existing selections will refer to the new frame. All further Page methods will apply to this frame as well.
type WebDriver ¶
A WebDriver controls a Selenium, PhantomJS, or ChromeDriver process. This struct embeds api.WebDriver, which provides Start and Stop methods for starting and stopping the process.
func ChromeDriver ¶
func ChromeDriver() *WebDriver
ChromeDriver returns an instance of a ChromeDriver WebDriver.
func NewWebDriver ¶
NewWebDriver returns an instance of a WebDriver specified by a templated URL and command. The URL should be the location of the WebDriver Wire Protocol web service brought up by the command. The command should be provided as a list of arguments (which are each templated). The optional timeout specifies how long to wait for the web service to become available. Default timeout is 5 seconds.
Valid template parameters are:
{{.Host}} - local address to bind to (usually 127.0.0.1) {{.Port}} - arbitrary free port on the local address {{.Address}} - {{.Host}}:{{.Port}}
Selenium JAR example:
command := []string{"java", "-jar", "selenium-server.jar", "-port", "{{.Port}}"} agouti.NewWebDriver("http://{{.Address}}/wd/hub", command)
func PhantomJS ¶
func PhantomJS() *WebDriver
PhantomJS returns an instance of a PhantomJS WebDriver. The return error is deprecated and will always be nil.
func Selenium ¶
func Selenium() *WebDriver
Selenium returns an instance of a Selenium WebDriver. The return error is deprecated and will always be nil.
func (*WebDriver) NewPage ¶
NewPage returns a *Page that corresponds to a new WebDriver session. Any provided options configure the page. For instance:
driver.NewPage(agouti.Desired(agouti.NewCapabilities().Without("javascriptEnabled")))
For Selenium, this argument must include a browser. For instance:
seleniumDriver.NewPage(agouti.Desired(agouti.NewCapabilities().Browser("safari")))
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package api provides a generic, low-level WebDriver API client for Go.
|
Package api provides a generic, low-level WebDriver API client for Go. |
Package core is DEPRECATED and will not receive future updates.
|
Package core is DEPRECATED and will not receive future updates. |
Package dsl uses Ginkgo to implement a Capybara-like DSL for writing acceptance tests.
|
Package dsl uses Ginkgo to implement a Capybara-like DSL for writing acceptance tests. |
internal
|
|
Package matchers provides a set of Gomega-compatible matchers for use with the agouti package.
|
Package matchers provides a set of Gomega-compatible matchers for use with the agouti package. |