Documentation
¶
Overview ¶
Example ¶
This is a Sequence of the same example from https://github.com/tebeka/selenium/blob/master/example_test.go This example shows how to navigate to a http://play.golang.org page, input a short program, run it, and inspect its output.
package main
import (
"fmt"
"os"
"github.com/lexLibrary/sequence"
"github.com/tebeka/selenium"
)
func main() {
// Start a Selenium WebDriver server instance (if one is not already
// running).
const (
// These paths will be different on your system.
seleniumPath = "vendor/selenium-server-standalone-3.4.jar"
geckoDriverPath = "vendor/geckodriver-v0.18.0-linux64"
port = 8080
)
opts := []selenium.ServiceOption{
selenium.StartFrameBuffer(), // Start an X frame buffer for the browser to run in.
selenium.GeckoDriver(geckoDriverPath), // Specify the path to GeckoDriver in order to use Firefox.
selenium.Output(os.Stderr), // Output debug information to STDERR.
}
selenium.SetDebug(true)
service, err := selenium.NewSeleniumService(seleniumPath, port, opts...)
if err != nil {
panic(err) // panic is used only as an example and is not otherwise recommended.
}
defer service.Stop()
// Connect to the WebDriver instance running locally.
caps := selenium.Capabilities{"browserName": "firefox"}
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))
if err != nil {
panic(err)
}
defer wd.Quit()
// once you have a webdriver initiated, then you simply pass it into a new sequence
err = sequence.Start(wd).
Get("http://play.golang.org/?simple=1").
Find("#code").Clear().SendKeys(`
package main
import "fmt"
func main() {
fmt.Println("Hello WebDriver!\n")
}
`).
Find("#run").Click().
Find("#output").
Text().Contains("Hello WebDriver").Eventually().
End()
if err != nil {
panic(err)
}
}
Index ¶
- type Elements
- func (e *Elements) All() *Elements
- func (e *Elements) And() *Sequence
- func (e *Elements) Any() *Elements
- func (e *Elements) Attribute(attribute string) *StringMatch
- func (e *Elements) CSSProperty(property string) *StringMatch
- func (e *Elements) Clear() *Elements
- func (e *Elements) Click() *Elements
- func (e *Elements) Count(count int) *Elements
- func (e *Elements) Disabled() *Elements
- func (e *Elements) Enabled() *Elements
- func (e *Elements) End() error
- func (e *Elements) Eventually() *Elements
- func (e *Elements) Find(selector string) *Elements
- func (e *Elements) FindChildren(selector string) *Elements
- func (e *Elements) Hidden() *Elements
- func (e *Elements) Selected() *Elements
- func (e *Elements) SendKeys(keys string) *Elements
- func (e *Elements) Submit() *Elements
- func (e *Elements) TagName() *StringMatch
- func (e *Elements) Test(testName string, fn func(e selenium.WebElement) error) *Elements
- func (e *Elements) Text() *StringMatch
- func (e *Elements) Unselected() *Elements
- func (e *Elements) Visible() *Elements
- func (e *Elements) Wait(duration time.Duration) *Elements
- type Error
- type Errors
- type Sequence
- func (s *Sequence) Back() *Sequence
- func (s *Sequence) Debug() *Sequence
- func (s *Sequence) Driver() selenium.WebDriver
- func (s *Sequence) End() error
- func (s *Sequence) Eventually() *Sequence
- func (s *Sequence) Find(selector string) *Elements
- func (s *Sequence) Forward() *Sequence
- func (s *Sequence) Get(uri string) *Sequence
- func (s *Sequence) Refresh() *Sequence
- func (s *Sequence) Screenshot(filename string) *Sequence
- func (s *Sequence) Test(testName string, fn func(d selenium.WebDriver) error) *Sequence
- func (s *Sequence) Title() *TitleMatch
- func (s *Sequence) URL() *URLMatch
- func (s *Sequence) Wait(duration time.Duration) *Sequence
- type StringMatch
- type TitleMatch
- type URLMatch
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Elements ¶
type Elements struct {
// contains filtered or unexported fields
}
Elements is a collections of web elements
func (*Elements) All ¶
All means the following tests will pass if they pass only if pass for ALL of the selected elements
func (*Elements) Any ¶
Any means the following tests will pass if they pass for ANY of the selected elements
func (*Elements) Attribute ¶
func (e *Elements) Attribute(attribute string) *StringMatch
Attribute tests if the elements attribute matches
func (*Elements) CSSProperty ¶
func (e *Elements) CSSProperty(property string) *StringMatch
CSSProperty tests if the elements attribute matches
func (*Elements) Count ¶
Count verifies that the number of elements in the selection matches the argument
func (*Elements) Eventually ¶
Eventually will retry the previous test if it returns an error every EventuallyPoll duration until EventualTimeout is reached
func (*Elements) FindChildren ¶
FindChildren returns a new Elements object for all the elements that match the selector
func (*Elements) TagName ¶
func (e *Elements) TagName() *StringMatch
TagName tests if the elements match the given tag name
func (*Elements) Test ¶
Test tests an arbitrary function against all the elements in this sequence if the function returns an error then the test fails
func (*Elements) Unselected ¶
Unselected tests if the elements aren't selected
type Error ¶
type Error struct {
Stage string
Element selenium.WebElement
Err error
}
Error describes an error that occured during the sequence processing.
type Sequence ¶
type Sequence struct {
EventualPoll time.Duration
EventualTimeout time.Duration
// contains filtered or unexported fields
}
Sequence is a helper structs of chaining selecting elements and testing them if any part of the sequence fails the sequence ends and returns the error built to make writing tests easier
func (*Sequence) Debug ¶
Debug will print the current page's title and source For use with debugging issues mostly
func (*Sequence) Eventually ¶
Eventually will retry the previous test if it returns an error every EventuallyPoll duration until EventualTimeout is reached
func (*Sequence) Find ¶
Find returns a selection of one or more elements to apply a set of actions against If .Any or.All are not specified, then it is assumed that the selection will contain a single element and the tests will fail if more than one element is found
func (*Sequence) Screenshot ¶
Screenshot takes a screenshot
func (*Sequence) Title ¶
func (s *Sequence) Title() *TitleMatch
Title checks the match against the page's title
type StringMatch ¶
type StringMatch struct {
// contains filtered or unexported fields
}
StringMatch is for testing the value of strings in elements
func (*StringMatch) Contains ¶
func (s *StringMatch) Contains(match string) *Elements
Contains tests if the string value contains the passed in value
func (*StringMatch) EndsWith ¶
func (s *StringMatch) EndsWith(match string) *Elements
EndsWith tests if the string value end with the passed in value
func (*StringMatch) Equals ¶
func (s *StringMatch) Equals(match string) *Elements
Equals tests if the string value matches the passed in value exactly
func (*StringMatch) Regexp ¶
func (s *StringMatch) Regexp(exp *regexp.Regexp) *Elements
Regexp tests if the string value matches the regular expression
func (*StringMatch) StartsWith ¶
func (s *StringMatch) StartsWith(match string) *Elements
StartsWith tests if the string value starts with the passed in value
type TitleMatch ¶
type TitleMatch struct {
// contains filtered or unexported fields
}
TitleMatch is for testing the value of the title
func (*TitleMatch) Contains ¶
func (t *TitleMatch) Contains(match string) *Sequence
Contains tests if the title contains the passed in value
func (*TitleMatch) EndsWith ¶
func (t *TitleMatch) EndsWith(match string) *Sequence
EndsWith tests if the title ends with the passed in value
func (*TitleMatch) Equals ¶
func (t *TitleMatch) Equals(match string) *Sequence
Equals tests if the title matches the passed in value exactly
func (*TitleMatch) Regexp ¶
func (t *TitleMatch) Regexp(exp *regexp.Regexp) *Sequence
Regexp tests if the title matches the regular expression
func (*TitleMatch) StartsWith ¶
func (t *TitleMatch) StartsWith(match string) *Sequence
StartsWith tests if the title starts with the passed in value
type URLMatch ¶
type URLMatch struct {
// contains filtered or unexported fields
}
URLMatch is for testing the value of the page's URL
func (*URLMatch) Fragment ¶
Fragment tests if the page's url fragment (#) matches the passed in value
func (*URLMatch) QueryValue ¶
QueryValue tests if the page's url contains the url query matches the value