A set of utility classes to make interacting with web applications simpler through playwright-java
A custom implementation of the Playwright Locator with additional capabilities for interacting with web elementsExample: Select 'Third Value'
SmartElement.find(page, "select").selectOptionByLabel("Third Value");A utility class used to interact with web tables through a common approach
Name | Position | Office | Age |
---|---|---|---|
Airi Satou | Accountant | Tokyo | 33 |
Angelica Ramos | Chief Executive Officer (CEO) | London | 47 |
Ashton Cox | Junior Technical Author | San Francisco | 66 |
Get the table by its id 'example' and construct a SmartTable by defining how the table headers, rows and cells are located.
var table = SmartElement.find(page, "id=example").asTable("thead >> th", "tbody >> tr", "td");
var table = SmartTable.find(SmartElement.find(page, "id=example"), "thead >> th", "tbody >> tr", "td");Example: Find how old 'Ashton Cox' is
On the table object use the find row function with a map of the data you need to find within a row, on the returned row, call the getCellValue function for the 'Age' column
return table.findRow(Map.of("Name", "Ashton Cox")).getCellValue("Age");Example: Get multiple pages of table data
In addition to creating a SmartTable, define a Navigator which defines the locator for the table navigation bar and the locators for it's buttons (i.e next, previous, last, first). Upon calling the extract data function, this will automatically use the navigator to extract data across all pages of the table
return table.with(new SmartTable.Navigator(SmartElement.find(page, "id=example_paginate")).withPreviousPage("a:has-text(\"Previous\")").withNextPage("a:has-text(\"Next\")")).extractData();Example: Validate table data
For each row of data to validate, create a map of the columns/values to verify. A list of these maps can be passed into the validate table method which will return a ValidationResult object
List<Map<String, String>> expectedData = List.of( Map.of("Name", "Angelica Ramos", "Position", "Chief Executive Officer (CEO)", "Office", "London", "Age", "47"), Map.of("Name", "Airi Satou", "Position", "Accountant", "Office", "Tokyo", "Age", "33"));A utility class which allows for various types of validation, with results returned in a ValidationResult
table.validateTable(expectedData, Validate.Method.EQUALS).assertPass();
Example: Check if 'A', 'B', 'C' is in alphabetical order
Validate.that().listInAlphabeticalOrder(List.of("A", "B", "C"), true).assertPass();