Home Documentation Architecture Flow

B - Understanding the Architecture Flow

Learn how XPathy's layered architecture enables fluent, chainable locator building through context switching.

Architecture Overview

XPathy follows a layered architecture for building locators. Each starting point returns a builder object that knows how to handle that context:

  • .byText() → switches context to element text, allowing operations like .equals(), .contains(), .startsWith()
  • .byAttribute(attribute) → switches context to a specific attribute, enabling methods such as .equals(), .contains(), .startsWith(), .greaterThan(), .lessThan()
  • .byNumber() → converts inner text into a number, making numeric methods like .greaterThan(), .lessThan(), .between() available
  • .byStyle(styleAttribute) → inspects inline CSS properties inside the style attribute, and supports .equals(), .haveIt()

How Methods are Chained

When you call .equals(), .contains(), .startsWith(), etc., you are finalizing the condition on the selected context.

Example 1: Attribute Context

Code
XPathy locator = div.byAttribute(id).equals("header");

Flow:

  1. div sets the base tag
  2. .byAttribute(id) selects the id attribute
  3. .equals("header") finalizes the expression as //div[@id='header']

Example 2: Text Context

Code
XPathy locator = h2.byText().startsWith("Title");

Flow:

  1. h2 sets the base tag
  2. .byText() switches to the text node
  3. .startsWith("Title") produces //h2[starts-with(text(),'Title')]
Key Insight: This consistent flow applies to all contexts. You always begin with a tag or attribute, select the context with .byText(), .byAttribute(), .byNumber(), or .byStyle(), then finalize with methods like .equals(), .contains(), .startsWith(), .greaterThan(), or .between().

Complete Flow Examples

Number Context Flow

Code
XPathy locator = td.byNumber().greaterThan(100);

Flow:

  1. td sets the base tag
  2. .byNumber() converts text content to number context
  3. .greaterThan(100) creates condition //td[number(text()) > 100]

Style Context Flow

Code
XPathy locator = div.byStyle(backgroundColor).equals("#fff");

Flow:

  1. div sets the base tag
  2. .byStyle(backgroundColor) switches to inline style context
  3. .equals("#fff") checks for background color value
Result: The resulting XPathy object can be converted to a Selenium By object with .getLocator(), making it directly usable in your test automation scripts.