Skip to content

JohanBrorson/webdriver-ui-mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebDriver UI Mapper Build Status codecov

WebDriver UI Mapper is a tool that maps JSON files with WebDriver locators to Locator java objects

Advantages of UI Maps

  • Easier maintenance by having a central location for UI objects instead of having them scattered throughout the tests.
  • Readability can be improved by giving the selectors human-readable names.
  • Possible to reuse the locators.

Maven Dependency

In your Maven project, add the following to your pom.xml file

    <dependency>
      <groupId>com.github.johanbrorson</groupId>
      <artifactId>webdriver-ui-mapper</artifactId>
      <version>[2.0.0, 3.0)</version>
    </dependency>

Example UI Map

[
  {
    "name": "searchInput",
    "selector": "//input[@name='q']",
    "method": "XPATH"
  },
  {
    "name": "searchButton",
    "selector": "btnG",
    "method": "NAME"
  }
]

Example Page Object Class

@LocatorFile(filePath = "locators/SearchPage.json")
public class SearchPage {
  private final WebDriver driver;
  @ByLocator private By searchInput;
  @ByLocator private By searchButton;

  public SearchPage(WebDriver driver) throws IOException {
    this.driver = driver;
    ByLocatorHelper.initInstanceVariables(this);
  }

  public void enterSearchText(String searchText) {
    driver.findElement(searchInput).clear();
    driver.findElement(searchInput).sendKeys(searchText);
  }

  public void clickSearchButton() {
    driver.findElement(searchButton).click();
  }
}

Releases

No releases published

Packages

No packages published

Languages