GithubHelp home page GithubHelp logo

confusedvorlon / hstestingbackchannel Goto Github PK

View Code? Open in Web Editor NEW
81.0 3.0 7.0 101 KB

Send notifications directly from your UITesting classes to your running app.

License: MIT License

Objective-C 91.24% Ruby 8.76%

hstestingbackchannel's Introduction

Backchannel for UITesting.

Snapshot is awesome.

Now it uses UI Testing.

UI Testing is massively better than UI Automation - but sometimes, you just want to cheat.

HSTestingBackchannel gives you a simple method to send messages from your UITesting tests directly to your running app in the form of notifications.

Installation

Install with CocoaPods

pod 'HSTestingBackchannel', :configuration => 'Debug'

# Dependency of HSTestingBackchannel - include this line to install it only in debug
pod 'GCDWebServer', :configuration => 'Debug'

Usage

1. In your App Delegate, install the helper

#if DEBUG
    import HSTestingBackchannel
#endif

And then, in application(_:didFinishLaunchingWithOptions:):

#if DEBUG
    HSTestingBackchannel.installReceiver()
#endif

2. Send notifications from your UITesting class

HSTestingBackchannel.sendNotification("SnapshotTest")

or

HSTestingBackchannel.sendNotification("SnapshotTest", with: ["aKey": "aValue"])

3. Respond to notifications within your app

#if DEBUG
    NotificationCenter.default.addObserver(
        forName: NSNotification.Name("SnapshotTest"),
        object: nil,
        queue: .main) { _ in
            // Do Something
    }) 
#endif

Bonus - Copy dummy files to the Simulator

Within a test method (or in setUp), call something like

HSTestingBackchannel.installFiles(from: "..pathTo/fastlane/DummyImages",
                                    to: HSTestingResources)

This will install the contents of DummyImages in the resources folder of your running app. You can also install directly to the Documents directory in the app.

Multiple Simultaneous Simulators

By default, Fastlane now runs multiple simulators simultaneously. This means you need to make sure that the server for each simulator is running on a different test.

Use the setup method to do the following

let app = XCUIApplication()

HSTestingBackchannel.port = UInt.random(in: 8000...60000)
app.launchArguments.append(
    contentsOf: ["-HSTestingBackchannelPort", "\(HSTestingBackchannel.port)"])

Snapshot.setupSnapshot(app, waitForAnimations: true)

app.launch()

How it works

HSTestingBackchannel installs a web server in your main app (GCDWebServer).

You simply send requests directly to that - and it recognises them and broadcasts NSNotifications

hstestingbackchannel's People

Contributors

antiraum avatar confusedvorlon avatar janpio avatar thompsonate avatar wolfgangd avatar zeveisenberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hstestingbackchannel's Issues

Xcode 9 concurrent_simulators

With Xcode 9, snapshot can run multiple simulators concurrently (concurrent_simulators).
But when this is enabled (as it is by default), HSTestingBackchannel sends its notifications only to one simulator, all others don't receive anything.

Detect UI Testing mode at compilation time in Swift

Is there a way to detect UI Testing mode at compilation time in Swift App Delegate?

I have successfully used HSTestingBackchannel in Swift with a bridging header and by detecting it at run time.

In XCTestCase subclass:

let app = XCUIApplication()
app.launchArguments = ["-testMode"]
app.launch()

In App Delegate:

if CommandLine.arguments.contains("-testMode")
{
    HSTestingBackchannel.installReceiver()
}

But it appears that the app is run in the Release configuration, so I can't set a preprocessor macro to distinguish it from a real release. In the scheme, Test is set to Debug, but that seems to apply to the XCTestCase code, not the app itself when launched in UI Testing mode.

I fear that importing HSTestingBackchannel in a release configuration will be detected and rejected by Apple at app review.

Question - 2 way communication

Is it possible to send a message back from the app to the UI test target? Currently I'm successfully doing messaging from the UI to the app but would love to do the other way around as well....

Latest podspec not on CocoaPods

Hi,

I tried using this repo with Snapshot and found out my tests were freezing because of the flag for port numbers. This was fixed in version 1.3.0, but CocoaPods is still hosting 1.2.2. I fixed it by cloning the repo and using a :path specifier in my Podfile. Maybe I was doing something wrong, but if not could you please publish version 1.3.0 on CocoaPods?

-Chris

Consider Documentation for installFilesFrom

Correct me if I'm wrong, but files should be in the target's "Copy Bundle Resources" and then they're accessible via:

        let bundle = NSBundle(forClass: self.dynamicType)
        let path = bundle.resourcePath! + "/" + AppConstants.UITesting.DemoCSVFilename
        XCTAssertTrue(NSFileManager.defaultManager().fileExistsAtPath(path))
        HSTestingBackchannel.installFilesFrom(path, to: HSTestingDocuments)

Crash in installReceiver()

Consistently crashes when initializing HSTestingBackchannel. The web server is being deallocated when the HSTestingBackchannel initializer returns.

Screen Shot 2021-08-24 at 9 56 39 PM

Screen Shot 2021-08-24 at 10 01 53 PM

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.