calabash / calabash-ios

Calabash for iOS
Other
1.81k stars 369 forks source link

Calabash::Cucumber::ServerNotRespondingError: Could not connect to the Calabash Server #1254

Closed jordanevolves closed 7 years ago

jordanevolves commented 7 years ago

I'm finding that when I run calabash-ios console then start_test_server_in_background, my app launches briefly then closes with output Calabash::Cucumber::ServerNotRespondingError: Could not connect to the Calabash Server @ http://127.0.0.1:37265/.

For background:

Interestingly, if I run the app from Xcode with the same build configuration targeting the same simulator, the app starts normally. I can see in Xcode debug output that the Calabash server starts up and is listening - although the IP on which it's listening when I start from Xcode (127.0.0.1) doesn't match the one listed in the error I get when I run start_test_server_in_background. Is this the source of the issue?

jordanevolves commented 7 years ago

After upgrading gem version to 0.20.4 (server still 0.20.3) I'm finding that I'm not even able to run server_version['version'] in the console:


RunLoop::HTTP::Error: Timeout exceeded
    from /Users/Jordan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/run_loop-2.2.4/lib/run_loop/http/retriable_client.rb:157:in 'block in request'
    from /Users/Jordan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/run_loop-2.2.4/lib/run_loop/http/retriable_client.rb:150:in 'times'
    from /Users/Jordan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/run_loop-2.2.4/lib/run_loop/http/retriable_client.rb:150:in 'request'
    from /Users/Jordan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/run_loop-2.2.4/lib/run_loop/http/retriable_client.rb:93:in 'post'
    from /Users/Jordan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/run_loop-2.2.4/lib/run_loop/device_agent/client.rb:1463:in '_dismiss_springboard_alerts'
    from /Users/Jordan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/calabash-cucumber-0.20.4/lib/calabash-cucumber/http_helpers.rb:118:in '_private_dismiss_springboard_alerts'
    from /Users/Jordan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/calabash-cucumber-0.20.4/lib/calabash-cucumber/http_helpers.rb:22:in 'http'
    from /Users/Jordan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/calabash-cucumber-0.20.4/lib/calabash-cucumber/connection_helpers.rb:14:in 'http'
    from /Users/Jordan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/calabash-cucumber-0.20.4/lib/calabash-cucumber/core.rb:174:in 'server_version'
    from (irb):1
    from /Users/Jordan/.rbenv/versions/2.3.1/bin/irb:11:in '<main>'
jordanevolves commented 7 years ago

An additional note: After upgrading calabash.framework to 0.20.4 to match the gem version, then doing a "deep clean" (Shift+Option+Cmd+K) in Xcode and rebuilding/launching my app via Xcode, I'm seeing that Calabash server version 0.20.4 is listening. I then run DEBUG=1 calabash-ios console and see:

DEBUG: Trying to connect to Calabash Server: 1 of 1
DEBUG: Connected to Calabash Server on try: 1 of 1

But when I try a command such as query("view") I get the same Timeout Exceeded error as listed above.

jordanevolves commented 7 years ago

If immediately after doing the above and getting the timeout error, I run start_test_server_in_background in the console (even though I already have a simulator running with the app launched and Calabash server listening according to Xcode, and I've pointed the calabash-ios console to that simulator using DEVICE_TARGET), I get a RunLoop::NoSimulatorAppFoundError, but THEN if I do a query("view") the query works! Very confusing. start_test_server_in_background shouldn't be needed if I've used DEVICE_TARGET to point calabash-ios console to a simulator with the app (with Calabash linked in) already running, right?

singhujjwal commented 7 years ago

Hi, I am also facing the same issue with calabash-ios 0.20.3. Although its intermittent. Whenever I kill the app, and start console again i do not see this issue.

Thanks, Ujjwal

jordanevolves commented 7 years ago

I should have paid more attention to the part of the error message that reads: If your app is crashing at launch, find a crash report to determine the cause. :)

Turns out that the issue was actually due to an app crash - I wasn't properly loading a required library. Referencing crash reports in ~/Library/Logs/DiagnosticReports led me to the error, then I just had to add the required libraries in Build Phases > Embed Frameworks for my app target. Something that threw me off a bit was that the app wasn't crashing when I ran it from Xcode with the Calabash build config, but was when I launched it via bundle exec cucumber in the same simulator. There must be something different about the way I'm building in these two cases that I haven't yet pinpointed which causes the necessary libraries to be embedded in the former case and not the latter.

singhujjwal commented 7 years ago

Hi, My app is not crashing below is the debug logs

`calabash-ios 0.20.3> start_test_server_in_background EXEC: xcrun simctl list devices --json EXEC: xcrun instruments -s devices DEBUG: HTTP: get http://10.232.16.169:27753/1.0/health {:retries=>1, :timeout=>0.5} DEBUG: DeviceAgent says, "Calabash is ready and waiting." DEBUG: DeviceAgent is already running DEBUG: HTTP: post http://10.232.16.169:27753/1.0/session {:retries=>200, :timeout=>20} DEBUG: Launched com.xxxx.xxxx.xxxx on #<Device: xx-xxxx-ipad-xxxx (10.2) 8679b6be3a472b3a15462d343978f97c9afefaba> DEBUG: {"status":"launched!"} DEBUG: Took 0.083821 seconds to launch com.xxxx.xxxx.xxxx on #<Device: xx-xxxx-ipad-rk (10.2) 8679b6be3a472b3a15462d343978f97c9afefaba> DEBUG: Trying to connect to Calabash Server: 1 of 10 DEBUG: Trying to connect to Calabash Server: 2 of 10 DEBUG: Trying to connect to Calabash Server: 3 of 10 DEBUG: Trying to connect to Calabash Server: 4 of 10 DEBUG: Trying to connect to Calabash Server: 5 of 10 DEBUG: Trying to connect to Calabash Server: 6 of 10 DEBUG: Trying to connect to Calabash Server: 7 of 10 DEBUG: Trying to connect to Calabash Server: 8 of 10 DEBUG: Trying to connect to Calabash Server: 9 of 10 DEBUG: Trying to connect to Calabash Server: 10 of 10 Calabash::Cucumber::ServerNotRespondingError: Could not connect to the Calabash Server @ http://10.232.16.169:37265.

See these two guides for help.

  1. Make sure your application is linked with Calabash.
  2. Make sure there is not a firewall blocking traffic on http://10.232.16.169:37265.
  3. Make sure http://10.232.16.169:37265 is correct.

If your app is crashing at launch, find a crash report to determine the cause.

from /usr/local/lib/ruby/gems/2.3.0/gems/calabash-cucumber-0.20.3/lib/calabash-cucumber/http/http.rb:97:in `raise_on_no_connectivity'
from /usr/local/lib/ruby/gems/2.3.0/gems/calabash-cucumber-0.20.3/lib/calabash-cucumber/http/http.rb:81:in `ensure_connectivity'
from /usr/local/lib/ruby/gems/2.3.0/gems/calabash-cucumber-0.20.3/lib/calabash-cucumber/launcher.rb:388:in `relaunch'
from /usr/local/lib/ruby/gems/2.3.0/gems/calabash-cucumber-0.20.3/lib/calabash-cucumber/core.rb:1567:in `start_test_server_in_background'
from (irb):1
from /usr/local/bin/irb:11:in `<main>'

calabash-ios 0.20.3> `

Can you please help me what is going wrong. It works sometimes when i kill all the active and background apps.

Thanks, Ujjwal

jmoody commented 7 years ago

Check your device logs in Xcode. You will be able to tell if the server is running.

If you have more than one application running linked with calabash.framework then the first one will block the port of the LPServer.

jmoody commented 7 years ago

@jordanevolves

Your linker flags are incorrect.

-force_load "$(SOURCE_ROOT)/calabash.framework/calabash"

@singhujjwal

There are only a few things that could be wrong:

  1. Your application is not linked with Calabash.
  2. Another application is running on your device that is linked with Calabash - thus the 37265 port is blocked.
  3. The IP address of your device is incorrect.
  4. Your device and the host machine are not on the same network.

You can test all of these by launching your application manually and running curl.

$ curl http://<ip address:37265/version