Documentation ¶
Overview ¶
Biloba builds on top of chromedp to bring stable, performant, automated browser testing to Ginkgo. It embraces three principles:
- Performance via parallelization
- Stability via pragmatism
- Conciseness via Ginkgo and Gomega
The godoc documentation you are reading now is meant to be a sparse reference. To build a mental model for how to use Biloba please peruse the documentation.
Index ¶
- Constants
- func BilobaConfigDisableFailureScreenshots() func(*Biloba)
- func BilobaConfigDisableProgressReportScreenshots() func(*Biloba)
- func BilobaConfigEnableDebugLogging() func(*Biloba)
- func BilobaConfigFailureScreenshotsSize(width, height int) func(*Biloba)
- func BilobaConfigProgressReportScreenshotSize(width, height int) func(*Biloba)
- func BilobaConfigWithChromeConnection(cc ChromeConnection) func(*Biloba)
- func StartingWindowSize(x int, y int) chromedp.ExecAllocatorOption
- type Biloba
- func (b *Biloba) AllCompleteDownloads() Downloads
- func (b *Biloba) AllDownloads() Downloads
- func (b *Biloba) AllSpawnedTabs() Tabs
- func (b *Biloba) AllTabs() Tabs
- func (b *Biloba) BeEnabled() types.GomegaMatcher
- func (b *Biloba) BeVisible() types.GomegaMatcher
- func (b *Biloba) BrowserContextID() cdp.BrowserContextID
- func (b *Biloba) CaptureImgcatScreenshot() string
- func (b *Biloba) CaptureScreenshot() []byte
- func (b *Biloba) Click(args ...any) types.GomegaMatcher
- func (b *Biloba) ClickEach(selector any)
- func (b *Biloba) Close() error
- func (b *Biloba) Count(selector any) int
- func (b *Biloba) Dialogs() Dialogs
- func (b *Biloba) DownloadWithContent(content any) DownloadFilter
- func (b *Biloba) DownloadWithFilename(filename any) DownloadFilter
- func (b *Biloba) DownloadWithURL(url any) DownloadFilter
- func (b *Biloba) EachHaveInnerText(args ...any) types.GomegaMatcher
- func (b *Biloba) EachHaveProperty(property string, expected ...any) types.GomegaMatcher
- func (b *Biloba) EvaluateTo(expected any) types.GomegaMatcher
- func (b *Biloba) Exist() types.GomegaMatcher
- func (b *Biloba) GetProperties(selector any, properties ...string) Properties
- func (b *Biloba) GetPropertiesForEach(selector any, properties ...string) SliceOfProperties
- func (b *Biloba) GetProperty(selector any, property string) any
- func (b *Biloba) GetPropertyForEach(selector any, property string) []any
- func (b *Biloba) GetValue(selector any) any
- func (b *Biloba) GomegaString() string
- func (b *Biloba) HandleAlertDialogs() *DialogHandler
- func (b *Biloba) HandleBeforeunloadDialogs() *DialogHandler
- func (b *Biloba) HandleConfirmDialogs() *DialogHandler
- func (b *Biloba) HandlePromptDialogs() *DialogHandler
- func (b *Biloba) HasElement(selector any) bool
- func (b *Biloba) HaveClass(expected string) types.GomegaMatcher
- func (b *Biloba) HaveCompleteDownload(f DownloadFilter) types.GomegaMatcher
- func (b *Biloba) HaveCount(expected any) types.GomegaMatcher
- func (b *Biloba) HaveInnerText(expected any) types.GomegaMatcher
- func (b *Biloba) HaveProperty(property string, expected ...any) types.GomegaMatcher
- func (b *Biloba) HaveSpawnedTab(f TabFilter) types.GomegaMatcher
- func (b *Biloba) HaveTab(f TabFilter) types.GomegaMatcher
- func (b *Biloba) HaveValue(expected any) types.GomegaMatcher
- func (b *Biloba) InnerText(selector any) string
- func (b *Biloba) InnerTextForEach(selector any) []string
- func (b *Biloba) InvokeOn(selector string, methodName string, args ...any) any
- func (b *Biloba) InvokeOnEach(selector string, methodName string, args ...any) []any
- func (b *Biloba) InvokeWith(selector string, callableScript string, args ...any) any
- func (b *Biloba) InvokeWithEach(selector string, callableScript string, args ...any) []any
- func (b *Biloba) JSFunc(f string) JSFunc
- func (b *Biloba) JSVar(v string) JSVar
- func (b *Biloba) Location() string
- func (b *Biloba) Navigate(url string) *Biloba
- func (b *Biloba) NavigateWithStatus(url string, status int) *Biloba
- func (b *Biloba) NewTab() *Biloba
- func (b *Biloba) Prepare()
- func (b *Biloba) RelativeXPath(path ...string) XPath
- func (b *Biloba) RemoveDialogHandler(handler *DialogHandler)
- func (b *Biloba) Run(script string, args ...any) any
- func (b *Biloba) RunErr(script string, args ...any) (any, error)
- func (b *Biloba) SetProperty(args ...any) types.GomegaMatcher
- func (b *Biloba) SetPropertyForEach(selector any, property string, value any)
- func (b *Biloba) SetValue(args ...any) types.GomegaMatcher
- func (b *Biloba) SetWindowSize(width, height int, opts ...chromedp.EmulateViewportOption)
- func (b *Biloba) TabWithDOMElement(selector any) TabFilter
- func (b *Biloba) TabWithTitle(title any) TabFilter
- func (b *Biloba) TabWithURL(url any) TabFilter
- func (b *Biloba) Title() string
- func (b *Biloba) WindowSize() (int, int)
- func (b *Biloba) XPath(path ...string) XPath
- func (b *Biloba) XPredicate() XPath
- type BilobaConfigOption
- type ChromeConnection
- type Dialog
- type DialogHandler
- type DialogType
- type Dialogs
- type Download
- type DownloadFilter
- type Downloads
- type GinkgoTInterface
- type JSFunc
- type JSVar
- type Properties
- func (p Properties) Get(k string) any
- func (p Properties) GetAnySlice(k string) []any
- func (p Properties) GetBool(k string) bool
- func (p Properties) GetFloat64(k string) float64
- func (p Properties) GetInt(k string) int
- func (p Properties) GetString(k string) string
- func (p Properties) GetStringSlice(k string) []string
- type SliceOfProperties
- func (sp SliceOfProperties) Filter(k string, search any) SliceOfProperties
- func (sp SliceOfProperties) Find(k string, search any) Properties
- func (sp SliceOfProperties) Get(k string) []any
- func (sp SliceOfProperties) GetAnySlice(k string) [][]any
- func (sp SliceOfProperties) GetBool(k string) []bool
- func (sp SliceOfProperties) GetFloat64(k string) []float64
- func (sp SliceOfProperties) GetInt(k string) []int
- func (sp SliceOfProperties) GetString(k string) []string
- func (sp SliceOfProperties) GetStringSlice(k string) [][]string
- type TabFilter
- type Tabs
- type XPath
- func (x XPath) Ancestor(tag ...string) XPath
- func (x XPath) AncestorNotSelf(tag ...string) XPath
- func (x XPath) And(predicates ...XPath) XPath
- func (x XPath) Child(tag ...string) XPath
- func (x XPath) Descendant(tag ...string) XPath
- func (x XPath) DescendantNotSelf(tag ...string) XPath
- func (x XPath) First() XPath
- func (x XPath) FollowingSibling(tag ...string) XPath
- func (x XPath) HasAttr(attr string) XPath
- func (x XPath) Last() XPath
- func (x XPath) Not(predicate XPath) XPath
- func (x XPath) Nth(n int) XPath
- func (x XPath) Or(predicates ...XPath) XPath
- func (x XPath) Parent() XPath
- func (x XPath) PrecedingSibling(tag ...string) XPath
- func (x XPath) String() string
- func (x XPath) WithAttr(attr string, value string) XPath
- func (x XPath) WithAttrContains(attr string, value string) XPath
- func (x XPath) WithAttrStartsWith(attr string, value string) XPath
- func (x XPath) WithChildMatching(childPath XPath) XPath
- func (x XPath) WithClass(class string) XPath
- func (x XPath) WithID(id string) XPath
- func (x XPath) WithText(value string) XPath
- func (x XPath) WithTextContains(value string) XPath
- func (x XPath) WithTextStartsWith(value string) XPath
Constants ¶
const BILOBA_VERSION = "0.1.6"
const DialogTypeAlert = page.DialogTypeAlert
const DialogTypeBeforeunload = page.DialogTypeBeforeunload
const DialogTypeConfirm = page.DialogTypeConfirm
const DialogTypePrompt = page.DialogTypePrompt
Variables ¶
This section is empty.
Functions ¶
func BilobaConfigDisableFailureScreenshots ¶
func BilobaConfigDisableFailureScreenshots() func(*Biloba)
Pass BilobaConfigWithChromeConnection to ConnectToChrome to disable screenshots on failure
func BilobaConfigDisableProgressReportScreenshots ¶
func BilobaConfigDisableProgressReportScreenshots() func(*Biloba)
Pass BilobaConfigDisableProgressReportScreenshots to ConnectToChrome to disable screenshots when Progress Reports are emitted
func BilobaConfigEnableDebugLogging ¶
func BilobaConfigEnableDebugLogging() func(*Biloba)
Pass BilobaConfigEnableDebugLogging to ConnectToChrome to send all Chrome debug logging to the GinkgoWriter
func BilobaConfigFailureScreenshotsSize ¶ added in v0.1.3
Pass BilobaConfigFailureScreenshotsSize to ConnectToChrome to set the size for the screenshots generated on failure
func BilobaConfigProgressReportScreenshotSize ¶ added in v0.1.3
Pass BilobaConfigProgressReportScreenshotSize to ConnectToChrome to set the size for the screenshots generated when a progress report is requested
func BilobaConfigWithChromeConnection ¶
func BilobaConfigWithChromeConnection(cc ChromeConnection) func(*Biloba)
Pass BilobaConfigWithChromeConnection to ConnectToChrome to provide your own ChromeConnection details
func StartingWindowSize ¶
func StartingWindowSize(x int, y int) chromedp.ExecAllocatorOption
Pass StartingWindowSize into SpinUpChrome to set the default window size for all tabs
Types ¶
type Biloba ¶
type Biloba struct { //Context is the underlying chromedp context. Pass this in to chromedp to be take actions on this tab Context context.Context ChromeConnection ChromeConnection // contains filtered or unexported fields }
Biloba is the main object provided by Biloba for interacting with Chrome. You get an instance of Biloba when you ConnectToChrome. This instance is the reusable root tab and cannot be closed.
Any new tabs created or spawned while your tests run will be represented as different instances of Biloba.
To send commands to a particular tab you use the Biloba instance associated with that tab.
Read https://onsi.github.io/biloba/#parallelization-how-biloba-manages-browsers-and-tabs to build a mental model of how Biloba manages tabs
func ConnectToChrome ¶
func ConnectToChrome(ginkgoT GinkgoTInterface, options ...BilobaConfigOption) *Biloba
Call ConnectToChrome(GinkgoT()) to connect to a Chrome browser
Returns a *Biloba struct that you use to interact with the browser
Read https://onsi.github.io/biloba/#bootstrapping-biloba for details on how to set up your Ginkgo suite and use ConnectToChrome correctly
func (*Biloba) AllCompleteDownloads ¶
AllCompleteDownloads() returns all downloads associated with this tab that are complete
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (*Biloba) AllDownloads ¶
AllDownloads() returns all downloads associated with this tab
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (*Biloba) AllSpawnedTabs ¶
AllSpawnedTabs() returns all tabs that were spawned by the current tab. Spawned tabs are tabs that were created by the browser in response to some sort of user/javascript interaction. They are not tabs that you create explicitly with NewTab()
Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs
func (*Biloba) AllTabs ¶
AllTabs() returns all Biloba tabs currently associated with the current spec
Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs
func (*Biloba) BeEnabled ¶
func (b *Biloba) BeEnabled() types.GomegaMatcher
BeEnabled() is a Gomega matcher that passes if the first element returned by selector is not disabled.
Use it like this:
Expect("input").To(tab.BeEnabled()) Eventually("button").Should(tab.BeEnabled())
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) BeVisible ¶
func (b *Biloba) BeVisible() types.GomegaMatcher
BeVisible() is a Gomega matcher that passes if the first element returned by selector is visible.
Use it like this:
Expect("div.comment").To(tab.BeVisible()) Eventually("div.comment").Should(tab.BeVisible())
visibility is determined by non-zero offsetWidth and offsetHeight
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) BrowserContextID ¶
func (b *Biloba) BrowserContextID() cdp.BrowserContextID
The Chrome DevTools BrowserContextID() associated with this Biloba tab.
BrowserContextID is an isolation mechanism provided by Chrome DevTools - you may need to pass this in explicitly if you intend to make some low-level calls to chromedp.
func (*Biloba) CaptureImgcatScreenshot ¶
CaptureImgCatScreenshot() returns a full screenshot of the current tab as an iTerm2 imgcat-compatible string. Simply print it out to see images on your terminal.
func (*Biloba) CaptureScreenshot ¶
CaptureScreenshot() returns a full screenshot of the current tab as a []byte array (you can decode it with the image package)
func (*Biloba) Click ¶
func (b *Biloba) Click(args ...any) types.GomegaMatcher
Click() has two modes of operation:
When invoked with a selector:
tab.Click("#submit")
it immediately clicks the first element matching selector. It fails if no element is found, or if the element is hidden or disabled.
When invoked with no arguments, tab.Click() returns a Gomega matcher. This allows you to poll until an element is clickable (exists, is visible, and is enabled):
Eventually("#submit").Should(tab.Click())
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) ClickEach ¶
ClickEach() clicks on every DOM element matching selector that is visible and enabled.
If no elements match, nothing happens.
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) Close ¶
Close() closes a Biloba tab. It is an error to call Close() on the reusable root tab.
There is one additional edge case in which Close() can return an error. You can learn about it here: https://onsi.github.io/biloba/#going-the-extra-mile-for-stability
In short - if you have a test that involves both downloading files and tabs spawned by the browser (i.e. tabs that you didn't explicitly Create()) you should call:
Eventually(tab.Close).Should(Succeed())
func (*Biloba) Count ¶
Count(selector) returns the number of elements matching selector
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) Dialogs ¶
Dialogs() returns all dialogs handled by this Biloba tab in this spec
Read https://onsi.github.io/biloba/#inspecting-handled-dialogs to learn more about inspecting handled dialogs
func (*Biloba) DownloadWithContent ¶
func (b *Biloba) DownloadWithContent(content any) DownloadFilter
DownloadWithContent() returns a filter that selects Downloads with matching content (a []byte slice). content may be a []byte slice (exact match) or Gomega matcher
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (*Biloba) DownloadWithFilename ¶
func (b *Biloba) DownloadWithFilename(filename any) DownloadFilter
DownloadWithFilename() returns a filter that selects Downloads with a matching filename - this is the filename suggested to the browser when the download commences. filename may be a string (exact match) or Gomega matcher
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (*Biloba) DownloadWithURL ¶
func (b *Biloba) DownloadWithURL(url any) DownloadFilter
DownloadWithURL() returns a filter that selects Downloads with a matching url. url may be a string (exact match) or Gomega matcher
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (*Biloba) EachHaveInnerText ¶
func (b *Biloba) EachHaveInnerText(args ...any) types.GomegaMatcher
EachHaveInnerText(expected) is a Gomega matcher that passes if the []string slice of innerTexts for all matching elements returned by selector matches expected. expected can be a []string, but you'll probably want to use a Gomega matcher
Use it like this:
Eventually("div.comment").Should(tab.EachHaveInnerText(ContainElement("new comment"))) //equivalent to, but tidier than Eventually(tab.InnerTextForEach).WithArgument("div.comment").Should(ContainElement("new comment"))
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DO M
func (*Biloba) EachHaveProperty ¶
func (b *Biloba) EachHaveProperty(property string, expected ...any) types.GomegaMatcher
EachHaveProperty() is a Gomega matcher with two modes of operation:
When invoked with only one argument, it passes only if all elements matching selector have the requested javascript property defined on them:
Eventually("div.comment").Should(tab.EachHaveProperty("dataset.poster"))
When invoked with more than one argument, it only passes if the slice of values representing the property collected from the elements exactly matches the subsequent expected arguments:
Eventually("div.comment").Should(tab.EachHaveProperty("dataset.poster", "Jane", "George", "Sally"))
Alternatively, you can pass a Gomega matcher as a single expected argument after property. Biloba will present the slice of properties to that matcher. For example:
Eventually("div.comment").Should(tabEach.HaveProperty("dataset.poster", ContainElement("George")))
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#properties to learn more about working with properties
func (*Biloba) EvaluateTo ¶
func (b *Biloba) EvaluateTo(expected any) types.GomegaMatcher
EvaluateTo is a matcher that asserts that the result of running the script passed to Gomega matches expected:
Eventually("app.users.map(user => user.name)").Should(tab.EvaluateTo(ConsistOf("George", "Sally", "Bob")))
EvaluateTo can be passed a Gomega matcher to assert against the returned value from the script. Or it can be passed an arbitrary value in which case Equal() is used.
Read https://onsi.github.io/biloba/#running-arbitrary-javascript to learn more about running JavaScript in Biloba
func (*Biloba) Exist ¶
func (b *Biloba) Exist() types.GomegaMatcher
Exist() is a Gomega matcher that passes if the selector exists. Use it like this:
Eventually("div.comment").Should(tab.Exist())
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) GetProperties ¶
func (b *Biloba) GetProperties(selector any, properties ...string) Properties
GetProperties() returns a Properties struct containing multiple properties from the first DOM element selected by selector. If no DOM element matches, GetProperties() fails. If any of the requested properties don't exist - those properties will be set to nil.
p := GetProperties(".notice", "tagName", "classList", "dataset", "disabled") p.GetString("tagName") //"DIV" p.GetStringSlice("classList") //[]string{"notice", "highlight"} p.GetBool("disabled") //false
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#properties to learn more about working with properties
func (*Biloba) GetPropertiesForEach ¶
func (b *Biloba) GetPropertiesForEach(selector any, properties ...string) SliceOfProperties
GetPropertiesForEach() returns a SliceOfProperties - i.e. a slice of Properties - from each DOM element selected by selector. If no DOM element matches, GetPropertiesForEach() returns an empty SliceOfProperties. If any of the requested properties don't exist - those individual properties will be set to nil.
p := GetPropertiesForEach(".notice", "tagName", "classList", "dataset", "disabled") p.GetString("tagName") //[]string{"DIV", "DIV", "DIV"} p.GetStringSlice("classList") //[][]string{{"notice", "highlight"}, {"notice", "gray"}, {"notice"}} p.GetBool("disabled") //[]bool{false, true, false}
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#properties to learn more about working with properties
func (*Biloba) GetProperty ¶
GetProperty(selector, property) returns the named javascript property from the first element matching selector
GetProperty will fail if no element is found. It returns nil if property is not defined on the element. Otherwise it returns the value of the property as type any - you'll need to do type assertions yourself. Or just use a Gomega matcher to handle the types for you.
Dot-delimited properties are also support. e.g.
tab.GetProperty("div.comment", "dataset.poster")
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#properties to learn more about working with properties
func (*Biloba) GetPropertyForEach ¶
GetPropertyForEach(selector, property) returns the requested property for all elements matching selector. It returns []any and follows the rules of Biloba.GetProperty. If no elements are found an empty slice is returned.
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#properties to learn more about working with properties
func (*Biloba) GetValue ¶
GetValue returns the form/input related value for the first element matched by selector
Biloba rationalizes the behavior of all input, select, and textarea elements so you don't have to fiddle with the differences:
tab.GetValue("textarea") //will be a string representing the text in the textarea tab.GetValue("input[type='text']") // will be a string representing the text value of the input tab.GetValue("input[type='checkbox']") // will be true or false depending on whether the checkbox is checked tab.GetValue("input[type='radio']") // will be the value attribute of the selected radio button in the name group associated with the selected element tab.GetValue("select") // will be the value of the selected option of the select element tab.GetValue("select.multi-select") // will be a []string of values for all the selected options of the multiple select element
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#form-elements to learn more about working with form elements
func (*Biloba) GomegaString ¶
func (*Biloba) HandleAlertDialogs ¶
func (b *Biloba) HandleAlertDialogs() *DialogHandler
HandleAlertDialogs() registers an alert DialogHandler
Read https://onsi.github.io/biloba/#handling-dialogs to learn more about handling dialogs
func (*Biloba) HandleBeforeunloadDialogs ¶
func (b *Biloba) HandleBeforeunloadDialogs() *DialogHandler
HandleBeforeunloadDialogs() registers an beforeunload DialogHandler
Read https://onsi.github.io/biloba/#handling-dialogs to learn more about handling dialogs
func (*Biloba) HandleConfirmDialogs ¶
func (b *Biloba) HandleConfirmDialogs() *DialogHandler
HandleConfirmDialogs() registers a confirm DialogHandler
Read https://onsi.github.io/biloba/#handling-dialogs to learn more about handling dialogs
func (*Biloba) HandlePromptDialogs ¶
func (b *Biloba) HandlePromptDialogs() *DialogHandler
HandlePromptDialogs() registers a prompt Dialoghandler
Read https://onsi.github.io/biloba/#handling-dialogs to learn more about handling dialogs
func (*Biloba) HasElement ¶
HasElement(selector) returns true if an element matching selector is found
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) HaveClass ¶
func (b *Biloba) HaveClass(expected string) types.GomegaMatcher
HaveClass returns a Gomega matcher to assert that the first element matching selector has the expected class.
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) HaveCompleteDownload ¶
func (b *Biloba) HaveCompleteDownload(f DownloadFilter) types.GomegaMatcher
HaveCompleteDownload() is a matcher that passes if this tab has a complete download that satisfies the passed in DownloadFilter
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (*Biloba) HaveCount ¶
func (b *Biloba) HaveCount(expected any) types.GomegaMatcher
HaveCount(expected) is a Gomega matcher that passes if the number of elements returned by selector matches expected. expected can be an integer or Gomega matcher.
Use it like this:
Expect("div.comment").To(tab.HaveCount(3)) Eventually("div.comment").Should(tab.HaveCount(BeNumerically(">", 5)))
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) HaveInnerText ¶
func (b *Biloba) HaveInnerText(expected any) types.GomegaMatcher
HaveInnerText(expected) is a Gomega matcher that passes if the first element returned by selector has innerText matching expected. expected can be a string, or a Gomega matcher
Use it like this:
Expect("div.comment").To(tab.HaveInnerText("hello world")) Expect("div.comment").To(tab.HaveInnerText(HaveSuffix("world")))
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DO M
func (*Biloba) HaveProperty ¶
func (b *Biloba) HaveProperty(property string, expected ...any) types.GomegaMatcher
HaveProperty() is a Gomega matcher with two modes of operation:
When invoked with only one argument, it passes only if the first element matching selector has the requested javascript property defined on it:
Eventually("div.comment").Should(tab.HaveProperty("dataset.poster"))
When invoked with two arguments, it only passes if the value of the specified property matches the second argument. This expect argument can be a Gomega matcher. Otherwise gomega.Equal is used
Eventually("div.comment").Should(tab.HaveProperty("dataset.poster", "Jane"))
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#properties to learn more about working with properties
func (*Biloba) HaveSpawnedTab ¶
func (b *Biloba) HaveSpawnedTab(f TabFilter) types.GomegaMatcher
HaveSpawnedTab() is a matcher that succeeds if the passed-in TabFilter returns true for any of the spawned tabs associated with this tab. You can use it to wait for a tab to open:
tab.Click("a[target='_blank']") Eventually(tab).Should(tab.HaveSpawnedTab(tab.TabWithTile("hello there")))
Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs
func (*Biloba) HaveTab ¶
func (b *Biloba) HaveTab(f TabFilter) types.GomegaMatcher
HaveTab() is a matcher that succeeds if the passed-in TabFilter returns true for any of the tabs associated with this tab's Chrome Connection. This will include all tabs - not just tabs spawned by this Tab. You generally only use this on the reusable root tab - but you are allowed to use it on any tab; the result will be the same.
Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs
func (*Biloba) HaveValue ¶
func (b *Biloba) HaveValue(expected any) types.GomegaMatcher
HaveValue returns a Gomega matcher to assert that the first element matching selector has the expected value. If you pass in a Gomega matcher it will be used
For example:
Expect("textarea").To(tab.HaveValue(ContainSubstring("hello"))) Expect("input[type='text']").To(tab.HaveValue("Sally")) Expect("input[type='checkbox']").To(tab.HaveValue(BeTrue())) Expect("input[type='radio']").To(tab.HaveValue("red")) //here red is the value of the selected radio button Expect("select").To(tab.HaveValue("obi-wan")) //here obi-wan is the value of the selected option Expect("select.multi-select").To(tab.HaveValue(ConsistOf("obi-wan", "leia", "han"))) //here we assert that these three options are selected
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#form-elements to learn more about working with form elements
func (*Biloba) InnerText ¶
InnerText(selector) returns the innerText of the first element matching selector
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) InnerTextForEach ¶
InnerTextForEach(selector) returns a slice []string of innerText for each element matching selector
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) InvokeOn ¶
InvokeOn() takes a selector, a method name, and optional arguments. It will find the first element matching selector and invoke method on that option, passing in any arguments provided. That is:
tab.InvokeOn("input.login", "scrollIntoView") tab.InvokeOn(".notice", "setAttribute", "data-age", "17")
are equivalent to the javascript:
document.querySelector("input.login")["scrollIntoView"]() document.querySelector(".notice")["setAttribute"]("data-age", "17")
InvokeOn() fails if no element is found, or if the method is not defined on the element. Anything returned by method is returned by InvokeOn with type any:
Expect(document.InvokeOn("getAttribute", "data-age")).To(Equal("17"))
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#invoking-javascript-on-and-with-selected-elements to learn more about invoking javascript on/with DOM elements
func (*Biloba) InvokeOnEach ¶
InvokeOnEach() invokes the passed-in method, passing in the args if any, on all elements matching selector. It returns a []any slice containing any return values from each invocation.
All invocations receive the same arguments.
See Biloba.InvokeOn for more details
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#invoking-javascript-on-and-with-selected-elements to learn more about invoking javascript on/with DOM elements
func (*Biloba) InvokeWith ¶
InvokeWith() finds the first element matching selector then invokes the passed-in function, passing in the element and any additional args provided. It returns anything returned by the function as type any.
callableScript must be a snippet of javascript that evaluates to a callable function. For example:
appendLi := `(el, text) => { let li = document.createElement('li') li.innerText = text el.appendChild(li); }` b.InvokeWith("ul", appendLi, "Another Item") //runs on the first <ul> b.InvokeWithEach("ul", appendLi, "Another Item For All") //runs on all <ul>s
InvokeWith fails if no element is found ¶
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#invoking-javascript-on-and-with-selected-elements to learn more about invoking javascript on/with DOM elements
func (*Biloba) InvokeWithEach ¶
InvokeWithEach() finds all elements matching selector then invokes the passed-in function on each element, passing in the element and any additional args provided. It collects the return values for each invocation and returns them as an []any slice.
See Biloba.InvokeWith for more details
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#invoking-javascript-on-and-with-selected-elements to learn more about invoking javascript on/with DOM elements
func (*Biloba) JSFunc ¶
JSFunc() allows you to write Javascript functions that are invoked with Go arguments and then passed in to Run:
adder := b.JSFunc("(...nums) => nums.reduce((s, n) => s + n, 0)") var result int b.Run(adder.Invoke(1, 2, 3, 4, 5, 10), &result)
Read https://onsi.github.io/biloba/#running-arbitrary-javascript to learn more about running JavaScript in Biloba
func (*Biloba) JSVar ¶
JSVar() allows you to indicate that the wrapped variable should be not be interpolated by Invoke(), instead it should be provided by the JavaScript environment and not Go.
This is perhaps best understood with an example:
adder := tab.JSFunc("(...nums) => nums.reduce((s, n) => s + n, 0)") tab.Run(adder.Invoke(15, 10, tab.JSVar("app.numRecords"), tab.JSVar("app.numUsers + 10")))
This call to invoke will generate the following literal script:
((...nums) => nums.reduce((s, n) => s + n, 0))(...[15, 10, app.numRecords, app.numUsers + 10])
which, when eval()'d in JavaScript will pull in the app variable from the global window object and grab the numRecords and numUsers properties.
If were to not wrap these variables in JSVar:
tab.Run(adder.Invoke(15, 10, "app.numRecords", "app.numUsers + 10")) //wrong!
then the generated script would be:
//not what you want! ((...nums) => nums.reduce((s, n) => s + n, 0))(...[15, 10, "app.numRecords", "app.numUsers + 10"])
which would (of course) evaluate to "25app.numRecordsapp.numUsers + 10". (of course).
Read https://onsi.github.io/biloba/#running-arbitrary-javascript to learn more about running JavaScript in Biloba
func (*Biloba) Navigate ¶
Navigate() causes this tab to navigate to the provided URL. The spec fails if the response does not have status code 200
Read https://onsi.github.io/biloba/#navigation to learn more about navigation
func (*Biloba) NavigateWithStatus ¶
NavigateWithStatus() causes this tab to navigate to the provided URL and asserts that the response has the provided status code.
Read https://onsi.github.io/biloba/#navigation to learn more about navigation
func (*Biloba) NewTab ¶
NewTab() creates a new browser tab and returns a Biloba instance pointing to it
Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs
func (*Biloba) Prepare ¶
func (b *Biloba) Prepare()
Prepare() should be called before every spec. It prepares the reusable Biloba tab for reuse.
Read https://onsi.github.io/biloba/#bootstrapping-biloba for details on how to set up your Ginkgo suite and use Prepare() correctly
Read https://onsi.github.io/biloba/#parallelization-how-biloba-manages-browsers-and-tabs to build a mental model of how Biloba manages tabs
func (*Biloba) RelativeXPath ¶
RelativeXPath() begins a relative XPath query - one that begins with "./"
It is primarily used with XPath.WithChildMatching:
b.XPath("ul").WithChildMatching(b.RelativeXPath("li").WithText("igloo"))
will select <ul> elements that have a child <li> with text igloo
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (*Biloba) RemoveDialogHandler ¶
func (b *Biloba) RemoveDialogHandler(handler *DialogHandler)
Pass RemoveDialogHandler() a handler returned by one of the Handle*Dialogs methods to unregister it
Read https://onsi.github.io/biloba/#handling-dialogs to learn more about handling dialogs
func (*Biloba) Run ¶
Run() runs the passed in script and returns the result (as type any):
tab.Run("1+3") // returns 4.0
You can also pass a single pointer argument if you would like Biloba to decode the result into a specific type (a la json.Unmarshal):
var result int tab.Run("1+3", &result) // result is now 4
If an error occurs Run() will fail the spec ¶
Read https://onsi.github.io/biloba/#running-arbitrary-javascript to learn more about running JavaScript in Biloba
func (*Biloba) RunErr ¶
RunErr() runs the passed in script and returns the result as well as an error
You should generally use Biloba.Run instead of RunErr and let Biloba handle errors for you
Read https://onsi.github.io/biloba/#running-arbitrary-javascript to learn more about running JavaScript in Biloba
func (*Biloba) SetProperty ¶
func (b *Biloba) SetProperty(args ...any) types.GomegaMatcher
SetProperty() has two modes of operation:
When invoked with a selector and two arguments:
tab.SetProperty(selector, property, value)
it immediately sets the specified property on the first element matching selector to value. If no element is found, tab.SetProperty fails the spec. property must have type string but value can be any type
When invoked with just two arguments, tab.SetProperty returns a Gomega matcher that will only succeed once an element is found and its property set:
Eventually("div.comment").Should(tab.SetProperty("dataset.poster", "George"))
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#properties to learn more about working with properties
func (*Biloba) SetPropertyForEach ¶
SetPropertyForEach() sets the specified property to the specified value on all DOM elements matching selector. It does nothing if no elements match.
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#properties to learn more about working with properties
func (*Biloba) SetValue ¶
func (b *Biloba) SetValue(args ...any) types.GomegaMatcher
SetValue() has two modes of operation:
When invoked with a selector and a value:
tab.SetValue(selector, value)
it immediately sets the value on the first element matching selector. If no element is found, tab.SetValue fails the spec. The element must be visible and enabled.
When invoked with just one argument, tab.SetValue returns a Gomega matcher that will only succeed once an element is found, is visible, and is enabled and its value gets set:
Eventually("input[type='checkbox']").Should(tab.SetValue(true))
the types you provide `SetValue` will depend on the type of input you are addressing. See Biloba.GetValue for examples.
Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM Read https://onsi.github.io/biloba/#form-elements to learn more about working with form elements
func (*Biloba) SetWindowSize ¶
func (b *Biloba) SetWindowSize(width, height int, opts ...chromedp.EmulateViewportOption)
SetWindowSize() sets the window size for this tab. A DeferCleanup is automatically registered to reset the window size after the spec ends
func (*Biloba) TabWithDOMElement ¶
TabWithDOMElement() is a TabFilter that selects tabs that have at least one element matching selector
Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs Read https://onsi.github.io/biloba/#working-with-the-dom to learn more about selectors and handling the DOM
func (*Biloba) TabWithTitle ¶
TabWithTitle() is a TabFilter that selects tabs with window titles matching title. If title is a string, an exact match is required. If title is a matcher, the matcher is used to test the tab's Biloba.Title
Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs
func (*Biloba) TabWithURL ¶
TabWithURL() is a TabFilter that selects tabs with URLs matching url. If url is a string, an exact match is required. If url is a matcher, the matcher is used to test the tab's Biloba.Location
Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs
func (*Biloba) WindowSize ¶
WindowSize() returns the current window size of this tab.
func (*Biloba) XPath ¶
XPath() constructs an XPath query - you can provide a fully specified query:
tab.XPath("//div[@id='foo']")
or use the XPath DSL:
tab.XPath("div").WithID("foo")
You then pass the result into one of Biloba's DOM methods/matchers:
tab.Click(tab.XPath("div").WithID("foo")) Eventually(tab.XPath(".comment").WithText("Hello world")).Should(tab.Exist())
When invoked with no arguments tab.XPath() returns a new XPath query that begins with "//*" for example:
tab.Click(tab.XPath().WithID("foo"))
will match any element with id 'foo'
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (*Biloba) XPredicate ¶
XPredicate() returns an empty XPath snippet for use with boolean operations:
b.XPath("button").WithText("Add Comment").Not(b.XPredicate().HasAttr("disabled"))
will match <button> elements containing text "Add Comment" that are not disabled.
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
type BilobaConfigOption ¶
type BilobaConfigOption func(*Biloba)
BilobaConfigOptions are passed in to ConnectToChrome to configure a given connection to Chrome
type ChromeConnection ¶
type ChromeConnection struct {
WebSocketURL string
}
ChromeConnection captures the details necessary for ConnectToChrome to connect to Chrome
func SpinUpChrome ¶
func SpinUpChrome(ginkgoT GinkgoTInterface, options ...chromedp.ExecAllocatorOption) ChromeConnection
Call SpinUpChrome(GinkgoT()) to spin up a Chrome browser
Read https://onsi.github.io/biloba/#bootstrapping-biloba for details on how to set up your Ginkgo suite and use SpinUpChrome correctly
type Dialog ¶
type Dialog struct { Type page.DialogType Message string DefaultPrompt string HandleResponse bool HandleText string //Autohandled is true if Biloba's default handlers handled this dialog Autohandled bool }
Dialog represents a Dialog handled by Biloba
Read https://onsi.github.io/biloba/#inspecting-handled-dialogs to learn more
type DialogHandler ¶
type DialogHandler struct {
// contains filtered or unexported fields
}
DialogHandler is returned by Biloba's Handle*Dialogs methods
Use DialogHandler's methods to configure how you want Biloba to handle the response.
Read https://onsi.github.io/biloba/#handling-dialogs to learn more
func (*DialogHandler) MatchingMessage ¶
func (d *DialogHandler) MatchingMessage(message any) *DialogHandler
Set MatchingMessage to only handle dialogs whose message matches
You can pass in a string or Gomega matcher
func (*DialogHandler) WithResponse ¶
func (d *DialogHandler) WithResponse(r bool) *DialogHandler
WithResponse controls whether Biloba should accept or decline the dialog
func (*DialogHandler) WithText ¶
func (d *DialogHandler) WithText(text string) *DialogHandler
WithText controls what text Biloba should provide to prompt dialogs
If none i provided the default prompt given by the browser is used
type DialogType ¶
type DialogType = page.DialogType
DialogType is used to distinguish between different types of Dialogs
type Dialogs ¶
type Dialogs []*Dialog
func (Dialogs) MatchingMessage ¶
OfType() filters Dialogs by message. You may pass in a string or Gomega matcher
func (Dialogs) MostRecent ¶
MostRecent() returns the last element of Dialogs
func (Dialogs) OfType ¶
func (d Dialogs) OfType(t DialogType) Dialogs
OfType() filters Dialogs by DialogType
type Download ¶
type Download struct { GUID string URL string Filename string // contains filtered or unexported fields }
Download represents a downloaded file
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (*Download) Content ¶
Content() returns the contents of the file that was downloaded
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (*Download) IsActive ¶
IsActive() returns true if the download is still in progress
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (*Download) IsCancelled ¶
IsComplete() returns true if the download was cancelled
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (*Download) IsComplete ¶
IsComplete() returns true if the download is complete
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
type DownloadFilter ¶
DownloadFilter is used to filter downloads
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
type Downloads ¶
type Downloads []*Download
Downloads represents a slice of *Download
func (Downloads) Filter ¶
func (d Downloads) Filter(f DownloadFilter) Downloads
Filter returns a Downloads slice containing all matching *Download objects
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
func (Downloads) Find ¶
func (d Downloads) Find(f DownloadFilter) *Download
Find returns the first download that matches DownloadFilter, or nil if none match
Read https://onsi.github.io/biloba/#managing-downloads to learn more about managing Downloads in Biloba
type GinkgoTInterface ¶
type GinkgoTInterface interface { Name() string Helper() Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) TempDir() string Logf(format string, args ...any) Failed() bool GinkgoRecover() DeferCleanup(args ...any) Print(args ...any) Printf(format string, args ...any) Println(a ...interface{}) F(format string, args ...any) string Fi(indentation uint, format string, args ...any) string Fiw(indentation uint, maxWidth uint, format string, args ...any) string AddReportEntryVisibilityFailureOrVerbose(name string, args ...any) ParallelProcess() int ParallelTotal() int AttachProgressReporter(func() string) func() RenderTimeline() string }
GinkgoTInterface is the interface by which Biloba receives GinkgoT()
type JSFunc ¶
type JSFunc string
func (JSFunc) Invoke ¶
Invoke() interpolates the passed-in args into the JSFunc and generates a script that cna be passed to Run()
adder := b.JSFunc("(...nums) => nums.reduce((s, n) => s + n, 0)") var result int tab.Run(adder.Invoke(1, 2, 3, 4, 5, 10), &result)
Read https://onsi.github.io/biloba/#running-arbitrary-javascript to learn more about running JavaScript in Biloba
type JSVar ¶
type JSVar struct {
// contains filtered or unexported fields
}
func (JSVar) MarshalJSON ¶
type Properties ¶
Properties is returned by Biloba.GetProperties and provides getters that perform type assertions and nil-conversions for you
For each of the Get* methods if the requested property does not exist or is nil, the getter will return the zero value of the associated type (or an empty slice of correct type for the Get*Slice methods)
Read https://onsi.github.io/biloba/#properties to learn more about properties
func (Properties) Get ¶
func (p Properties) Get(k string) any
func (Properties) GetAnySlice ¶
func (p Properties) GetAnySlice(k string) []any
func (Properties) GetBool ¶
func (p Properties) GetBool(k string) bool
func (Properties) GetFloat64 ¶
func (p Properties) GetFloat64(k string) float64
func (Properties) GetInt ¶
func (p Properties) GetInt(k string) int
func (Properties) GetString ¶
func (p Properties) GetString(k string) string
func (Properties) GetStringSlice ¶
func (p Properties) GetStringSlice(k string) []string
type SliceOfProperties ¶
type SliceOfProperties []Properties
SliceOfProperties has underlying type []Properties and is returned by [GetPropertiesForEach]. SliceOfProperties provides getters that perform type assertions and nil-conversions for you.
For each of the Get* methods the return value is a slice of appropriate type. The slice will have the same length as the SliceOfProperties instance and will be filled with the values returned by each Properties invocation of Get* (i.e. nil and missing types will return the zero value.)
Read https://onsi.github.io/biloba/#properties to learn more about properties
func (SliceOfProperties) Filter ¶
func (sp SliceOfProperties) Filter(k string, search any) SliceOfProperties
Filter() returns the subset of Properties in SliceOfProperties that satisfies the provided search criteria.
The search behaves similarly to [Biloba.Find].
Read https://onsi.github.io/biloba/#properties to learn more about properties
func (SliceOfProperties) Find ¶
func (sp SliceOfProperties) Find(k string, search any) Properties
Find() the first Properties in SliceOfProperties that satisfies the provided search criteria.
If search is a a Gomega matcher then the return Properties will have a value for key k that is successfully matched by the matcher.
If search is not a matcher then Equal(search) is used to perform the match ¶
Read https://onsi.github.io/biloba/#properties to learn more about properties
func (SliceOfProperties) Get ¶
func (sp SliceOfProperties) Get(k string) []any
func (SliceOfProperties) GetAnySlice ¶
func (sp SliceOfProperties) GetAnySlice(k string) [][]any
func (SliceOfProperties) GetBool ¶
func (sp SliceOfProperties) GetBool(k string) []bool
func (SliceOfProperties) GetFloat64 ¶
func (sp SliceOfProperties) GetFloat64(k string) []float64
func (SliceOfProperties) GetInt ¶
func (sp SliceOfProperties) GetInt(k string) []int
func (SliceOfProperties) GetString ¶
func (sp SliceOfProperties) GetString(k string) []string
func (SliceOfProperties) GetStringSlice ¶
func (sp SliceOfProperties) GetStringSlice(k string) [][]string
type Tabs ¶
type Tabs []*Biloba
Tabs represents a slice of Biloba tabs
Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs
func (Tabs) Filter ¶
Find returns the all tabs matching the TabFilter
Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs
type XPath ¶
type XPath string
Type XPath allows you to provide an XPath query anywhere Biloba accepts a selector
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) Ancestor ¶
Ancestor() appends the ancestor-or-self axis to the XPath query. Ancestor() appends "/ancestor-or-self::*" while Ancestor(tag) appends "/ancestor-or-self::tag"
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) AncestorNotSelf ¶
AncestorNotSelf() appends the ancestor axis to the XPath query. AncestorNotSelf() appends "/ancestor::*" while AncestorNotSelf(tag) appends "/ancestor::tag"
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) And ¶
And() takes arbitrarily many XPredicate() and ANDs them together, then appends that predicate the XPath query.
tab.XPath().And(tab.XPredicate().WithClass("hidden"), tab.XPredicate().WithClass("important"))
will select all elements that have class hidden and class important. Note that in most cases you should just:
tab.XPath().WithClass("hidden").WithClass("important")
And() is necessary if you want to nest boolean operations:
tab.XPath().Or( Not(tab.XPredicate().WithClass("hidden")), And( tab.XPredicate().WithClass("important"), tab.XPredicate().WithClass("top-secret"), ), )
will select all elements that do not have class hidden or elements that have both important and top-secret.
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) Child ¶
Child() adds the child axis to the XPath query. Child() appends "/*" and Child(tag) appends "/tag"
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) Descendant ¶
Descendant() appends the descendant axis to the XPath query. Descendant() appends "//*" while Descendant(tag) appends "//tag"
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) DescendantNotSelf ¶
DescendantNotSelf() appends the descendant axis to the XPath query. DescendantNotSelf() appends "/descendant::*" while DescendantNotSelf(tag) appends "/descendant::tag"
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) First ¶
First() adds the index selection predicate [1] to the XPath query to select the first matching element
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) FollowingSibling ¶
FollowingSibling() appends the following-sibling axis to the XPath query. FollowingSibling() appends "/following-sibling::*" while FollowingSibling(tag) appends "/following-sibling::tag"
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) HasAttr ¶
HasAttr(attr) appends the [@attr] attribute existence predicate to the XPath
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) Last ¶
Last(n) adds the index selection predicate [last()] to the XPath query to select the last matching element
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) Not ¶
Not() takes an XPredicate() and negates it, then appends that predicate the XPath query:
tab.XPath().Not(tab.XPredicate().WithClass("hidden"))
will select all elements that do not have class hidden
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) Nth ¶
Nth(n) adds the index selection predicate [n] to the XPath query to select the nth matching element
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) Or ¶
Or() takes arbitrarily many XPredicate() and ORs them together, then appends that predicate the XPath query:
tab.XPath().Or(Not(tab.XPredicate().WithClass("hidden")), tab.XPredicate().WithClass("important"))
will select all elements that do not have class hidden or have class important.
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) Parent ¶
Parent() appends the direct parent axis "/.." to the XPath query
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) PrecedingSibling ¶
PrecedingSibling() appends the preceding-sibling axis to the XPath query. PrecedingSibling() appends "/preceding-sibling::*" while PrecedingSibling(tag) appends "/preceding-sibling::tag"
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) String ¶
String() renders the XPath generated by the DSL as a string. This means you can just fmt.Print an XPath query to see what Biloba has generated
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) WithAttr ¶
WithAttr(attr, value) appends the [@attr='value'] attribute predicate to the XPath
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) WithAttrContains ¶
WithAttrContains(attr, value) appends the [contains(@attr, 'value')] attribute predicate to the XPath
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) WithAttrStartsWith ¶
WithAttrStartsWith(attr, value) appends the [starts-with(@attr, 'value')] attribute predicate to the XPath
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) WithChildMatching ¶
WithChildMatching() takes a RelativeXPath() and adds it as a predicate to the XPath query:
b.XPath("ul").WithChildMatching(b.RelativeXPath("li").WithText("igloo"))
will select <ul> elements that have a child <li> with text igloo
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) WithClass ¶
WithClass(call) appends a class predicate to the XPath. See https://devhints.io/xpath for details
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) WithID ¶
WithID(id) appends [@id='id'] to the XPath
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) WithText ¶
WithText(value) appends the [text()='value'] predicate to the XPath
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) WithTextContains ¶
WithTextContains(value) appends the [contains(text(), 'value')] predicate to the XPath
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL
func (XPath) WithTextStartsWith ¶
WithTextStartsWith(value) appends the [starts-with(text(), 'value')] predicate to the XPath
Read https://onsi.github.io/biloba/#the-xpath-dsl to learn more about Biloba's XPath DSL