Skip to content

A set of utility classes to make interacting with web applications simpler through playwright-java

Notifications You must be signed in to change notification settings

Danphillipz/playwright-java-utility

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

playwright-java-utility

A set of utility classes to make interacting with web applications simpler through playwright-java

SmartElement

A custom implementation of the Playwright Locator with additional capabilities for interacting with web elements
Example: Select 'Third Value'
SmartElement.find(page, "select").selectOptionByLabel("Third Value");

SmartTable

A utility class used to interact with web tables through a common approach
NamePositionOfficeAge
Airi SatouAccountantTokyo33
Angelica RamosChief Executive Officer (CEO)London47
Ashton CoxJunior Technical AuthorSan Francisco66
Example: Construct a SmartTable
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"));
table.validateTable(expectedData, Validate.Method.EQUALS).assertPass();

Validate

A utility class which allows for various types of validation, with results returned in a ValidationResult
Example: Check if 'A', 'B', 'C' is in alphabetical order
Validate.that().listInAlphabeticalOrder(List.of("A", "B", "C"), true).assertPass();

About

A set of utility classes to make interacting with web applications simpler through playwright-java

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages