Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. func testThatNetworkAfterEvent() {
  2. // Use SBTUITunneledApplication instead of XCUIApplication
  3. let app = SBTUITunneledApplication()
  4. app.launchTunnelWithOptions([SBTUITunneledApplicationLaunchOptionResetFilesystem]) {
  5. // do additional setup before the app launches
  6. // i.e. prepare stub request, start monitoring requests
  7. }
  8.  
  9. app.monitorRequestsWithRegex("(.*)myserver(.*)") // monitor all requests containing myserver
  10.  
  11. // 1. Interact with UI tapping elements that generate your events
  12.  
  13. // 2. Wait for events to be sent. This could be determined from the UI (a UIActivitiIndicator somewhere in your app?) or ultimately if you have no other option with an NSThread.sleepfortimeinterval
  14.  
  15. // 3. Once ready flush calls and get the list of requests
  16. let requests: [SBTMonitoredNetworkRequest] = app.monitoredRequestsFlushAll()
  17.  
  18. for request in requests {
  19. let requestBody = request.request!.HTTPBody // HTTP Body in POST request?
  20. let responseJSON = request.responseJSON
  21. let requestTime = request.requestTime // How long did the request take?
  22. }
  23. }
  24.  
  25. SBTUITestTunnelServer.registerCustomCommandNamed("myCustomCommandKey") {
  26. injectedObject in
  27. // this block will be invoked from app.performCustomCommandNamed()
  28. }
  29.  
  30. func testThatNetworkAfterEvent() {
  31. let app = ....
  32.  
  33. // at the right time
  34. app.performCustomCommandNamed("myCustomCommand", object: someObjectToInject)
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement