Coder Social home page Coder Social logo

bharadwaj-pendyala / xcuitest-framework-for-testing-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sherbhachu/xcuitest-framework-for-testing-ios

0.0 1.0 0.0 18 KB

An example of how you could potentially implement Page Objects when testing iOS apps using XCTest / XCUITest in Swift

License: MIT License

Swift 100.00%

xcuitest-framework-for-testing-ios's Introduction

xcuitest-framework-for-testing-ios

An example of how you could potentially implement Page Objects when testing iOS apps using XCTest / XCUITest in Swift

The project was written using Swift v4 and XCode 9.2

Simply open up the 'TestApp' project and build. Then navigate to the 'BasicTests.swift' file to see an example test that implements the framework.

I have also added a little helper method to check when an element is in the 'selected' state.

The key concepts are the following;

Feature.swift (Found in... TestAppUITests > Feature > Feature.swift)

This file essentually handles the App state (including setup and teardown). This file is where you are required to explicitly add your screen objects (swift files) so that they can be loaded and referenced when writing your test functions.

App.swift (Found in... TestAppUITests > Library > Helpers > App.swift)

This file is the singleton in charge of creating XCUIApplication instance and managing the global app state. This is created so the same application instance can be used accross different pages of the app and the instance we are calling is the one that got launched.

SinfoniQATestCase.swift (Found in... TestAppUITests > Library > SinfoniQA > SinfoniQATestCase.swift)

This file acts as a sort of parent class, where the files are able to access other methods. You could actually get away with not having this and putting this capability elsewhere.

The file also includes a method that allows you to check the 'selected' state of an element. Particularly useful when wanting to check if a button/switch is in the state you want it to be in.

BaseScreen.swift (Found in... TestAppUITests > Screens > BaseScreen.swift)

This is essentially the blueprint for what all the other screens/pages will be modelled on. It contains a component that will allow for a 'trait' to be defined for each screen/page which adds a pre-condition/check to ensure you're on the screen/page that you think you're on, i.e....

firstViewControllerScreen.isScreenShown()

There is an initialiser that initialises the 'test' so that the screen/page can be initialised, i.e. allowing you to do...

bottomTabBar.navigateToTab(tab: .circle)

Example of a screen object...

import XCTest

class FirstViewScreen: BaseScreen {

    var title: XCUIElement!
    var subTitle: XCUIElement!

    override init() {
    super.init()
    
    title = app.staticTexts["First View"]
    subTitle = app.staticTexts["Loaded by FirstViewController"]
    
    screenTraits.append(title)
    }
}

Notes:

  • Inherit from BaseScreen
  • Define a variable for each element, force unwrapping it, since we know we will have a value for it...
  • Specify the element itself
  • Explicitly set a trait for this specific screen.

Example of what a test looks like...

import XCTest

class BasicTests: Feature {
    
    func testBottomTabBar() {
	XCTAssertTrue(bottomTabBar.tabBar.buttons.count == 2)
	bottomTabBar.navigateToTab(tab: .circle)
	XCTAssertTrue(secondViewControllerScreen.subTitle.label == "something")
    }
}

xcuitest-framework-for-testing-ios's People

Contributors

sherbhachu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.