Giter Site home page Giter Site logo

subito-it / sbtuitesttunnel Goto Github PK

View Code? Open in Web Editor NEW
331.0 331.0 76.0 4.69 MB

Enable network mocks and more in UI Tests

License: Other

Ruby 0.81% Objective-C 76.63% Swift 22.14% C 0.10% Objective-C++ 0.31%
cocoapods network-monitoring stub testing-tools ui-automated-tests xcode xcodebuild xctest xcuitest

sbtuitesttunnel's Introduction

SBTUITestTunnel

CI

Version License Platform Swift Package Manager

Overview

Apple introduced a new UI Testing feature starting from Xcode 7 that is, quoting Will Turner on stage at the WWDC, a huge expansion of the testing technology in the developer tools. The framework is easy to use and the integration with the IDE is great however there is a major problem with the way tests are launched. Testing code runs as a separate process which prevents to directly share data with the app under test making it hard to do things like dynamically inject data or stub network calls.

SBTUITestTunnel extends UI testing functionality allowing to dynamically:

  • stub network calls
  • download/upload files from/to the app's sandbox
  • monitor network calls
  • rewrite network calls
  • block cookies
  • interact with NSUserDefaults
  • define custom blocks of codes executed in the application target
  • fine grain fast-scrolling in table/collection/scroll views
  • CLLocationManager stubbing
  • UNUserNotificationCenter stubbing

The library supports concurrent parallel testing, so multiple Simulators can be used at once.

The library consists of two separated components which communicate with each other, one to be instantiate in the application's target and the other in the testing target.

Should I use this?

SBTUITestTunnel is intended to extend Apple's XCTest framework, not to replace it. It all boils down to a single subclass of XCUIApplication which comes with the additional features listed above, so it is very easy to integrate with your existing testing code.

Documentation

  • Installation: Describes how to install the library
  • Setup: Describes how to integrate the library in your code
  • Usage: Describes how to use the library
  • Example: Describes how to setup and use the example app

Additional resources?

We made additional resources available to improve the UI Testing experience:

  • Mendoza: parallelize UI tests over multiple physical machines
  • Cachi: parse Xcode's 11 .xcresult bundles
  • SBTUITestTunnelHost: access the mac host from your test target

Thanks

Kudos to the developers of the following pods which we use in SBTUITestTunnel:

Contributions

Contributions are welcome! If you have a bug to report, feel free to help out by opening a new issue or sending a pull request.

Authors

Tomas Camin (@tomascamin)

License

SBTUITestTunnel is available under the Apache License, Version 2.0. See the LICENSE file for more info.

sbtuitesttunnel's People

Contributors

acecilia avatar ahmedos avatar ahmedsalah196 avatar alvar-bolt avatar andyfinnell avatar antigp avatar ashraf-ali-aa avatar atom-wintermute avatar cameroncooke avatar cyhsutw avatar egorkomarov avatar francybiga avatar jszumski avatar kaomte avatar lechuckcaptain avatar lyricsboy avatar navartis avatar plu avatar ryan-noths avatar tcamin avatar tinder-maxwellelliott avatar tinder-owenthomas 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

sbtuitesttunnel's Issues

Running tests on different devices

@tcamin I was wondering how are you run tests on specific device types i.e on iPhone and iPad without creating different test targets, in the blog post http://bytes.schibsted.com/year-ui-testing-xctest/ it just shows a snippet of code.

The current implementation I have done in the UI framework is to check the device type and fail the test if it does not match the requirement, I have not seen any way to skip the test in the XCUI framework

    private func checkTestCompatibility() {
        if app.isRunningOnIPhone {
            guard userFlow.contains([.phone]) else {
                XCTFail("Skipping iPad Test")
                return
            }
        } else {
            guard userFlow.contains([.tablet]) else {
                XCTFail("Skipping iPhone Test")
                return
            }
        }
    }

Data race in `sendSynchronousRequestWithPath:params:`

WARNING: ThreadSanitizer: data race (pid=695)
  Read of size 8 at 0x7d0c0000c9b8 by thread T2:
    #0 __Block_byref_object_dispose_ <null>:189 (SBTUITestTunnel+0x00000000a42e)
    #1 _Block_object_dispose <null>:152 (libsystem_blocks.dylib+0x000000000c8e)
    #2 _Block_release <null>:152 (libsystem_blocks.dylib+0x000000000951)

  Previous write of size 8 at 0x7d0c0000c9b8 by thread T15:
    #0 __80-[SBTUITunneledApplication sendSynchronousRequestWithPath:params:assertOnError:]_block_invoke.221 <null>:189 (SBTUITestTunnel+0x00000000a58f)
    #1 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke <null>:170 (CFNetwork+0x0000000226af)
    #2 _dispatch_client_callout <null>:147 (libdispatch.dylib+0x00000002512d)

  Location is heap block of size 48 at 0x7d0c0000c990 allocated by main thread:
    #0 malloc <null>:185 (libclang_rt.tsan_iossim_dynamic.dylib+0x00000004054a)
    #1 _Block_object_assign <null>:152 (libsystem_blocks.dylib+0x000000000b62)
    #2 _Block_copy <null>:152 (libsystem_blocks.dylib+0x0000000008b2)
    #3 -[SBTUITunneledApplication sendSynchronousRequestWithPath:params:] <null>:189 (SBTUITestTunnel+0x00000000a764)
    #4 -[SBTUITunneledApplication performCustomCommandNamed:object:] <null>:189 (SBTUITestTunnel+0x000000008d69)
    #5 (redacted)
    #6 (redacted)
    #7 (redacted)
    #8 (redacted)
    #9 (redacted)
    #10 (redacted)
    #11 (redacted)
    #12 (redacted)
    #13 -[CCIStepsManager executeStep:inTestCase:] <null>:181 (Cucumberish+0x00000000dbf8)
    #14 executeSteps <null>:181 (Cucumberish+0x00000001390f)
    #15 __executeScenario_block_invoke <null>:181 (Cucumberish+0x000000013cf4)
    #16 -[Cucumberish executeAroundHocksWithScenario:executionBlock:] <null>:181 (Cucumberish+0x00000000fd70)
    #17 executeScenario <null>:181 (Cucumberish+0x000000011a3b)
    #18 __invoking___ <null>:180 (CoreFoundation+0x00000007e05b)

  Thread T2 (tid=5434, running) created by thread T-1
    [failed to restore the stack]

  Thread T15 (tid=6805, running) created by thread T-1
    [failed to restore the stack]

SUMMARY: ThreadSanitizer: data race (SBTUITestTunnel+0xa42e) in __Block_byref_object_dispose_
==================

Because it's a release build I'm not sure which property is racing yet. Looking into it, but you might be able to see it as well.

Data race on startupBlockCompleted

WARNING: ThreadSanitizer: data race (pid=23574)
  Write of size 1 at 0x7d080004a0b8 by thread T12:
    #0 __65-[SBTUITunneledApplication launchTunnelWithOptions:startupBlock:]_block_invoke <null>:166 (SBTUITestTunnel+0x0000000051a6)
    #1 __tsan::invoke_and_release_block(void*) <null>:162 (libclang_rt.tsan_iossim_dynamic.dylib+0x00000005c48b)
    #2 _dispatch_client_callout <null>:149 (libdispatch.dylib+0x00000002512d)

  Previous read of size 1 at 0x7d080004a0b8 by main thread:
    #0 -[SBTUITunneledApplication launchTunnelWithOptions:startupBlock:] <null>:166 (SBTUITestTunnel+0x000000004dee)
    #1 <redacted>
    #2 <redacted>
    #3 <redacted>
    #4 <redacted>
    #5 executeScenario <null>:158 (Cucumberish+0x00000001180a)
    #6 __invoking___ <null>:182 (CoreFoundation+0x00000007e05b)

  Location is heap block of size 32 at 0x7d080004a0a0 allocated by main thread:
    #0 malloc <null>:162 (libclang_rt.tsan_iossim_dynamic.dylib+0x00000004054a)
    #1 _Block_object_assign <null>:154 (libsystem_blocks.dylib+0x000000000b62)
    #2 _Block_copy <null>:154 (libsystem_blocks.dylib+0x0000000008b2)
    #3 -[SBTUITunneledApplication launchTunnelWithOptions:startupBlock:] <null>:166 (SBTUITestTunnel+0x000000004daf)
    #4 <redacted>
    #5 <redacted>
    #6 <redacted>
    #7 <redacted>
    #8 executeScenario <null>:158 (Cucumberish+0x00000001180a)
    #9 __invoking___ <null>:182 (CoreFoundation+0x00000007e05b)

  Thread T12 (tid=6337350, running) created by thread T-1
    [failed to restore the stack]

SUMMARY: ThreadSanitizer: data race (SBTUITestTunnel+0x51a6) in __65-[SBTUITunneledApplication launchTunnelWithOptions:startupBlock:]_block_invoke

startupBlockCompleted in launchTunnelWithOptions:startupBlock: is written to on one thread while possibly being read from in another thread.

Display all network request

It would be useful to display list all network request the flows through SBTUITestTunnel and whether if is it being mocked out. the command should be available via po print in xcode

Example

po sbtuitest.displayAllrequest()

Urls
www.test.com   -> mocked local data
www.test2.com
www.test3.com
www.test4.com -> mocked local data

Data race on responseId

WARNING: ThreadSanitizer: data race (pid=25681)
  Read of size 8 at 0x7d0c0007c378 by thread T20:
    #0 __Block_byref_object_dispose_ SBTUITunneledApplication.m:680 (SBTUITestTunnel+0x00000000ab85)
    #1 _Block_object_dispose <null>:154 (libsystem_blocks.dylib+0x000000000c8e)
    #2 _Block_release <null>:154 (libsystem_blocks.dylib+0x000000000951)

  Previous write of size 8 at 0x7d0c0007c378 by thread T19:
    #0 __66-[SBTUITunneledApplication sendSynchronousRequestWithPath:params:]_block_invoke.255 SBTUITunneledApplication.m:687 (SBTUITestTunnel+0x00000000ace6)
    #1 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke <null>:172 (CFNetwork+0x000000021c9f)
    #2 _dispatch_client_callout <null>:149 (libdispatch.dylib+0x00000002512d)

  Location is heap block of size 48 at 0x7d0c0007c350 allocated by main thread:
    #0 malloc <null>:258 (libclang_rt.tsan_iossim_dynamic.dylib+0x0000000404ba)
    #1 _Block_object_assign <null>:154 (libsystem_blocks.dylib+0x000000000b62)
    #2 _Block_copy <null>:154 (libsystem_blocks.dylib+0x0000000008b2)
    #3 -[SBTUITunneledApplication performCustomCommandNamed:object:] SBTUITunneledApplication.m:525 (SBTUITestTunnel+0x000000009237)

  Thread T20 (tid=6394786, running) created by thread T-1
    [failed to restore the stack]

  Thread T19 (tid=6393846, running) created by thread T-1
    [failed to restore the stack]

SUMMARY: ThreadSanitizer: data race SBTUITunneledApplication.m:680 in __Block_byref_object_dispose_

responseId in sendSynchronousRequestWithPath:params:.

Mock HTTP method

Hi, these methods don’t say where I can specify HTTP request method:
stubRequestsWithRegex
stubRequestsWithQueryParams
If I want to mock a request with POST/GET/DELETE... method, how can I do that?

Cannot start UI Test

I can see that application registers stubs and probably gets initialized. However, UI test module says it cannot connect... What could be the problem?

2016-12-27 09:17:04.915 [41163:320762] Multiple stubs registered for request <NSURLRequest: 0x60800000d210> { URL: https://app-measurement.com/a }! 2016-12-27 09:17:04.915[41163:320762] -> { SBTProxyURLProtocolBlockKey = "<__NSMallocBlock__: 0x608001467240>"; SBTProxyURLProtocolMatchingRuleKey = "URL: N/A\nQuery: .*get_user_info.*\nMethod: N/A"; SBTProxyURLProtocolStubResponse = "data-length: 318\nstatusCode: 200\nresponseTime: -1500.00\nheaders: {\n \"Content-Length\" = 318;\n \"Content-Type\" = \"application/json\";\n}"; } 2016-12-27 09:17:04.916[41163:320762] -> { SBTProxyURLProtocolBlockKey = "<__NSMallocBlock__: 0x60800146e080>"; SBTProxyURLProtocolMatchingRuleKey = "URL: N/A\nQuery: .*store.*\nMethod: N/A"; SBTProxyURLProtocolStubResponse = "data-length: 26\nstatusCode: 200\nresponseTime: -1500.00\nheaders: {\n \"Content-Length\" = 26;\n \"Content-Type\" = \"application/json\";\n}"; }

failed: caught "NSInternalInconsistencyException", "[SBTUITestTunnel] failed waiting app to be ready" ( 0 CoreFoundation 0x000000010ce66d4b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010c8c821e objc_exception_throw + 48 2 CoreFoundation 0x000000010ce6ae42 +[NSException raise:format:arguments:] + 98 3 Foundation 0x000000010c45d66d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195 4 SBTUITestTunnel 0x000000011e798134 -[SBTUITunneledApplication waitForServerReady] + 356 5 SBTUITestTunnel 0x000000011e797928 -[SBTUITunneledApplication launchTunnelWithOptions:startupBlock:] + 1240

Undefined symbols for architecture xxx: "_OBJC_CLASS_$_SBTUITestTunnelServer"

Hi, I try to use your library but i got an error when i follow your tutorial on README.md.

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_SBTUITestTunnelServer", referenced from:
      type metadata accessor for __ObjC.SBTUITestTunnelServer in AppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have the same issue on all simulators and devices.

More informations on my implementation :

  • XCode 8.0
  • Swift 2.3
  • iOS 10
  • Pods 1.1.0.rc.2 and Runpath Search Paths set
  • podfile:
target 'XXX' do
    pod 'SBTUITestTunnel/Server',   '~> 1.0'
end

target 'XXXTests' do

end

target 'XXXUITests' do
    pod 'SBTUITestTunnel/Client', '~> 1.0'
end
  • AppDelegate
import UIKit
import SBTUITestTunnel

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var appInitializer: AppInitializer?

    override class func initialize() {
        SBTUITestTunnelServer.takeOff()
        super.initialize()
    }

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        return true
    }

}

change host url

Is it possible to start SBTUITestTunnel on a specific ip address and port number rather than using localhost url endpoint, I wanted to use charles proxy to intercept the network requests for debugging purposes and not have to set the proxy in system settings. The way I envisioned this working is have 2 modes one the standard SBTUITestTunnel mock feature and the other is passing in a argument or setting in user defaults ip address and port of a proxy server and when you start the app SBTUITestTunnel forward the network requests to the specified ip address but if you run the ui tests it defaults back to the default the standard localhost.

Array JSON and stubRequests

Hi, thanks for your project.

I have in my project an array JSON, But how put this with stubRequests ?
Because is not a dictionary, and with returnJsonFileName can't load this format.
[ { color: "red", value: "#f00" }, { color: "green", value: "#0f0" }, { color: "blue", value: "#00f" }, { color: "cyan", value: "#0ff" }, { color: "magenta", value: "#f0f" }, { color: "yellow", value: "#ff0" }, { color: "black", value: "#000" } ]

ld: framework not found FXKeychain

Hey @tcamin ,

I have been trying to integrate this library to mock XCode UI test and followed the instructions here, https://github.com/Subito-it/SBTUITestTunnel#installation-cocoapods.I am working on a Swift project so I have imported the header files in *-Bridging-Header.h .When I try to build the project , it fails saying

ld: framework not found FXKeychain
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I can confirm that FXKeychain (1.5.3) is getting downloaded when I run pod install. Not sure what I am missing here.Some input might bail me out.

Xcode10 GM, iOS12 error when running unit tests on Device

NOTE: this works on the Simulator iPhone XR , just not on my iPhone 7 + running iOS 12 - is that just a KNOWN issue?

clang: error: linker command failed with exit code 1 (use -v to see invocation)

image

I tried a "Clean Build Folder"

app.launchTunnel() unrecognized selector sent to instance

Hello, I am using cocoapods to integrate this lib into my project. There is no problem on building, but when the test target is being executed, "unrecognized selector sent to instance" is reported on calling "app.launchTunnel()". It seems that the 'app' from the Objective-C category isn't loaded correctly. Do you have any idea how to resolve this issue ?

X-Code: Version 9.2 (9C40b)
Cocoapods: 1.3.1
SBTUITestTunnel: 3.0.4

Async waitForMonitoredRequestsMatching removed

Hi !

Why did you remove Async Wait for Requests Commands from .h file, is there any issues with these methods ? Found it pretty useful with matched requests in completion block

- (void)waitForMonitoredRequestsMatching:(nonnull SBTRequestMatch *)match
                                 timeout:(NSTimeInterval)timeout
                              iterations:(NSUInteger)iterations
                         completionBlock:(nonnull void (^)(BOOL timeout, NSArray<SBTMonitoredNetworkRequest *> * _Nonnull matchedRequests))completionBlock;

Set up requests before launchTunnel

Is it possible to set up the mock requests before the app has launched?
I am currently setting SBTUITestTunnel up using a configuration file to map requests to response data files but in the app there is a config file which is requested on launch and contains lists of various endpoints for the app to use. I am calling the mock setup immediately after calling app.launchTunnel() but because app.launchTunnel() waits for a response from the application under test so the mock setup is occurring too late to intercept the config call.

rewrite network response

Hi @tcamin is it possible to intercept a response request from a remote server and partially rewrite the response i.e

remote server:

{
    "time-epoch": "1519119705",
    "country": "GB"
}

Partial rewite
replace GB to IT

{
    "time-epoch": "1519119705",
    "country": "IT"
}

Regex wildcard

Hi is it possible to get the wildcard string value from a SBTRequestMatch request i.e SBTRequestMatch.url("myhost.com/v1/user/.*/info", should retrun the value from .*

pod install failing

Hi,

After cleaning the pods cache, pod install stop working:

The Error is as follow:
`
[!] Error installing SBTUITestTunnel
[!] /usr/local/bin/git clone https://github.com/Subito-it/SBTUITestTunnel.git /var/folders/5n/z7w81dgn1_1bnc_6578lbrth0000gp/T/d20180109-3161-1m3nwtv --template= --single-branch --depth 1 --branch 2.2.9

Cloning into '/var/folders/5n/z7w81dgn1_1bnc_6578lbrth0000gp/T/d20180109-3161-1m3nwtv'...
warning: Could not find remote branch 2.2.9 to clone.
fatal: Remote branch 2.2.9 not found in upstream origin
`

the Podfile has these definitios:

pod 'SBTUITestTunnel/Server', '> 2.2'
pod 'SBTUITestTunnel/Client', '
> 2.2'

Any idea what is wrong (remote missing) ?

PS:I tried updating everythings, ruby, cocoapods, etc.

Simulate no internet connection

Is it possible to simulate no internet connection with SBTUITestTunnel in XCUITests?
(Use case: during test execution I need to turn internet off, make several asserts, than turn it back on and make several asserts)
If so, where can I found relevant code or docs?
thx!

DEBUG name in project

Hi, thanks for your project.

In my project, we have rename the Build Configuration,
Exemple Debug is Staging and Release is Prod.

But now, we not go into the functions of your project.
You use define DEBUG throughout your project.

Have you solution for that ?

capture d ecran 2016-11-10 a 14 45 33

Scrolling does not work

During the UI tests, my view does not scroll to the correct line automatically.
Before adapting SBTUITestTunnel, it did do this.
Is there some setting I am missing?

Pass Headers from request

is it possible to support automatically passing in request headers to SBTUITunnel
i.e the app makes a request using the header/token X-OTT-Agent and SBTUITunnel uses those values automatically when mocking the network request

define custom DEBUG pre-processor macro

is there a way to use a custom DEBUG pre-processor macro without having to modify the pod files i.e use #if DEBUG_CONFIG instead for #if DEBUG, in my current project we are using custom DEBUG pre-processor.

View mock request via charles proxy

It would be really useful to view actual mock network request via Charles proxy currently it displays the example below, which is not very useful for debugging

http://localhost:8666/commandStubPathMatching
{
	"result": "stb-e3a8eb03ca99a84f37ffb5a4436c098d39e78609"
}

Support sending custom command

The client should be able to send a custom command (an NSString + NSDictionary) that would be handled by a registered block in the server.

After `app.terminate`, stubbed requests don't seem to work?

This has been the fastest networking stub library to get working! thanks!

However, i noticed an interesting bug:

We have to test a condition where if we quit the app with certain state, it should restart a certain way.

However, it seems that the stubbed calls simply are not working after we call one of:

app.terminate()

or

app.quit()

I see in app.terminate your subclass calls

[self sendSynchronousRequestWithPath:SBTUITunneledApplicationCommandShutDown params:nil assertOnError:NO];
    
    [self resetInternalState];

So i'd imagine that's why... however, even if i create the stubs again using

app.stubRequests(
            matching: SBTRequestMatch.init(url: "KukuiDVI/Login/DEMO"),
            response:SBTStubResponse(response: jsonData("LoginDemoAccount")!))

before I call

app.launchTunnel

again, it doesn't work.

Any ideas?

Our sample test looks something like this:

func testLoggedInButDidNotChooseEmployee_restartingAppClickedFirstEmplployee_goesToRepairOrderScreen() {
        // Given:
        loginToDemoAccountAtLoginScreen(app)

        XCTAssertTrue(app.navigationBars["Profiles"].exists)
        app.terminate()
        app.launch()

        // When:
        app.tables.cells.element(boundBy: 0).tap()

        // Then:
        XCTAssertTrue(app.navigationBars["Repair Orders"].exists)
    }

Stubbing example looks like half swift and half objective C

This line would not compile. It is at least missing a parenthesis.

let stubId = app.stubRequestsMatching:SBTRequestMatch(SBTRequestMatch.URL("google.com"), returnJsonDictionary: ["key": "value"], returnCode: 200, responseTime: SBTUITunnelStubsDownloadSpeed3G)

Issue when building on real devices while in SBTUITunnel framework

Hi there,

although I did the setup correctly and completely as per the documentation, the error below is always displaying:

ld: ‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/XCTest’ does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file ‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/XCTest’ for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
  • I cleaned the project
  • I added the preprocessor macros
  • I wrapped the code inside App delegate with #IF #DEBUG
  • The one difference is that the App code is in Objective-C not swift but I don't think this should matter, however the tests are written in Swift.

Please help me as this is a Blocker for me.

Thanks in advance!

Allow incoming network connections (OSX Firewall)

Do you want the application MyApp.app to accept incoming network connections?

Is there a way to get rid of these annoying pop-ups without disabling OSX Firewall altogether?

Since MyApp.app will be recreated every time I run my tests my preference will not be remembered the next time I run my tests.

`NSURLSession.dataTaskWithRequest` can be monitored, but the request body is not captured

When using NSURLSession.dataTaskWithRequest with a POST request, the request can have an HTTPBody. Even though this kind of request can be stubbed and monitored, the resulting SBTMonitoredNetworkRequest.request object will never have an HTTPBody set. In my UI tests, my request monitoring logic requires access to the HTTPBody, so this is a bit of a blocker.

The root cause seems to be that the HTTPBodyFix category on NSURLSession doesn't swizzle dataTaskWithRequest, but rather only uploadTaskWithRequest. To verify, I added the following swizzled method to that category, and was able to successfully retrieve the HTTPBody from SBTMonitoredNetworkRequest.request in my tests:

- (NSURLSessionDataTask *)swz_dataTaskWithRequest:(NSURLRequest *)request
                                completionHandler:(void (^)(NSData *data,
                                                            NSURLResponse *response,
                                                            NSError *error))completionHandler
{
    if ([request isKindOfClass:[NSMutableURLRequest class]] && request.HTTPBody) {
        [NSURLProtocol setProperty:request.HTTPBody forKey:SBTUITunneledNSURLProtocolHTTPBodyKey inRequest:(NSMutableURLRequest *)request];
    }

    return [self swz_dataTaskWithRequest:request completionHandler:completionHandler];
}

// And then in +load:
SBTTestTunnelInstanceSwizzle(self.class, @selector(dataTaskWithRequest:completionHandler:), @selector(swz_dataTaskWithRequest:completionHandler:));

There are multiple versions of dataTaskWithRequest, and I think they all need to be added to this category to capture the HTTPBody property if it was provided. If you'd like, I can try to prepare a PR -- it's basically just swizzling these additional methods that needs to be added, as far as I can tell.

SBT-Client Linking Error - Physical Device Only

I'm able to run on the simulator with no problem, but when I try to run on physical device I get:

Apple Mach-O Linker (id) Error

Unfortunately I can't share the project but was hoping you may have an idea of the cause based on it working on simulator but not on physical device.

Add a stub as a remore video file in AVPlayer

Hi

I want to add a stub (mp4 file) to a AVPlayerItem and play the video remotely. But I got the following error

Error Domain=AVFoundationErrorDomain Code=-11850 "Operation Stopped" UserInfo={NSLocalizedFailureReason=The server is not correctly configured., NSLocalizedDescription=Operation Stopped, NSUnderlyingError=0x6000016faac0 {Error Domain=CoreMediaErrorDomain Code=-12939 "byte range and no content length - error code is 206" UserInfo={NSDescription=byte range and no content length - error code is 206, NSURL=https://url-to-my-video/stub-download.mp4}}}

Could you help me to solve this please?

Use with Quick

I'd like to use SBTUITestTunnen with Quick (and Nimble) to make my tests more readable.
However, when I call app.launchTunnel() for the second time (in a different context) I get the following error:

caught "NSInternalInconsistencyException", "[SBTUITestTunnel] Failed to connect to client app {
    NSNetServicesErrorCode = "-72003";
    NSNetServicesErrorDomain = 10;
}"

Here's a simplified example:

class ExampleSpec: QuickSpec {
   override func spec() {
   	beforeSuite {
   		self.continueAfterFailure = false
   	}
   	describe("example") {
   		context("some context") {
   			it("should match my expectations") {
   				self.app.launchTunnel()
   				expect(true).to(beTrue())
   			}
   		}
   		context("some other context") {
   			it("should match my expectations") {
   				self.app.launchTunnel()
   				expect(true).to(beTrue())
   			}
   		}
   	}
   }
}

Any thought on how to use SBTUITestTunnel with Quick?

pod install new versions 3.1.0

Hi,
first, thanks for a great product.
is there any way to get new version 3.1.0 using cocopods?
now only 2.2.2 is available using pod install.

thanks!

Assertion failure on Travis CI...

Running on Travis CI, occasionally I get a timeout when starting the server. Is it possible to change the hard-coded 30 seconds to something user configurable? Or could there be some other reason its failing?

2017-06-05 21:29:55.521 XCTRunner[10943:32296] *** Assertion failure in -[SBTUITunneledApplication waitForServerUp], /Pods/SBTUITestTunnel/Pod/Client/SBTUITunneledApplication.m:154
2017-06-05 21:29:55.524 XCTRunner[10943:32296] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '[SBTUITestTunnel] failed to connect to client app.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010952ab0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000108f8f141 objc_exception_throw + 48
2 CoreFoundation 0x000000010952ecf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000108b293b6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 SBTUITestTunnel 0x000000011f17e9a4 -[SBTUITunneledApplication waitForServerUp] + 356
5 SBTUITestTunnel 0x000000011f17e5d3 __65-[SBTUITunneledApplication launchTunnelWithOptions:startupBlock:]_block_invoke + 67
6 libdispatch.dylib 0x000000010c648585 _dispatch_call_block_and_release + 12
7 libdispatch.dylib 0x000000010c669792 _dispatch_client_callout + 8
8 libdispatch.dylib 0x000000010c65168b _dispatch_root_queue_drain + 287
9 libdispatch.dylib 0x000000010c65150d _dispatch_worker_thread3 + 113
10 libsystem_pthread.dylib 0x000000010cad3616 _pthread_wqthread + 1299
11 libsystem_pthread.dylib 0x000000010cad30f1 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Crash on iOS 11 simulator

We have implemented SBTUITestTunnel in an app, and this code is working fine on the 10.3.1 simulator. When testing on the iOS 11 simulator we're getting a crash on the line [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; with EXC_BAD_ACCESS (code=1, address=0x10:

#32	0x0000000110b7f42c in -[SBTUITestTunnelServer processStartupCommandsIfNeeded] at /project/Pods/SBTUITestTunnel/Pod/Server/SBTUITestTunnelServer.m:664
#33	0x0000000110b788ca in -[SBTUITestTunnelServer takeOffOnce] at /project/Pods/SBTUITestTunnel/Pod/Server/SBTUITestTunnelServer.m:180
#34	0x0000000110b781ae in __32+[SBTUITestTunnelServer takeOff]_block_invoke at /project/Pods/SBTUITestTunnel/Pod/Server/SBTUITestTunnelServer.m:105
#35	0x0000000112f5b2b5 in _dispatch_client_callout ()
#36	0x0000000112f5c749 in dispatch_once_f ()
#37	0x0000000110b78148 in _dispatch_once [inlined] at /Users/mparks/Desktop/Xcode-9.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.0.sdk/usr/include/dispatch/once.h:84
#38	0x0000000110b7812d in +[SBTUITestTunnelServer takeOff] at /project/Pods/SBTUITestTunnel/Pod/Server/SBTUITestTunnelServer.m:104
#39	0x00000001104fd52f in static TestTunnel.setup() at /project/Company/TestTunnel.swift:18
#40	0x000000010bc5ec1d in AppDelegate.setupTestTunnel() at /project/Company-iOS/AppDelegate.swift:268
#41	0x000000010bc5dab2 in AppDelegate.init() at /project/Company-iOS/AppDelegate.swift:59

Any ideas?

UI Tests always fail when connecting to CI

Hi There,

I am integrating SBTUITestTunnel to our UI Tests, it is now working fine locally when running it from Xcode or even running them by fastlane.
The problem when integrating them to our CI (Bamboo), they always fail:

assertion failed NSInternalInconsistencyException > failed waiting for the app to be ready

App event loop idle notification not received, will attempt to continue.

App animations complete notification not received, will attempt to continue

II tried to disable the animations on the app and also I did the trick of letting the takeOff with false then with true after all the views are fully loaded and nothing seems to be working.

It even crashed the app many times on the CI.

any clue on this please because I need to use SBTUITestTunnel really on our App and can't seem to find a solution for this issue.

Thanks!

[NSInternalInconsistencyException] Failed waiting app to be ready

Hello, I am using SBTUITestTunnel v3.0.6 and I have a question, can I stubb requests in app running via bundle_id?

Example, if I run app with bundle:

   app = SBTUITunneledApplication(bundleIdentifier: "com.my.app")
   app.launchTunnel // >> NSInternalInconsistencyException

I have NSInternalInconsistencyException:

[SBTUITestTunnel] Failed waiting app to be ready

(SBTRequestMatch) For POST requests, query parameter is not functioning properly

When setting up an SBTRequestMatch object, the query parameter will not be taken into account when monitoring for POST requests.

For example:
let matchCriteria = SBTRequestMatch.init(url: "https://api.segment.io/v1/batch", query: ["THISDOESNOTEXIST"], method: "POST")

let matchCriteria = SBTRequestMatch.init(url: "https://api.segment.io/v1/batch", query: ["THISEXISTS"], method: "POST")

Both of these will return the same number of matches for requests. It doesn't seem to matter what is entered as the query parameter.

The only thing that succeeds (in failing) is modifying the URL or the method.

CURL support

A nice feature to have is the ability to make CURL requests to SBT to mock networks responses an example where this would be useful is when running tests with appium or other frameworks.

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.