class Bezel::Testing::Doc

A parsed HTML page for tests to query (Testing.html_response): its elements as a tree, found by a small selector language:

doc = Bezel::Testing::Doc.parse("<form action=\"/users\"><input name=\"user[email]\" value=\"a&amp;b\"></form>")
doc.has_element?("form[action=\"/users\"] input")   # => true
doc.select("input")[0].attr("value")                 # => "a&b"
doc.has_text?("nothing")                              # => false

The parser reads well-formed HTML as Bezel.html writes it, and is forgiving with the rest: void elements need no end tag, an end tag closes up to its element, entities are decoded, comments and the doctype are skipped, script, style, textarea and title hold text.

src/testing/doc.qz:21

Class methods

def self.parse(source: String) -> Bezel::Testing::Doc

The document of source.

src/testing/doc.qz:28

Methods

def root -> Bezel::Testing::Node

The document's root (a node without a tag).

src/testing/doc.qz:31

def select(selector: String) -> Array[Bezel::Testing::Node]

The elements selector matches, in document order.

src/testing/doc.qz:34

def at(selector: String) -> Bezel::Testing::Node?

The first element selector matches, or nil.

src/testing/doc.qz:37

def has_element?(selector: String) -> Bool

Whether an element matches selector.

src/testing/doc.qz:40

def text -> String

The text of the page, whitespace collapsed.

src/testing/doc.qz:43

def has_text?(text: String) -> Bool

Whether the page's text has text (whitespace collapsed in both).

src/testing/doc.qz:46