UI Automation for JVM - munichbughunter/SevenFacette GitHub Wiki

Introduction

The 7Facette web module is a browser automation library. It is basically a Selenium WebDriver wrapper inspired by Selenide. We build it in a pragmatic way. That means:

  • We use no Page Factory
  • No @FindBy annotation
  • Informative error messages
  • Automatic Driver Management
  • Straightforward Page Objects
  • Automatic screenshots on fail
  • Very easy to configure

Quick Tour - Configuration and Initialization

Installation

To use the 7Facette web module you also need the core module. With the core you can read the configuration. To getting the binaries, take a look at the Getting Started.

Configuration

The configuration can be made using the YML like in the core module. You can set the following configuration properties:

  • autoClose: default true. You can set it to false
  • baseUrl: Url of the system under test (SUT)
  • browserName: Name of the browser. Default is "chrome" you can set it to "firefox"
  • capabilities: List of desired capabilities
  • highlightBorder: Enable true (default) or disable false border highlight
  • highlightColor: The color for highlighting. Default is red
  • highlightSize: Line thickness in pixels, default "2px"
  • highlightStyle: The border-style property sets the style of an element’s four borders
  • pollingInterval: Element interaction, browser starts polling the page, default value is 0.1
  • remoteUrl: Make it possible to run tests with the RemoteDriver. 7Facette will automatically create RemoteDriver and run tests
  • reportDir: Report directory
  • screenSize: Set default screen size
  • startMaximized: Start browser maximized, default true
  • timeout: This means that will wait for condition until timeout exceeds. Here is the default 4 seconds

Usage

Simple example

 open(MyTestPage::new)
      .myTestMethode("10", "/", "2")
      .result.shouldHave(text("5"));

Error messages

failed while waiting 4 seconds
to assert text
for element located {By.cssSelector: #result}
reason: condition did not match
   expected: [5]
   actual: [10]

Page Object Support

Page objects is one of the pattern that is highly recommended to use in Test Automation projects.

class UploadPage extends Page {
  public UploadPage(Browser browser) {
    super(browser);
  }

  public String getUrl() {
    return "<SUT-URL>";
  }

  public FElement uploadFile = element(By.id("uploadfile_0"));
  public FElement submitButton = element(By.id("submitbutton"));
  public FElement message = element("#res");

  public UploadPage uploadImage() {
    this.submitButton.click();
    return this;
  }
}

Web page interaction

Test automation engineers spend a lot of time writing query selectors and element locators to find element on a given page. 7Facette provides a set of methods that helps to interact with page elements.

The element() function

The element function is the access point to the page content. It returns a FElement object that is a representation of WebElement that we interact with.

Using CSS locators

Function element() accepts a String parameter as a cssLocator find element by id = header

element("#header")

find element by css class = .paginator

element(".paginator")

find element by tag = footer

element("footer")

Using Webdriver’s By locator

For element() there is an equivalent signature where an instance of WebDriver’s By selector can be used instead of a String.

find element by id = header

element(By.id("#header"))

find element by css class = .paginator

element(By.className(".paginator"))

find element by tag = footer

element(By.tagName("footer"))

Using CSS selectors is the preferred way to use in 7Facette. For XPath selectors another convenience mechanism is provided.

Using XPATH locators

XPATH is a powerful element location mechanism that can be also used in 7Facette

find element by xpath = //div[@text()='name']

element(By.xpath("//div[@text()='name']"))

The FElement

The FElement class is a representation of WebElement, we want to interact with. The element() method returns lazy initialized element, so interaction with the real webElement starts when you call some method:

Example

// Element initialization, browser doesn’t poll the web page
FElement submitButton = element(By.id("submitbutton")); 

Element interaction, browser starts polling the page
this.submitButton.click();

Press Enter

element("#selector").pressEnter()

Upload File

FElement has useful methods that help to write tests.

Example file upload

element("input").uploadFile("/home/user/file.pdf")

Conditions

To make code more readable and concise 7Facette provide useful methods that allow to asset different conditions either for single element or collection of elements.

You can evaluate conditions using method listed below:

Positive:

  • should()

  • shouldHave()

  • shoulBe()

Negative:

  • shouldNot()

  • shouldNotHave()

  • shouldNotBe()

Example:

element("#h1").shouldHave(text("This is test"))

All should* methods evaluate condition with timeout. This means that should method will wait for condition true until timeout exceeds. By default timeout is 4 seconds, but it can be changed via Config (see Configuration section).

Wait until conditions

There are some cases when you need to wait for element before doing some actions. In such cases you should use waitUnit() method:

element(".spinner_button").waitUntil(visible, 6000).click()

WaitUntil will evaluate condition until custom timeout exceeds.

⚠️ **GitHub.com Fallback** ⚠️