calabash / run_loop

The bridge between Calabash iOS and Xcode command-line tools like instruments and simctl.
Other
32 stars 41 forks source link

xcodebuild test-without-building causes iOS Simulator to relaunch _after_ user asks for simulator to be relaunched #618

Closed SergiyBeno closed 7 years ago

SergiyBeno commented 7 years ago

Environment:

Calabash 0.20.4 run_loop 2.4.1 iPhone 7 (10.3) (Simulator) Sierra 10.12.4 xcode-select --print-path: /Applications/Xcode.app/Contents/Developer xcodebuild -version: Xcode 8.3 Build version 8E162

{"device_family":"iPhone",
"outcome":"SUCCESS",
"server_port":37265,
"simulator_device":"",
"simulator":"CoreSimulator 375.20 - Device: iPhone 7 - Runtime: iOS 10.3 (14E269) - DeviceType: iPhone 7",
"app_name":"Xxxxxx",
"app_version":"5",
"screen_dimensions":{"native_scale":2,"sample":1,"height":1334,"width":750,"scale":2},
"git":{"revision":"dc15597","remote_origin":"git@github.com:calabash\/calabash-ios-server.git","branch":"master"},
"device_name":"xxxxxx’s Mac mini","4inch":false,
"app_id":"com.xxxxxx",
"form_factor":"iphone6",
"system":"x86_64",
"version":"0.20.4",
"iOS_version":"10.3",
"short_version_string":"8.13.2",
"ios_version":"10.3",
"iphone_app_emulated_on_ipad":false,
"model_identifier":"iPhone9,1",
"app_base_sdk":"iphonesimulator10.3"}

Steps to reproduce:

I have a feature file that contains 6 different scenarios and two @reinstall tags which I'm using simply to reinstall application under the test once at the beginning of the feature and the 2-nd time in the middle of that feature. Something like that:

Feature: test feature

@reinstall Scenario: 1st scenario GivenWhenThen

Scenario: 2nd scenario GWT

Scenario: 3rd scenario GWT

@reinstall Scenario: 4th scenario GWT

Scenario: 5th scenario GWT

Scenario: 6th scenario GWT

When I launch tests I see that simulator has been successfully launched and application is reinstalled. After that next 3 scenario are also successful passed. Problem appears when it comes to the 4th scenario and tries to reinstall application. I'm getting error like I have pasted below. On the screen I can see that DeviceAgent has been launched 2 times instead of regular single launch but still application is not brought to the foreground and test fails.

Terminal output:

Could not connect to the DeviceAgent service.

 device: #<Simulator: iPhone 7 (10.3) 74CE907B-BF6E-4C4E-B6C9-223BC76206B5 x86_64>
    url: http://127.0.0.1:27753/

 To diagnose the problem tail the launcher log file:

 $ tail -1000 -F /var/lib/jenkins/.calabash/iOSDeviceManager/logs/current.log

  (RuntimeError)
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/run_loop-2.4.1/lib/run_loop/device_agent/client.rb:1365:in `rescue in launch_cbx_runner'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/run_loop-2.4.1/lib/run_loop/device_agent/client.rb:1356:in `launch_cbx_runner'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/run_loop-2.4.1/lib/run_loop/device_agent/client.rb:271:in `launch'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/run_loop-2.4.1/lib/run_loop/device_agent/client.rb:147:in `run'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/run_loop-2.4.1/lib/run_loop.rb:113:in `run'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/calabash-cucumber-0.20.4/lib/calabash-cucumber/launcher.rb:408:in `block in new_run_loop'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/calabash-cucumber-0.20.4/lib/calabash-cucumber/launcher.rb:406:in `times'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/calabash-cucumber-0.20.4/lib/calabash-cucumber/launcher.rb:406:in `new_run_loop'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/calabash-cucumber-0.20.4/lib/calabash-cucumber/launcher.rb:365:in `relaunch'
 /private/var/lib/jenkins/workspace/iOS_regression_tests/ExternalTools/features/support/01_launch.rb:42:in `block in <top (required)>'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/core_ext/instance_exec.rb:25:in `instance_exec'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/core_ext/instance_exec.rb:25:in `block in cucumber_instance_exec'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/core_ext/instance_exec.rb:42:in `cucumber_run_with_backtrace_filtering'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/core_ext/instance_exec.rb:13:in `cucumber_instance_exec'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/rb_support/rb_hook.rb:15:in `invoke'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/runtime/before_hooks.rb:21:in `block (2 levels) in before_hooks'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/action.rb:23:in `execute'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/step.rb:31:in `execute'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/runner.rb:104:in `execute'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/runner.rb:51:in `execute'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/runner.rb:26:in `test_step'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/step.rb:16:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:26:in `block (3 levels) in describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:25:in `each'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:25:in `block (2 levels) in describe_to'
 /private/var/lib/jenkins/workspace/iOS_regression_tests/ExternalTools/features/support/01_launch.rb:59:in `block (2 levels) in <top (required)>'
 /var/lib/jenkins/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
 /var/lib/jenkins/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/timeout.rb:33:in `block in catch'
 /var/lib/jenkins/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/timeout.rb:33:in `catch'
 /var/lib/jenkins/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/timeout.rb:33:in `catch'
 /var/lib/jenkins/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/timeout.rb:106:in `timeout'
 /private/var/lib/jenkins/workspace/iOS_regression_tests/ExternalTools/features/support/01_launch.rb:58:in `block in <top (required)>'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/core_ext/instance_exec.rb:25:in `instance_exec'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/core_ext/instance_exec.rb:25:in `block in cucumber_instance_exec'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/core_ext/instance_exec.rb:42:in `cucumber_run_with_backtrace_filtering'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/core_ext/instance_exec.rb:13:in `cucumber_instance_exec'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/rb_support/rb_hook.rb:15:in `invoke'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/runtime/support_code.rb:129:in `block (2 levels) in find_around_hooks'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/around_hook.rb:16:in `execute'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/runner.rb:104:in `execute'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/runner.rb:51:in `execute'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/runner.rb:33:in `around_hook'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/around_hook.rb:11:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:106:in `block (2 levels) in compose_around_hooks'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/filters/prepare_world.rb:22:in `block in test_case'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/around_hook.rb:16:in `execute'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/runner.rb:104:in `execute'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/runner.rb:51:in `execute'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/runner.rb:33:in `around_hook'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/around_hook.rb:11:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:106:in `block (2 levels) in compose_around_hooks'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:107:in `compose_around_hooks'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:24:in `block in describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/runner.rb:18:in `test_case'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:23:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/filters/prepare_world.rb:11:in `test_case'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:23:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/filters/apply_around_hooks.rb:8:in `test_case'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:23:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/filters/apply_after_hooks.rb:5:in `test_case'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:23:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/filters/apply_before_hooks.rb:5:in `test_case'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:23:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/filters/apply_after_step_hooks.rb:8:in `test_case'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:23:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/filters/activate_steps.rb:11:in `test_case'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:23:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/filters/quit.rb:11:in `test_case'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/case.rb:23:in `describe_to'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/filters/locations_filter.rb:17:in `block in done'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/filters/locations_filter.rb:16:in `each'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/filters/locations_filter.rb:16:in `done'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/filter.rb:61:in `done'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/test/filters/tag_filter.rb:18:in `done'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/compiler.rb:23:in `done'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core/gherkin/parser.rb:39:in `done'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core.rb:29:in `parse'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-core-1.3.1/lib/cucumber/core.rb:18:in `compile'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/runtime.rb:68:in `run!'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/lib/cucumber/cli/main.rb:32:in `execute!'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/gems/cucumber-2.2.0/bin/cucumber:8:in `<top (required)>'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/bin/cucumber:22:in `load'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/bin/cucumber:22:in `<main>'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
 /var/lib/jenkins/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'

Simulator logs:

Apr 12 16:18:59 xxxxxxx-Mac-mini useractivityd[99812]: objc[99812]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x10f625cc0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x10c59f6f0). One of the two will be used. Which one is undefined.
Apr 12 16:18:59 xxxxxxx-Mac-mini AppleIDAuthAgent[99708]: objc[99708]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x10a8cbcc0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x1079cb6f0). One of the two will be used. Which one is undefined.
Apr 12 16:18:59 xxxxxxx-Mac-mini useractivityd[99812]: Irrecoverable error for useractivity connection
Apr 12 16:19:00 xxxxxxx-Mac-mini medialibraryd[99819]: [Service] Database already validated. Returning immediately.
Apr 12 16:19:00 --- last message repeated 1 time ---
Apr 12 16:19:00 xxxxxxx-Mac-mini tccd[99770]: [access] Refusing client without bundle identifier (/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/MusicLibrary.framework/Support/medialibraryd)
Apr 12 16:19:00 xxxxxxx-Mac-mini tccd[99770]: [access] Refusing TCCAccessRequest for service kTCCServiceAddressBook from invalid client with pid 99819
Apr 12 16:19:00 xxxxxxx-Mac-mini tccd[99770]: [access] Refusing client without bundle identifier (/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/MusicLibrary.framework/Support/medialibraryd)
Apr 12 16:19:00 xxxxxxx-Mac-mini tccd[99770]: [access] Refusing TCCAccessRequest for service kTCCServiceAddressBook from invalid client with pid 99819
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: Requesting launch of com.apple.test.DeviceAgent-Runner with options: {
        arguments =     (
            "-NSTreatUnknownArgumentsAsOpen",
            NO,
            "-ApplePersistenceIgnoreState",
            YES
        );
        environment =     {
            "DYLD_FRAMEWORK_PATH" = "";
            "DYLD_LIBRARY_PATH" = "";
            NSUnbufferedIO = YES;
            "XCODE_DBG_XPC_EXCLUSIONS" = "com.apple.dt.xctestSymbolicator";
            XCTestConfigurationFilePath = "/var/folders/0x/10v342cj4s7dsdk1c53c28kr000086/T/com.apple.dt.XCTest/02281199-9333-40D6-8CF1-D8D0187482F6/remote-container/tmp/DeviceAgent-02281199-9333-40D6-8CF1-D8D0187482F6.xctestconfiguration";
        };
        stderr = "/dev/ttys003";
        stdout = "/dev/ttys003";
        "wait_for_debugger" = 0;
    }
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: Beginning launch sequence for bundle 'com.apple.test.DeviceAgent-Runner'
        retryTimeout: 300.000000 (default write com.apple.CoreSimulatorBridge LaunchRetryTimeout <value>)
        bootTimeout: 300.000000 (default write com.apple.CoreSimulatorBridge BootRetryTimeout <value>)
        bootLeeway: 120.000000 (default write com.apple.CoreSimulatorBridge BootLeeway <value>)
        Note: Use 'xcrun simctl spawn booted defaults write <domain> <key> <value>' to modify defaults in the booted Simulator device.
    Simulator booted at: 2017-04-12 13:18:41 +0000
    Current time: 2017-04-12 13:19:02 +0000
    Within boot leeway: YES
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: Launch attempt #0 for bundle 'com.apple.test.DeviceAgent-Runner', have been trying to launch for 0 seconds. Modern launch services = YES
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: Got LSBundleProxy for 'com.apple.test.DeviceAgent-Runner', sequenceNumber 256, cacheGUID 183966D0-210C-4587-ABEF-82B0F8E85C60
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: [Common] [FBSSystemService][0xbde6] Sending request to open "com.apple.test.DeviceAgent-Runner"
Apr 12 16:19:02 xxxxxxx-Mac-mini assertiond[99716]: Submitted job with label: UIKitApplication:com.apple.test.DeviceAgent-Runner[0x37ae][99716]
Apr 12 16:19:02 xxxxxxx-Mac-mini SpringBoard[99711]: [com.apple.test.DeviceAgent-Runner] Bootstrap complete with label: UIKitApplication:com.apple.test.DeviceAgent-Runner[0x37ae][99716]
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: [Common] [FBSSystemService][0xbde6] Request successful: <BSProcessHandle: 0x7ff620f2a490; XCTRunner:99837; valid: YES>
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: Launch successful for 'com.apple.test.DeviceAgent-Runner'
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: Requesting launch of com.apple.test.DeviceAgent-Runner with options: {
        arguments =     (
            "-NSTreatUnknownArgumentsAsOpen",
            NO,
            "-ApplePersistenceIgnoreState",
            YES
        );
        environment =     {
            "DYLD_FRAMEWORK_PATH" = "";
            "DYLD_LIBRARY_PATH" = "";
            NSUnbufferedIO = YES;
            "XCODE_DBG_XPC_EXCLUSIONS" = "com.apple.dt.xctestSymbolicator";
            XCTestConfigurationFilePath = "/var/folders/0x/10v342cj4s7dsdk1c53c28kr000086/T/com.apple.dt.XCTest/1038A82C-9589-4C3E-AB59-2A12B2FF364F/remote-container/tmp/DeviceAgent-1038A82C-9589-4C3E-AB59-2A12B2FF364F.xctestconfiguration";
        };
        stderr = "/dev/ttys004";
        stdout = "/dev/ttys004";
        "wait_for_debugger" = 0;
    }
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: Beginning launch sequence for bundle 'com.apple.test.DeviceAgent-Runner'
        retryTimeout: 300.000000 (default write com.apple.CoreSimulatorBridge LaunchRetryTimeout <value>)
        bootTimeout: 300.000000 (default write com.apple.CoreSimulatorBridge BootRetryTimeout <value>)
        bootLeeway: 120.000000 (default write com.apple.CoreSimulatorBridge BootLeeway <value>)
        Note: Use 'xcrun simctl spawn booted defaults write <domain> <key> <value>' to modify defaults in the booted Simulator device.
    Simulator booted at: 2017-04-12 13:18:41 +0000
    Current time: 2017-04-12 13:19:02 +0000
    Within boot leeway: YES
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: Launch attempt #0 for bundle 'com.apple.test.DeviceAgent-Runner', have been trying to launch for 0 seconds. Modern launch services = YES
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: Got LSBundleProxy for 'com.apple.test.DeviceAgent-Runner', sequenceNumber 256, cacheGUID 183966D0-210C-4587-ABEF-82B0F8E85C60
Apr 12 16:19:02 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: [Common] [FBSSystemService][0xfc1] Sending request to open "com.apple.test.DeviceAgent-Runner"
Apr 12 16:19:02 xxxxxxx-Mac-mini XCTRunner[99837]: assertion failed: 16E195 14E269: libxpc.dylib + 64131 [624BAF4F-2E03-34F8-ACBA-970B04637786]: 0x7d
Apr 12 16:19:02 xxxxxxx-Mac-mini assertiond[99716]: client <BSProcessHandle: 0x7fbeb3704a70; SpringBoard:99711; valid: YES> HWM increased to 4 because of <BKProcessAssertion: 0x7fbeb360aa90; "Resume" (activation:inf); id:…DE723F090DC5>
Apr 12 16:19:02 xxxxxxx-Mac-mini assertiond[99716]: client <BSProcessHandle: 0x7fbeb3704a70; SpringBoard:99711; valid: YES> HWM increased to 5 because of <BKProcessAssertion: 0x7fbeb34165b0; "Deliver Message" (suspend:10s); id:…AAB0C1CC22CB>
Apr 12 16:19:02 xxxxxxx-Mac-mini XCTRunner[99837]: Running tests...
Apr 12 16:19:02 xxxxxxx-Mac-mini assertiond[99716]: client <BSProcessHandle: 0x7fbeb360ae50; testmanagerd:99722; valid: YES> HWM increased to 1 because of <BKProcessAssertion: 0x7fbeb360b5e0; "Developer testing" (backgroundUI:inf); id:…80F16169B0FA>
Apr 12 16:19:03 xxxxxxx-Mac-mini XCTRunner[99837]: Continuing to run tests in the background with task ID 1
Apr 12 16:19:03 xxxxxxx-Mac-mini assertiond[99716]: client <BSProcessHandle: 0x7fbeb36064d0; XCTRunner:99837; valid: YES> HWM increased to 1 because of <BKProcessAssertion: 0x7fbeb370a330; "Called by XCTRunner, from unknown method" (finishTask:180s); id:…83DD4066D478>
Apr 12 16:19:03 xxxxxxx-Mac-mini assertiond[99716]: client <BSProcessHandle: 0x7fbeb36064d0; XCTRunner:99837; valid: YES> HWM increased to 2 because of <BKProcessAssertion: 0x7fbeb3516cc0; "_UIRemoteKeyboard XPC disconnection" (finishTask:180s); id:…7A48B6F4AFB4>
Apr 12 16:19:03 xxxxxxx-Mac-mini assertiond[99716]: client <BSProcessHandle: 0x7fbeb36064d0; XCTRunner:99837; valid: YES> HWM increased to 3 because of <BKProcessAssertion: 0x7fbeb360b8c0; "snapshot-task" (finishTask:180s); id:…C25431CDA366>
Apr 12 16:19:03 xxxxxxx-Mac-mini assertiond[99716]: client <BSProcessHandle: 0x7fbeb36064d0; XCTRunner:99837; valid: YES> HWM increased to 4 because of <BKProcessAssertion: 0x7fbeb3516e20; "com.apple.uikit.applicationSnapshot" (finishTask:180s); id:…CC00461CDBCF>
Apr 12 16:19:03 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: [Common] [FBSSystemService][0xfc1] Request successful: <BSProcessHandle: 0x7ff620c0cfb0; XCTRunner:99837; valid: YES>
Apr 12 16:19:03 xxxxxxx-Mac-mini CoreSimulatorBridge[99717]: Launch successful for 'com.apple.test.DeviceAgent-Runner'
Apr 12 16:19:03 xxxxxxx-Mac-mini SpringBoard[99711]: [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Apr 12 16:19:03 --- last message repeated 1 time ---
Apr 12 16:19:03 xxxxxxx-Mac-mini com.apple.CoreSimulator.SimDevice.74CE907B-BF6E-4C4E-B6C9-223BC76206B5.launchd_sim[99694] (UIKitApplication:com.apple.test.DeviceAgent-Runner[0x37ae][99716][99837]): Service exited with abnormal code: 1

support/01_launch.rb

require 'calabash-cucumber/launcher'

module LaunchControl

  @@launcher = nil

  def self.launcher
    @@launcher ||= Calabash::Cucumber::Launcher.new
  end

  def self.launcher=(launcher)
    @@launcher = launcher
  end

  def self.target_is_simulator?
    self.launcher.simulator_target?
  end

  def self.target_is_physical_device?
    self.launcher.device_target?
  end

end

Before do |scenario|
  # ruby code not related to calabash or cucumber
  @launcher = LaunchControl.launcher
  scenario_tags = scenario.source_tag_names
  if scenario_tags.include?('@reinstall')
    ENV['RESET_BETWEEN_SCENARIOS'] = '1' if LaunchControl.target_is_simulator?
    if LaunchControl.target_is_physical_device?
      # ruby code not related to calabash or cucumber
      # ruby code not related to calabash or cucumber
    end
    # ruby code not related to calabash or cucumber
    # ruby code not related to calabash or cucumber
  else
    ENV['RESET_BETWEEN_SCENARIOS'] = '0' if LaunchControl.target_is_simulator?
  end
  unless scenario_tags.include?('@no_launch')
    @launcher.relaunch()
    wait_for do
      !query("*").empty?
    end
  end
end

AfterStep do |scenario|
end

After do |scenario|
  calabash_exit
  sleep 1.0
end

Around('@regression') do |scenario, block|
  Timeout.timeout(500) do
    block.call
  end
end
igorpakushin commented 7 years ago

+1 have the same issue

kutran commented 7 years ago

+1 for me too.

Terminal Output:

/Users/someuser/.rvm/gems/ruby-2.4.0/gems/edn-1.1.1/lib/edn/core_ext.rb:97: warning: constant ::Bignum is deprecated
Using the default, simulator and common profiles...
@keyboard
Feature: Typing on the Keyboard
In order to enter text like a user
As an app tester
I want Calabash to provide a Keyboard API

  Background: Navigate to the controls tab # features/keyboard.feature:7

  Could not connect to the DeviceAgent service.

  device: #<Simulator: iPhone 7 (10.3) 159E9C46-D20B-415C-89D2-79447298F679 x86_64>
     url: http://127.0.0.1:27753/

  To diagnose the problem tail the launcher log file:

  $ tail -1000 -F /Users/kutran/.calabash/iOSDeviceManager/logs/current.log

   (RuntimeError)
  ./features/support/01_launch.rb:19:in `launch'
  ./features/support/01_launch.rb:279:in `Before'
    Given I see the controls tab           # features/step_definitions/shared_steps.rb:1

  @travis
  Scenario: I should be able to type something                    # features/keyboard.feature:11
    Then I type "Hello"                                           # features/step_definitions/keyboard_steps.rb:9
    And the first responder text is "Hello"                       # features/step_definitions/keyboard_steps.rb:30
    And I dismiss the keyboard by tapping the keyboard action key # features/step_definitions/keyboard_steps.rb:19

Version:

{"device_family":"iPhone","outcome":"SUCCESS","server_port":37265,"simulator_device":"","simulator":"CoreSimulator 375.20 - Device: iPhone 7 - Runtime: iOS 10.3 (14E269) - DeviceType: iPhone 7","app_name":"CalSmoke-cal","app_version":"0.20.4","screen_dimensions":{"native_scale":2,"sample":1,"height":1334,"width":750,"scale":2},"git":{"revision":"dc15597","remote_origin":"git@github.com:calabash\/calabash-ios-server.git","branch":"master"},"device_name":"computer","4inch":false,"app_id":"sh.calaba.CalSmoke-cal","form_factor":"iphone 6","system":"x86_64","version":"0.20.4","iOS_version":"10.3","short_version_string":"0.20.4","ios_version":"10.3","iphone_app_emulated_on_ipad":false,"model_identifier":"iPhone9,1","app_base_sdk":"iphonesimulator10.3"}
jmoody commented 7 years ago

On the screen I can see that DeviceAgent has been launched 2 times instead of regular single launch but still application is not brought to the foreground and test fails.

I think the second launch is a result of the xcodebuild process exiting. In 2.4.0, we had to fallback on using xcodebuild test-without-building instead of an iOSDeviceManager (based on FBSimulatorControl) start_test solution.

Try this.

Before("@reinstall") do |scenario|
   RunLoop::CoreSimulator.quit_simulator
   sleep(5)
   RunLoop::CoreSimulator.quit_simulator
end

If that works, then we need to find a way of terminating the xcodebuild test-without-building process in such a way that the DeviceAgent is not launched a second time. We would like to preserve the ability to run N cucumber tests at once and not to go back to the only one instruments process days.

SergiyBeno commented 7 years ago

Thank you @jmoody for helping upon this issue. Sure, pushing changes and will be right back with updates.

igorpakushin commented 7 years ago

Hello @jmoody! The fix works for me(ruby 2.4.0, rbenv, run_loop (2.4.1), calabash-cucumber (0.20.4), not a jenkins, xcode 8.3.1 (8E1000a)) It restarts simulator twice then it proceeds. I will probably update run_loop later and will stick to using older xcode and run_loop 2.3.1 for now

igorpakushin commented 7 years ago

Not sure if it's important, but in my case simulator is restarted each feature file rather then checking for tags

umara123 commented 7 years ago

Thanks for that @jmoody , I've added it to my before hook for every scenario and it's given me a level of stability allowing me to proceed.

My before hook now looks like

Before do |scenario|
  RunLoop::CoreSimulator.quit_simulator
  sleep 3
  RunLoop::CoreSimulator.quit_simulator
  sleep 3

  launcher = Calabash::Launcher.launcher
  options = {
      # Add launch options here.
  }

  launcher.relaunch(options)
end
SergiyBeno commented 7 years ago

So weird - fix works locally when launching tests manually but persists in case tests where started via Jenkins service.

umara123 commented 7 years ago

Hmm seems like this fix doesn't give the solid reliability I require. It seems as though quitting the simulator sometimes gets it into a state where it's always seen to be Booted but in reality it isn't.

I've seen this before when I manually terminate jobs on Jenkins - somehow the kill command from Jenkins gets the running simulator in a state where it can't be launched as it's always seen to be Booted already.

The only resolution I've been able to find for this is to restart the machine.

SuperBarracuda commented 7 years ago

+1

SergiyBeno commented 7 years ago

Regarding my comment that issue was actual for CI machine - once I have removed following instructions from our job: xcrun simctl shutdown XXXXXXXX-XXXXX-XXXX-XXXX-XXXXXXXXXXXX xcrun simctl erase XXXXXXXX-XXXXX-XXXX-XXXX-XXXXXXXXXXXX I noticed that it became almost impossible to reproduce it.

fancychimp commented 7 years ago

This is happening for us with real devices. This happens during a test run every time we kick off a job in Jenkins and when we run tests locally. Restarting the machine isn't an option as this is happening in the middle of our tests. Is this specific to iOS 10? Or a version of run_loop?

Calabash version: 0.20.4 run_loop version: 2.4.0 Mac OS: El Capitan iOS: 10.2

vitaplena commented 7 years ago

I am seeing the same issue myself as reported in the link below, but I see I should have opened my issue in this project first: https://github.com/calabash/calabash-ios/issues/1313

I am also using both Jenkins and my local box. I am investigating how to make the tests more stable.

vinamelody commented 7 years ago

Hi, thanks for this post, I had the same error and DeviceAgent was successfully installed after upgrading run_loop gem to version 2.4.1

I'm trying to run calabash on iPad device (not simulator) on Xcode Version 8.3.2 (8E2002), iOS 10.3.1, Calabash version 0.20.4

sivaramprasadc commented 7 years ago

Getting the same error with the below configuration: OSX: Sierra 10.12.5 ruby 2.4.1 run_loop 2.4.1 xcode 8.3.2 Both Machine and device iPod (9.3.5) device are on same network Provided DEVICE_TARGET, DEVICE_ENDPOINT, BUNDLE_ID parms. Receiving below error: RuntimeError: Could not connect to the DeviceAgent service. device: #<Device: iPod touch (9.3.5) a6d7fffa06404f5c782cf2bb7538f5667bf54276> url: http://10.1.10.24:27753/ To diagnose the problem tail the launcher log file: $ tail -1000 -F /Users/automationtesting/.calabash/iOSDeviceManager/logs/current.log

Please suggest resolution. Thanks in advance.

jmoody commented 7 years ago

run-loop now manages the xcodebuild processes to prevent DeviceAgent relaunches (and launching simulators after tests have completed).

You should be able to remove your work arounds.

If the problem remains, create a new issue.