Skip to content

FxScreenGraph and XCUITest

No-Jun Park edited this page Jun 15, 2017 · 2 revisions

Overview

When writing a XCUITest, most of the test actions are about navigating within Firefox iOS app. Defining these actions individually on each test is cumbersome, and leads to a lot of duplicated code. If the app's UI is updated, each tests would need to be updated individually as well. There should be a smarter way of doing the UI navigation, and it would be better if we can just define the current state and the desired end state for the XCUITest to automatically navigate to the intended UI page.

Hence the screengraph.

Idea

Basically it is an implementation of the graph network. Each UI page can be defined as a node, and each node has information regarding where it can go to from the current node. Each node's information can be defined with createScene() method.

For example,

    map.createScene(NewPrivateTabScreen) { scene in
       scene.tap(app.textFields["url"], to: URLBarOpen)
       scene.tap(app.buttons["TabToolbar.menuButton"], to: NewTabMenu)
       scene.tap(app.buttons["URLBarView.tabsButton"], to: PrivateTabTray)

    scene.noop(to: HomePanelsScreen)
}

says the following:

  • In New Private Tab Screen, tapping url field goes to URLBarOpen node
  • Tapping menuButton goes to New Tab Menu node
  • Tapping tabsButton goes to PrivateTabTray node

There are also instances where it's not easy to define as a node, like creating a new tab.

func createNewTab() {
    self.goto(NewTabMenu)
    let app = XCUIApplication()
    app.collectionViews.cells["NewTabMenuItem"].tap()
    self.nowAt(NewTabScreen)
}

Above code does the following:

  • Go to New Tab Menu UI
  • Tap Tab Menu Item button
  • Inform screengraph that we're now in NewTabScreen node.

In order to use screengraph, a navigator object that 'traverses' the graph need to be instantiated in the beginning, like navigator = createScreenGraph(app).navigator(self) . Then, use goto() call to see the desired UI state. For example, simply calling navigator.goto(BrowserTabMenu) will make the test to open the Browser Tab Menu, by following the logic inside the FxScreenGraph.swift.

It is strongly recommended to use FxScreenGraph for your XCUITest, and make updates to FxScreenGraph if there is a new UI change.

Clone this wiki locally