Get started

Assertions

List of assertions

CSTesting provides browser.assertThat(locator) for element assertions and browser.assertThat() for page assertions. They evaluate once (no auto-retry). To wait then assert, use waitForSelector first.

Element assertions

Assertion Description
assertThat(locator).isVisible()Element is visible
assertThat(locator).isEditable()Element is editable (not disabled, not readonly)
assertThat(locator).isEmpty()Element value or text is empty
assertThat(locator).isEnabled()Element is enabled
assertThat(locator).isDisabled()Element is disabled
assertThat(locator).contains(expected)Text or value contains the given string
assertThat(locator).hasText(expected)Element text matches or contains the expected text
assertThat(locator).containText(expected)Element text contains the given string
assertThat(locator).hasValue(expected)Input/select value equals the expected string
assertThat(locator).containValue(expected)Input/select value contains the given string
assertThat(locator).hasAttribute(name)Element has the DOM attribute (any value)
assertThat(locator).hasAttribute(name, value)Element attribute equals the expected value
assertThat(locator).count(n)Number of matching elements equals n
assertThat(locator).hasCount(n)Same as count(n) — list has exact number of matches

Page assertions

Assertion Description
assertThat().hasTitle(expected)Page title equals or contains the expected string
assertThat().hasURL(pattern)Page URL contains or matches pattern (* as wildcard)

Comparison with Playwright

Below is how CSTesting assertions map to a Playwright-style list. Supported = available in CSTesting; Not yet = not implemented.

Assertion Description CSTesting
assertThat(locator).isAttached()Element is attached to DOMNot yet — use waitForSelector then assert
assertThat(locator).isChecked()Checkbox is checkedNot yet
assertThat(locator).isDisabled()Element is disabledisDisabled()
assertThat(locator).isEditable()Element is editableisEditable()
assertThat(locator).isEmpty()Container is emptyisEmpty() (value or text)
assertThat(locator).isEnabled()Element is enabledisEnabled()
assertThat(locator).isFocused()Element is focusedNot yet
assertThat(locator).isHidden()Element is not visibleNot yet — use !isVisible() or assert after wait
assertThat(locator).isInViewport()Element intersects viewportNot yet
assertThat(locator).isVisible()Element is visibleisVisible()
assertThat(locator).containsClass()Element has specified CSS classesNot yet — use hasAttribute("class", ...)
assertThat(locator).containsText()Element contains textcontainText(expected)
assertThat(locator).hasAccessibleDescription()Accessible descriptionNot yet
assertThat(locator).hasAccessibleName()Accessible nameNot yet
assertThat(locator).hasAttribute()Element has a DOM attributehasAttribute(name) / hasAttribute(name, value)
assertThat(locator).hasClass()Element has a classNot yet — use hasAttribute("class", "foo") or check attribute
assertThat(locator).hasCount()List has exact number of childrenhasCount(n) / count(n)
assertThat(locator).hasCSS()Element has CSS propertyNot yet
assertThat(locator).hasId()Element has an IDNot yet — use hasAttribute("id", "myId")
assertThat(locator).hasJSProperty()Element has JS propertyNot yet
assertThat(locator).hasRole()Element has ARIA roleNot yet
assertThat(locator).hasText()Element matches texthasText(expected)
assertThat(locator).hasValue()Input has a valuehasValue(expected)
assertThat(locator).hasValues()Select has options selectedNot yet — use getSelectedValues() and assert in code
assertThat(locator).matchesAriaSnapshot()Matches ARIA snapshotNot yet
assertThat(page).hasTitle()Page has a titleassertThat().hasTitle(expected)
assertThat(page).hasURL()Page has a URLassertThat().hasURL(pattern)
assertThat(response).isOK()Response has OK statusNot yet — no response API in CSTesting

Usage

// Element assertions
browser.assertThat(browser.locator("h1")).isVisible();
browser.assertThat(browser.locator("#email")).isEditable();
browser.assertThat(browser.locator("button[type=submit]")).isEnabled();
browser.assertThat(browser.locator(".message")).containText("Success");
browser.assertThat(browser.locator("input[name=user]")).hasValue("alice");
browser.assertThat(browser.locator("li")).hasCount(5);

// Page assertions
browser.assertThat().hasTitle("Example Domain");
browser.assertThat().hasURL("https://example.com");
browser.assertThat().hasURL("**/dashboard");

All assertions throw AssertionError on failure.