Documentation ¶
Overview ¶
Package core is DEPRECATED and will not receive future updates. Please use "github.com/sclevine/agouti" instead.
Index ¶
- func Cookie(name string, value string) agouti.Cookie
- type Capabilities
- type Log
- type MultiSelection
- type Page
- type Selectable
- type Selection
- type WebDriver
- func Chrome() (WebDriver, error)
- func ChromeDriver() WebDriver
- func CustomWebDriver(url string, command []string, timeout ...time.Duration) WebDriver
- func NewWebDriver(url string, command []string, timeout ...time.Duration) WebDriver
- func PhantomJS() (WebDriver, error)
- func Selenium() (WebDriver, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Capabilities ¶
type Capabilities interface { // Browser sets the desired browser name - {chrome|firefox|safari|iphone|...}. Browser(browser string) Capabilities // Version sets the desired browser version (ex. "3.6"). Version(version string) Capabilities // Platform sets the desired browser platform - {WINDOWS|XP|VISTA|MAC|LINUX|UNIX}. Platform(platform string) Capabilities // With enables the provided feature (ex. "handlesAlerts"). With(feature string) Capabilities // Without disables the provided feature (ex. "javascriptEnabled"). Without(feature string) Capabilities // Custom sets a custom desired capability. Custom(key string, value interface{}) Capabilities // JSON returns a JSON string representing the desired capabilities. JSON() (string, error) }
A Capabilities instance defines the desired capabilities the WebDriver should use to configure a Page.
For example, to open a Firefox page with JavaScript disabled:
driver.Page(Use().Browser("firefox").Without("javascriptEnabled"))
See: https://code.google.com/p/selenium/wiki/DesiredCapabilities
func Use ¶
func Use() Capabilities
Use returns a Capabilities instance that can be passed to a page. All methods called on this instance will modify the original instance.
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 interface { // All Selection methods are valid MultiSelection methods. Selection // At finds the element at the provided index. At(index int) 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.
type Page ¶
type Page interface { // Selections are created using the Selectable page methods (ex. Find()). Selectable // Destroy closes the session and any open browsers processes. Destroy() error Navigate(url string) error // SetCookie sets a cookie on the page. SetCookie(cookie agouti.Cookie) error // DeleteCookie deletes a cookie on the page by name. DeleteCookie(name string) error // ClearCookies deletes all cookies on the page. ClearCookies() error // URL returns the current page URL. URL() (string, error) // Size sets the current page size in pixels. Size(width, height int) error // Screenshot takes a screenshot and saves it to the provided filename. Screenshot(filename string) error // Title returns the page title. Title() (string, error) // HTML returns the current contents of the DOM for the entire page. HTML() (string, error) // 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 RunScript(body string, arguments map[string]interface{}, result interface{}) error // PopupText returns the current alert, confirm, or prompt popup text. PopupText() (string, error) // EnterPopupText enters text into an open prompt popup. EnterPopupText(text string) error // ConfirmPopup confirms an alert, confirm, or prompt popup. ConfirmPopup() error // CancelPopup cancels an alert, confirm, or prompt popup. CancelPopup() error // Forward navigates forward in history. Forward() error // Back navigates backwards in history. Back() error // Refresh refreshes the page. Refresh() error // 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. SwitchToParentFrame() error // 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. SwitchToRootFrame() error // SwitchToWindow switches to the first available window with the provided name // (JavaScript `window.name` attribute). SwitchToWindow(name string) error // NextWindow switches to the next available window. NextWindow() error // CloseWindow closes the active window. CloseWindow() error // WindowCount returns the number of available windows. WindowCount() (int, error) // ReadLogs returns log messages of the provided log type. For example, // page.ReadLogs("browser") returns browser console logs, such as JavaScript logs // and errors. If the all argument is provided as true, all logs since the session // was created are returned. Otherwise, only logs since the last call to ReadLogs // are returned. Valid log types may be obtained using the LogTypes method. ReadLogs(logType string, all ...bool) ([]Log, error) // LogTypes returns all of the valid log types that may be used with a LogReader. LogTypes() ([]string, error) }
A Page represents an open browser session. Pages may be created using the WebDriver#Page() method or by calling the Connect or SauceLabs functions.
func Connect ¶
func Connect(desired Capabilities, url string) (Page, error)
Connect opens a Page using the provided WebDriver URL.
DEPRECATED: Use NewPage instead.
type Selectable ¶
type Selectable interface { // Find finds exactly one element by CSS selector. Find(selector string) Selection // FindByXPath finds exactly one element by XPath selector. FindByXPath(selector string) Selection // FindByLink finds exactly one anchor element by its text content. FindByLink(text string) Selection // FindByLabel finds exactly one element by associated label text. FindByLabel(text string) Selection // FindByButton finds exactly one button element with the provided text. // Supports <button>, <input type="button">, and <input type="submit">. FindByButton(text string) Selection // First finds the first element by CSS selector. First(selector string) Selection // FirstByXPath finds the first element by XPath selector. FirstByXPath(selector string) Selection // FirstByLink finds the first anchor element by its text content. FirstByLink(text string) Selection // FirstByLabel finds the first element by associated label text. FirstByLabel(text string) Selection // FirstByButton finds the first button element with the provided text. // Supports <button>, <input type="button">, and <input type="submit">. FirstByButton(text string) Selection // All finds zero or more elements by CSS selector. All(selector string) MultiSelection // AllByXPath finds zero or more elements by XPath selector. AllByXPath(selector string) MultiSelection // AllByLink finds zero or more anchor elements by their text content. AllByLink(text string) MultiSelection // AllByLabel finds zero or more elements by associated label text. AllByLabel(text string) MultiSelection // AllByButton finds zero or more button elements with the provided text. // Supports <button>, <input type="button">, and <input type="submit">. AllByButton(text string) MultiSelection }
Selectable methods 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.
type Selection ¶
type Selection interface { // Selections have Find*(), All*(), and First*() methods that return new sub-Selections Selectable // String returns a string representation of the selection, ex. // CSS: .some-class | XPath: //table [3] | Link "click me" [single] String() string // Count returns the number of elements that the selection refers to. Count() (int, error) // EqualsElement returns whether or not two selections of exactly // one element each refer to the same element. EqualsElement(comparable interface{}) (bool, error) // 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. SwitchToFrame() error // Click clicks on all of the elements that the selection refers to. Click() error // DoubleClick double-clicks on all of the elements that the selection refers to. DoubleClick() error // Fill fills all of the fields the selection refers to with the provided text. Fill(text string) error // Check checks all of the unchecked checkboxes that the selection refers to. Check() error // Uncheck unchecks all of the checked checkboxes that the selection refers to. Uncheck() error // Select, when called on some number of <select> elements, will select all // <option> elements under those <select> elements that match the provided text. Select(text string) error // Submit submits all selected forms. The selection may refer to a form itself // or any input element contained within a form. Submit() error // Text returns the entirety of the text content for exactly one element. Text() (string, error) // Attribute returns an attribute value for exactly one element. Attribute(attribute string) (string, error) // CSS returns a CSS style property value for exactly one element. CSS(property string) (string, error) // Selected returns true if all of the elements that the selection refers to // are selected. Selected() (bool, error) // Visible returns true if all of the elements that the selection refers to // are visible. Visible() (bool, error) // Enabled returns true if all of the elements that the selection refers to // are enabled. Enabled() (bool, error) // Active returns true if the single element that the selection refers to is active. Active() (bool, error) }
Selection instances refer to a selection of elements. Every Selection method is a valid MultiSelection method.
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.
type WebDriver ¶
type WebDriver interface { // Start launches the WebDriver process. Start() error // Stop ends all remaining sessions and stops the WebDriver process. Stop() error // Page returns a new WebDriver session. The optional config argument // configures the returned page. For instance: // driver.Page(Use().Without("javascriptEnabled")) // For Selenium, this argument must include a browser. For instance: // seleniumDriver.Page(Use().Browser("safari")) Page(config ...Capabilities) (Page, error) }
WebDriver controls a Selenium, PhantomJS, or ChromeDriver process.
func Chrome ¶
Chrome returns an instance of a ChromeDriver WebDriver.
DEPRECATED: Use ChromeDriver instead.
func ChromeDriver ¶
func ChromeDriver() WebDriver
ChromeDriver returns an instance of a ChromeDriver WebDriver.
func CustomWebDriver ¶
CustomWebDriver returns an instance of a WebDriver specified by a templated URL and command.
DEPRECATED: Use NewWebDriver instead.
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}}"} core.NewWebDriver("http://{{.Address}}/wd/hub", command)