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 DOM | Not yet — use waitForSelector then assert |
assertThat(locator).isChecked() | Checkbox is checked | Not yet |
assertThat(locator).isDisabled() | Element is disabled | ✓ isDisabled() |
assertThat(locator).isEditable() | Element is editable | ✓ isEditable() |
assertThat(locator).isEmpty() | Container is empty | ✓ isEmpty() (value or text) |
assertThat(locator).isEnabled() | Element is enabled | ✓ isEnabled() |
assertThat(locator).isFocused() | Element is focused | Not yet |
assertThat(locator).isHidden() | Element is not visible | Not yet — use !isVisible() or assert after wait |
assertThat(locator).isInViewport() | Element intersects viewport | Not yet |
assertThat(locator).isVisible() | Element is visible | ✓ isVisible() |
assertThat(locator).containsClass() | Element has specified CSS classes | Not yet — use hasAttribute("class", ...) |
assertThat(locator).containsText() | Element contains text | ✓ containText(expected) |
assertThat(locator).hasAccessibleDescription() | Accessible description | Not yet |
assertThat(locator).hasAccessibleName() | Accessible name | Not yet |
assertThat(locator).hasAttribute() | Element has a DOM attribute | ✓ hasAttribute(name) / hasAttribute(name, value) |
assertThat(locator).hasClass() | Element has a class | Not yet — use hasAttribute("class", "foo") or check attribute |
assertThat(locator).hasCount() | List has exact number of children | ✓ hasCount(n) / count(n) |
assertThat(locator).hasCSS() | Element has CSS property | Not yet |
assertThat(locator).hasId() | Element has an ID | Not yet — use hasAttribute("id", "myId") |
assertThat(locator).hasJSProperty() | Element has JS property | Not yet |
assertThat(locator).hasRole() | Element has ARIA role | Not yet |
assertThat(locator).hasText() | Element matches text | ✓ hasText(expected) |
assertThat(locator).hasValue() | Input has a value | ✓ hasValue(expected) |
assertThat(locator).hasValues() | Select has options selected | Not yet — use getSelectedValues() and assert in code |
assertThat(locator).matchesAriaSnapshot() | Matches ARIA snapshot | Not yet |
assertThat(page).hasTitle() | Page has a title | ✓ assertThat().hasTitle(expected) |
assertThat(page).hasURL() | Page has a URL | ✓ assertThat().hasURL(pattern) |
assertThat(response).isOK() | Response has OK status | Not 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.