jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 243 forks source link

Teaspoon not opening url in Docker #538

Closed jsilvestri closed 5 years ago

jsilvestri commented 6 years ago

We recently upgraded to rails 5.1 from 4.2, and in the process upgraded to teaspoon 1.1.5 as well. I am able to get jasmine tests running with teaspoon both in a browser and by running teaspoon from the command line locally on my Mac, but I cannot get them to work in the Docker instance that used to work on rails 4.2 / teaspoon 1.1.1. I get the error Timed out (Selenium::WebDriver::Error::TimeOutError).

When I investigate further, in lib/teaspoon/driver/selenium.rb, driver.navigate.to(url) is not getting to anything, because even driver.execute_script("return window") returns []. I am using headless chromedriver v. 2.36.540471 (which I also use successfully with Docker for rspec tests).

I have Selenium debugging logs on, but they say nothing of interest (just that we get stuck in the .until loop in selenium.rb until time out is reached). If you have more ways I could debug, I would appreciate it. I have been scouring blogs and trying all sorts of flags!

Here are my logs (NOTE that there are many more lines further down that just duplicate the checking for return window.Teaspoon && window.Teaspoon.finished and return window.Teaspoon && window.Teaspoon.getMessages()).

# Logfile created on 2018-03-08 21:37:56 +0000 by logger.rb/56438
2018-03-08 21:38:00 DEBUG Selenium Executing Process ["/usr/local/bundle/bin/chromedriver", "--port=9515"]
2018-03-08 21:38:00 DEBUG Selenium polling for socket on ["127.0.0.1", 9515]
2018-03-08 21:38:00 DEBUG Selenium polling for socket on ["127.0.0.1", 9515]
Starting ChromeDriver 2.36.540471 (9c759b81a907e70363c6312294d30b6ccccc2752) on port 9515
Only local connections are allowed.
2018-03-08 21:38:00 INFO Selenium -> POST session
2018-03-08 21:38:00 INFO Selenium    >>> http://127.0.0.1:9515/session | {"desiredCapabilities":{"browserName":"chrome","version":"","platform":"ANY","javascriptEnabled":true,"cssSelectorsEnabled":true,"takesScreenshot":false,"nativeEvents":false,"rotatable":false,"chromeOptions":{"args":["--disable-infobars","--no-sandbox","--headless","--window-size=3840,2400","--disable-gpu","--debug-print[9]","--privileged"],"prefs":{"profile.default_content_settings.popups":0}}},"capabilities":{"firstMatch":[{"browserName":"chrome"}]}}
2018-03-08 21:38:00 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=utf-8", "Content-Length"=>"456"}
2018-03-08 21:38:00 INFO Selenium <- {"sessionId":"e91c0cf26d500ccdb15f73729ca9912c","status":0,"value":{"acceptInsecureCerts":false,"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.36.540471 (9c759b81a907e70363c6312294d30b6ccccc2752)","userDataDir":"/tmp/.org.chromium.Chromium.fEUwuj"},"cssSelectorsEnabled":true,"databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platform":"Linux","rotatable":false,"setWindowRect":true,"takesHeapSnapshot":true,"takesScreenshot":true,"unexpectedAlertBehaviour":"","version":"64.0.3282.167","webStorageEnabled":true}}
2018-03-08 21:38:00 INFO Selenium Detected OSS dialect.
2018-03-08 21:38:00 INFO Selenium -> POST session/e91c0cf26d500ccdb15f73729ca9912c/url
2018-03-08 21:38:00 INFO Selenium    >>> http://127.0.0.1:9515/session/e91c0cf26d500ccdb15f73729ca9912c/url | {"url":"http://127.0.0.1:35077/jasmine/default?reporter=Console"}
2018-03-08 21:38:00 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=utf-8", "Content-Length"=>"65"}
2018-03-08 21:38:03 INFO Selenium <- {"sessionId":"e91c0cf26d500ccdb15f73729ca9912c","status":0,"value":null}
2018-03-08 21:38:03 INFO Selenium -> POST session/e91c0cf26d500ccdb15f73729ca9912c/execute
2018-03-08 21:38:03 INFO Selenium    >>> http://127.0.0.1:9515/session/e91c0cf26d500ccdb15f73729ca9912c/execute | {"script":"return window.Teaspoon && window.Teaspoon.finished","args":[]}
2018-03-08 21:38:03 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=utf-8", "Content-Length"=>"73"}
2018-03-08 21:38:03 INFO Selenium <- {"sessionId":"e91c0cf26d500ccdb15f73729ca9912c","status":0,"value":null}
2018-03-08 21:38:03 INFO Selenium -> POST session/e91c0cf26d500ccdb15f73729ca9912c/execute
2018-03-08 21:38:03 INFO Selenium    >>> http://127.0.0.1:9515/session/e91c0cf26d500ccdb15f73729ca9912c/execute | {"script":"return window.Teaspoon && window.Teaspoon.getMessages() || []","args":[]}
2018-03-08 21:38:03 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=utf-8", "Content-Length"=>"84"}
2018-03-08 21:38:03 INFO Selenium <- {"sessionId":"e91c0cf26d500ccdb15f73729ca9912c","status":0,"value":[]}
2018-03-08 21:38:03 INFO Selenium -> POST session/e91c0cf26d500ccdb15f73729ca9912c/execute
2018-03-08 21:38:03 INFO Selenium    >>> http://127.0.0.1:9515/session/e91c0cf26d500ccdb15f73729ca9912c/execute | {"script":"return window.Teaspoon && window.Teaspoon.finished","args":[]}
2018-03-08 21:38:03 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=utf-8", "Content-Length"=>"73"}
2018-03-08 21:38:03 INFO Selenium <- {"sessionId":"e91c0cf26d500ccdb15f73729ca9912c","status":0,"value":null}
2018-03-08 21:38:03 INFO Selenium -> POST session/e91c0cf26d500ccdb15f73729ca9912c/execute
2018-03-08 21:38:03 INFO Selenium    >>> http://127.0.0.1:9515/session/e91c0cf26d500ccdb15f73729ca9912c/execute | {"script":"return window.Teaspoon && window.Teaspoon.getMessages() || []","args":[]}

Thanks!

jsilvestri commented 6 years ago

I managed to fix this this morning by trying RAILS_ENV=test rake teaspoon instead of just teaspoon or bundle exec teaspoon -f documentation. I am so glad to have it working, but am not sure why this would make any difference?

jejacks0n commented 6 years ago

The primary difference between how test and development (the default env that teaspoon runs in for caching/performance reasons) is usually how errors/exceptions are handled by rails. You might be seeing some exception somewhere that's causing rails to behave differently? That might be where I'd start -- hopefully helpful.

jsilvestri commented 6 years ago

@jejacks0n is there a way to force the teaspoon command line interface to use test? I tried RAILS_ENV=test teaspoon, but that has the same timeout error as initially listed in this issue.

RAILS_ENV=development rake teaspoon does fail, but with a different error:

DEPRECATION WARNING: The factory_girl gem is deprecated. Please upgrade to factory_bot. See https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md for further instructions. (called from require at /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.15.4/lib/bundler/runtime.rb:82)
Starting the Teaspoon server...
[4206] Puma starting in cluster mode...
[4206] * Version 3.11.0 (ruby 2.3.4-p301), codename: Love Song
[4206] * Min threads: 1, max threads: 1
[4206] * Environment: test
[4206] * Process workers: 2
[4206] * Preloading application
[4206] * Listening on tcp://127.0.0.1:37029
[4206] Use Ctrl-C to stop
Unable to start teaspoon server; could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
jejacks0n commented 5 years ago

It looks like it can't connect to the server at the port specified. You can configure teaspoon to use a specific port, and if you're inside a docker container you need to make sure that port is something that will be available.