biloba

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 23 Imported by: 0

README

Ginkgo

test | Biloba Docs


Biloba

"Automated browser testing is slow and flaky" - every developer, ever

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

Take a look at the documentation to learn more and get started!

Here's a quick taste of what Biloba specs look like:

func login(tab *Biloba, user string, password string) {
	GinkgoHelper()
	tab.Navigate("/login")
	Eventually("#user").Should(tab.SetValue("sally"))
	tab.SetValue("#password", "yllas")
	tab.Click("#log-in")
	Eventually(".chat-page").Should(tab.Exist())
}

Describe("a simple chat app", func() {
	var tab *Biloba
	BeforeEach(func() {
		login(b, "sally", "yllas")
		tab = b.NewTab()
		login(tab, "jane", "enaj")
	})

	It("shows all logged in users as present", func() {
		userXPath := b.XPath("div").WithID("user-list").Descendant()
		// b should show both users
		Eventually(userXPath.WithText("Sally")).Should(b.HaveClass("online"))
		Eventually(userXPath.WithText("Jane")).Should(b.HaveClass("online"))
		// tab should show both users
		Eventually(userXPath.WithText("Sally")).Should(tab.HaveClass("online"))
		Eventually(userXPath.WithText("Jane")).Should(tab.HaveClass("online"))
	})

	It("shows Jane when Sally is typing", func() {
		lastEntryXPath := tab.XPath("#conversation").Descendant().WithClass("entry").Last()
		b.SetValue("#input", "Hey Jane, how are you?")
		Eventually(lastEntryXPath).Should(SatisfyAll(
			tab.HaveInnerText("Jane is typing..."),
			tab.HaveClass("typing"),
		))

		b.SetValue("#input", "")
		Eventually(lastEntryXPath).ShouldNot(SatisfyAny(
			tab.HaveInnerText("Jane is typing..."),
			tab.HaveClass("typing"),
		))
	})

	It("shows Jane new messages from Sally, and sally new messages from Jane", func() {
		lastEntryXPath := tab.XPath("#conversation").Descendant().WithClass("entry").Last()
		b.SetValue("#input", "Hey Jane, how are you?")
		b.Click("#send")
		Eventually(lastEntryXPath).Should(tab.HaveInnerText("Hey Jane, how are you?"))

		tab.SetValue("#input", "I'm splendid, Sally!")
		tab.Click("#send")
		Eventually(lastEntryXPath).Should(b.HaveInnerText("I'm splendid, Sally!"))
	})

	It("tracks when users aren't online", func() {
		userXPath := b.XPath("div").WithID("user-list").Descendant()
		Eventually(userXPath.WithText("Jane")).Should(b.HaveClass("online"))

		tab.Close()
		Eventually(userXPath.WithText("Jane")).Should(b.HaveClass("offline"))
	})
})

Run these in series with ginkgo. And in parallel with ginkgo -p for fast, stable, browser tests.

Biloba is quite feature complete and in active development. However, a 1.0 release milestone has not been reached yet, so the public API contract may shift as the project evolves.


Ginkgo Tree Graphics Designed By 可行 From LovePik.com

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

View Source
const BILOBA_VERSION = "0.1.6"
View Source
const DialogTypeAlert = page.DialogTypeAlert
View Source
const DialogTypeBeforeunload = page.DialogTypeBeforeunload
View Source
const DialogTypeConfirm = page.DialogTypeConfirm
View Source
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

func BilobaConfigFailureScreenshotsSize(width, height int) func(*Biloba)

Pass BilobaConfigFailureScreenshotsSize to ConnectToChrome to set the size for the screenshots generated on failure

func BilobaConfigProgressReportScreenshotSize added in v0.1.3

func BilobaConfigProgressReportScreenshotSize(width, height int) func(*Biloba)

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

func (b *Biloba) AllCompleteDownloads() Downloads

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

func (b *Biloba) AllDownloads() Downloads

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

func (b *Biloba) AllSpawnedTabs() Tabs

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

func (b *Biloba) AllTabs() Tabs

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

func (b *Biloba) CaptureImgcatScreenshot() string

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

func (b *Biloba) CaptureScreenshot() []byte

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

func (b *Biloba) ClickEach(selector any)

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

func (b *Biloba) Close() error

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

func (b *Biloba) Count(selector any) int

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

func (b *Biloba) Dialogs() 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

func (b *Biloba) GetProperty(selector any, property string) any

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

func (b *Biloba) GetPropertyForEach(selector any, property string) []any

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

func (b *Biloba) GetValue(selector any) any

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 (b *Biloba) GomegaString() string

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

func (b *Biloba) HasElement(selector any) bool

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

func (b *Biloba) InnerText(selector any) string

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

func (b *Biloba) InnerTextForEach(selector any) []string

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

func (b *Biloba) InvokeOn(selector string, methodName string, args ...any) any

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

func (b *Biloba) InvokeOnEach(selector string, methodName string, args ...any) []any

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

func (b *Biloba) InvokeWith(selector string, callableScript string, args ...any) any

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

func (b *Biloba) InvokeWithEach(selector string, callableScript string, args ...any) []any

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

func (b *Biloba) JSFunc(f string) 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

func (b *Biloba) JSVar(v string) 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) Location

func (b *Biloba) Location() string

Location() returns the location (i.e. url) of the current tab.

func (*Biloba) Navigate

func (b *Biloba) Navigate(url string) *Biloba

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

func (b *Biloba) NavigateWithStatus(url string, status int) *Biloba

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

func (b *Biloba) NewTab() *Biloba

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

func (b *Biloba) RelativeXPath(path ...string) XPath

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

func (b *Biloba) Run(script string, args ...any) any

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

func (b *Biloba) RunErr(script string, args ...any) (any, error)

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

func (b *Biloba) SetPropertyForEach(selector any, property string, value any)

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

func (b *Biloba) TabWithDOMElement(selector any) TabFilter

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

func (b *Biloba) TabWithTitle(title any) TabFilter

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

func (b *Biloba) TabWithURL(url any) TabFilter

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) Title

func (b *Biloba) Title() string

Title() returns the window title of the current tab.

func (*Biloba) WindowSize

func (b *Biloba) WindowSize() (int, int)

WindowSize() returns the current window size of this tab.

func (*Biloba) XPath

func (b *Biloba) XPath(path ...string) 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

func (b *Biloba) XPredicate() XPath

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

func (d Dialogs) MatchingMessage(message any) Dialogs

OfType() filters Dialogs by message. You may pass in a string or Gomega matcher

func (Dialogs) MostRecent

func (d Dialogs) MostRecent() *Dialog

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

func (d *Download) Content() []byte

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

func (d *Download) IsActive() bool

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

func (d *Download) IsCancelled() bool

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

func (d *Download) IsComplete() bool

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

type DownloadFilter func(*Download) bool

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

func (j JSFunc) Invoke(args ...any) string

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

func (j JSVar) MarshalJSON() ([]byte, error)

type Properties

type Properties map[string]any

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 TabFilter

type TabFilter func(b *Biloba) bool

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

func (t Tabs) Filter(f TabFilter) Tabs

Find returns the all tabs matching the TabFilter

Read https://onsi.github.io/biloba/#managing-tabs to learn more about managing tabs

func (Tabs) Find

func (t Tabs) Find(f TabFilter) *Biloba

Find returns the first Biloba tab 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

func (x XPath) Ancestor(tag ...string) XPath

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

func (x XPath) AncestorNotSelf(tag ...string) XPath

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

func (x XPath) And(predicates ...XPath) XPath

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

func (x XPath) Child(tag ...string) XPath

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

func (x XPath) Descendant(tag ...string) XPath

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

func (x XPath) DescendantNotSelf(tag ...string) XPath

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

func (x XPath) First() XPath

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

func (x XPath) FollowingSibling(tag ...string) XPath

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

func (x XPath) HasAttr(attr string) XPath

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

func (x XPath) Last() XPath

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

func (x XPath) Not(predicate XPath) XPath

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

func (x XPath) Nth(n int) XPath

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

func (x XPath) Or(predicates ...XPath) XPath

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

func (x XPath) Parent() XPath

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

func (x XPath) PrecedingSibling(tag ...string) XPath

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

func (x XPath) String() 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

func (x XPath) WithAttr(attr string, value string) XPath

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

func (x XPath) WithAttrContains(attr string, value string) XPath

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

func (x XPath) WithAttrStartsWith(attr string, value string) XPath

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

func (x XPath) WithChildMatching(childPath XPath) XPath

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

func (x XPath) WithClass(class string) XPath

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

func (x XPath) WithID(id string) XPath

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

func (x XPath) WithText(value string) XPath

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

func (x XPath) WithTextContains(value string) XPath

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

func (x XPath) WithTextStartsWith(value string) XPath

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

Jump to

Keyboard shortcuts

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