Before anything, I want to list out the posts that I have read and tried implementing the answers from (avoiding duplicates):
I am working on an SDK and I have created some UI tests. I am trying not to connect to the backend systems and mocking them via a stubserver that runs in the local machine whilst testing. All requests must go to this server.
I have created an dummy app that will never be submitted to the App Store. Through this app I plan to test the SDK's screens. I followed the posts and articles above and included an exception to have insecure connections to my localhost server into the dummy app's Info.plist file. It looks like the following:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Yes I have allowed all kinds of exceptions. The network response does not complain about the app not having the exception for insecure connections to localhost but simply returns the following:
[Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSUnderlyingError=0x170248940 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=http://localhost:7878/endpoint, NSErrorFailingURLKey=http://localhost:7878/endpoint, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the server.}
[Timeline]: Timeline: { "Request Start Time": 510144201.835, "Initial Response Time": 510144201.860, "Request Completed Time": 510144201.860, "Serialization Completed Time": 510144201.860, "Latency": 0.025 secs, "Request Duration": 0.025 secs, "Serialization Duration": 0.000 secs, "Total Duration": 0.025 secs }
I look at the server logs and nothing is reported. I therefore assume that it does not hit the server entirely.
Any help would be appreciated. :)
Thanks
As @Teffi pointed out in the comments I was running the test on a device that did not have access to my localhost server running on my local machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With