GithubHelp home page GithubHelp logo

uitestutils's Introduction

UITestUtils

CI Status Version License Platform

Utilities support write UI Testing for Swift

Local HTTP Server

Supporting local server by Embassy and Ambassador

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        let arguments = ProcessInfo.processInfo.arguments
        for argument in arguments {
            switch argument {
            case "UI_TESTING":
                ServicesAPI.shared.configureBaseURL("http://localhost:8080")
            default:
                ServicesAPI.shared.configureBaseURL("https://da31de14-b60e-4249-8921-0dcf5d5796ef.mock.pstmn.io")
            }
        }
        return true
}
router["/api/v2/users"] = DelayResponse(JSONResponse(handler: { _ -> Any in
    return [
        ["id": "01", "name": "john"],
        ["id": "02", "name": "tom"]
    ]
}))

JSONString response support

router["/api/v2/users"] = DelayResponse(JSONStringResponse(handler: { _ -> Any in
    return """
        {
          "acess_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
        }
    """
}))

UITest Utils

Page Object Model Design pattern

 func testInvalidPassword() {
        
        _ = loginPage
            .enterUsername("nvduc2910")
            .enterPassword("")
            .tapLoginButton()
            .then { _ in
                XCTAssert(loginPage.invalidPasswordAlert.exists)
            }
}

AccessId support

extension LoginController: UITestablePage {
    
    typealias UIElementType = UIElements.LoginUIElements
    
    func makeViewTestable() {
        self.makeViewTestable(self.usernameTextField, using: .userNameTextField)
        self.makeViewTestable(self.passwordTextField, using: .passwordTextField)
        self.makeViewTestable(self.loginButton, using: .loginButton)
    }
}

XCTest Extensions

open func expectToSee(_ element: XCUIElement,
                     within timeout: TimeInterval = 5,
                     _ file: StaticString = #file,
                     _ line: UInt = #line) {
      if element.exists {
        XCTAssertTrue(true)
      } else {
        XCTAssertTrue(element.waitForExistence(timeout: timeout), file: file, line: line)
      }
 }
open func expectNotToSee(_ element: XCUIElement,
                        within timeout: TimeInterval = 5,
                        _ file: StaticString = #file,
                        _ line: UInt = #line) {
      let date = Date().addingTimeInterval(timeout)
      var result = false
      repeat {
        result = !element.exists
      } while !result && Date().timeIntervalSince1970 < date.timeIntervalSince1970

      XCTAssertTrue(result, file: file, line: line)
}
open func enterText(_ text: String, into element: XCUIElement, _ file: StaticString = #file, _ line: UInt = #line) {
      if !element.hasFocus() {
        element.tap()
      }

      element.typeText(text)

      guard let value = element.value as? String else { return XCTFail(file: file, line: line) }
      XCTAssertEqual(value, text, file: file, line: line)
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

  • Mock real server and local HTTP Server
  • Login flow test
  • Book list test

Requirements

Installation

UITestUtils is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'UITestUtils'

Author

nvduc2910, [email protected]

License

UITestUtils is available under the MIT license. See the LICENSE file for more info.

uitestutils's People

Contributors

nvduc2910 avatar

Watchers

 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.