waygraph / Trait
Variable: Trait
Trait:
object
Defined in: src/engine/trait/trait.ts:23
Discoverable entry point for the built-in Trait factories - type Trait. in an editor to see url/text/visible offered, instead of needing to already know urlMatches/textEquals/visible exist as free functions to import by name. Same functions, just reachable off the type's own name - urlMatches/textEquals/visible stay exported too, so nothing that already imports them by name breaks.
Type Declaration
absent
absent: (
selector) =>Trait
Passes when nothing matches selector: the control is not offered at all.
Parameters
selector
string
Returns
Example
Trait.absent("[data-testid=archive]")attribute
attribute: (
selector,name,value) =>Trait=attributeEquals
Passes when selector's attribute name is exactly value.
Parameters
selector
string
name
string
value
string
Returns
Example
Trait.attribute("#code", "readonly", "")breadcrumbs
breadcrumbs: (
links) =>Trait
Passes when the breadcrumbs (the links matching links, in order) lead to the pages above this one in the site map, by their addresses: none missing, none extra. Needs the project's layouts loaded (run, demo and test load them).
Parameters
links
string
Returns
Example
verify: [Trait.breadcrumbs(CrumbsSel.link)]contains
contains: (
selector,expected) =>Trait=containsText
Passes when selector's text contains expected (fixed, or from mem).
Parameters
selector
string
expected
Expected<string>
Returns
Example
Trait.contains("main", (mem) => mem.get(User.email))disabled
disabled: (
selector) =>Trait
Passes when at least one element matching selector is currently disabled - a submit button greyed out until required fields are filled, a "Save" not yet re-enabled after a pending edit. A real, nameable feature state, not just static content or an action's result. Uses .first() for the same reason visible does. A point-in-time read via Playwright's own isDisabled() - no wait built in, so pair it with Trait.visible (or rely on verify's own natural timing right after resolve) if the element itself might not be on the page yet.
Parameters
selector
string
Returns
Example
Trait.disabled(CheckoutSel.submitButton)enabled
enabled: (
selector) =>Trait
The complement of disabled - passes once selector is enabled.
Parameters
selector
string
Returns
frameContains
frameContains: (
frameSelector,innerSelector,expected) =>Trait=frameContainsText
Passes when innerSelector's text inside frameSelector contains expected as a substring - the common QA shape for "the email says X somewhere" without needing to match the whole body verbatim (surrounding whitespace/markup in a real email template would otherwise break an exact-equality check).
Parameters
frameSelector
string
innerSelector
string
expected
string
Returns
Example
Trait.frameContains("#preview-html", "body", "Please verify your account")frameText
frameText: (
frameSelector,innerSelector,expected) =>Trait=frameTextEquals
textEquals, scoped to a frame - see frameVisible for why this needs its own factory.
Parameters
frameSelector
string
innerSelector
string
expected
string
Returns
frameVisible
frameVisible: (
frameSelector,innerSelector) =>Trait
visible, scoped to a frame (e.g. a mail catcher's message-preview iframe) instead of the top-level page. page.locator(selector) alone never reaches inside an iframe - Playwright requires frameLocator for that - so Trait.visible cannot express this on its own. frameSelector finds the iframe itself; innerSelector is resolved inside it.
Parameters
frameSelector
string
innerSelector
string
Returns
Example
Trait.frameVisible("#preview-html", 'a[href*="verify"]')matches
matches: (
selector,pattern) =>Trait=matchesText
Passes when selector's text matches pattern.
Parameters
selector
string
pattern
RegExp
Returns
Example
Trait.matches("[data-testid=code]", /^MCH-\d{4}$/)text
text: (
selector,expected) =>Trait=textEquals
Passes when selector's text (whitespace collapsed) is exactly expected - a fixed string, or one read from mem.
Parameters
selector
string
expected
Expected<string>
Returns
Examples
Trait.text(".toast", "Saved")Trait.text("[data-testid=code]", (mem) => mem.get(Machine.code))url
url: (
pattern) =>Trait=urlMatches
Passes once the page's URL matches pattern, waiting for real navigation. pattern is a structured URLPatternInit (the same shape the standard URLPattern Web API takes) - { pathname, hostname, search, hash, ... } - not a hand-written regex. Whichever components you don't specify default to "match anything" there, so a hybrid SPA tacking its own ?tab=cart&session=xyz onto the URL never breaks a pathname-only check - there's no separate flag for that, omission already means "don't care." Reach for a bespoke Trait with a raw regex only if a route genuinely needs pattern power URLPatternInit's fields can't express.
Parameters
pattern
URLPatternInit
Returns
Examples
Trait.url({ pathname: "/inventory.html" })Trait.url({ hostname: "checkout.example.com", pathname: "/pay" })Trait.url({ pathname: "/users/:id" }) // named path params, matched structurallyvalue
value: (
selector,expected) =>Trait=valueEquals
Passes when a form field holds expected (fixed, or from mem).
Parameters
selector
string
expected
Expected<string>
Returns
Example
Trait.value("#name", "Mixer")visible
visible: (
selector) =>Trait
Passes once at least one element matching selector is visible on the page, waiting for it to appear. Uses .first() so list selectors (e.g. one row per message/document) don't trip Playwright strict mode - the check means "something matching is visible", not "the selector is unambiguous".
Parameters
selector
string
Returns
Examples
verify: [Trait.url({ pathname: "/inventory.html" })]verify: [Trait.text(".shopping_cart_badge", "1")]