Record Class TableQuery

java.lang.Object
java.lang.Record
jp.co.moneyforward.autotest.actions.web.TableQuery
Record Components:
tableName - A locator string to specify a table within a Page object.
columnName - A column from which value is project to the result.
queryTerms - Condition terms to select rows in a table.
normalizer - A BinaryOperator to normalize an incomplete row.

public record TableQuery(String tableName, String columnName, List<TableQuery.Term> queryTerms, BiFunction<List<com.microsoft.playwright.Locator>, List<com.microsoft.playwright.Locator>, List<com.microsoft.playwright.Locator>> normalizer) extends Record

A class to query HTML table object as if it were an SQL relation. Note that this class is designed to select only one column.

void example() {
   try (Playwright playwright = Playwright.create()) {
      BrowserType chromium = playwright.chromium();
      try (Browser browser = chromium.launch(new BrowserType.LaunchOptions().setHeadless(false))) {
        Page page = browser.newPage();
        page.navigate(testTableResourcePath());
        //#js-ca-main-contents > table > thead

        Locator l = TableQuery.select("事業者・年度の切替")
                              .from("body > table")
                              .where(term("事業者名", "abc-154206"))
                              .normalizeWith(normalizerFunction())
                              .build()
                              .perform(page)
                              .getFirst();
}

Limitation:

  • The target HTML table must have unique headers (th) for all columns.
  • Only "equal" condition is supported.
  • Only conjunctions are supported.

In case you think these need to be improved, contact the development team of insdog.

See Also:
  • Constructor Details

    • TableQuery

      public TableQuery(String tableName, String columnName, List<TableQuery.Term> queryTerms, BiFunction<List<com.microsoft.playwright.Locator>, List<com.microsoft.playwright.Locator>, List<com.microsoft.playwright.Locator>> normalizer)
      Creates an instance of a TableQuery record class.
      Parameters:
      tableName - the value for the tableName record component
      columnName - the value for the columnName record component
      queryTerms - the value for the queryTerms record component
      normalizer - the value for the normalizer record component
  • Method Details

    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • select

      public static TableQuery.Builder select(String columnName)
      A method from which you can start building a query. A Builder class object, which holds columnName as a column to project to the result will be returned.
      Parameters:
      columnName - A column to be projected into the result.
      Returns:
      A builder object.
    • perform

      public List<com.microsoft.playwright.Locator> perform(com.microsoft.playwright.Page page)
      Performs the query on the given page.
      Parameters:
      page - A page object on which this query will be performed.
      Returns:
      A list of locators, each of whose enclosing row that satisfies the terms.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • tableName

      public String tableName()
      Returns the value of the tableName record component.
      Returns:
      the value of the tableName record component
    • columnName

      public String columnName()
      Returns the value of the columnName record component.
      Returns:
      the value of the columnName record component
    • queryTerms

      public List<TableQuery.Term> queryTerms()
      Returns the value of the queryTerms record component.
      Returns:
      the value of the queryTerms record component
    • normalizer

      public BiFunction<List<com.microsoft.playwright.Locator>, List<com.microsoft.playwright.Locator>, List<com.microsoft.playwright.Locator>> normalizer()
      Returns the value of the normalizer record component.
      Returns:
      the value of the normalizer record component