Skip to content

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 ​

Trait

Example ​

ts
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 ​

Trait

Example ​

ts
Trait.attribute("#code", "readonly", "")

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 ​

string

Returns ​

Trait

Example ​

ts
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 ​

Trait

Example ​

ts
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 ​

Trait

Example ​

ts
Trait.disabled(CheckoutSel.submitButton)

enabled ​

enabled: (selector) => Trait

The complement of disabled - passes once selector is enabled.

Parameters ​

selector ​

string

Returns ​

Trait

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 ​

Trait

Example ​

ts
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 ​

Trait

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 ​

Trait

Example ​

ts
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 ​

Trait

Example ​

ts
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 ​

Trait

Examples ​

ts
Trait.text(".toast", "Saved")
ts
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 ​

Trait

Examples ​

ts
Trait.url({ pathname: "/inventory.html" })
ts
Trait.url({ hostname: "checkout.example.com", pathname: "/pay" })
ts
Trait.url({ pathname: "/users/:id" })   // named path params, matched structurally

value ​

value: (selector, expected) => Trait = valueEquals

Passes when a form field holds expected (fixed, or from mem).

Parameters ​

selector ​

string

expected ​

Expected<string>

Returns ​

Trait

Example ​

ts
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 ​

Trait

Examples ​

ts
verify: [Trait.url({ pathname: "/inventory.html" })]
ts
verify: [Trait.text(".shopping_cart_badge", "1")]

waygraph 0.18.3 (alpha) · Node 24+ · peer @playwright/test ^1.40.0 · syntax may change before 1.0: see what was removed