jejacks0n / teaspoon

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

Move away from PhantomJS as default? #545

Open rmm5t opened 5 years ago

rmm5t commented 5 years ago

With the PhantomJS project abandoned, and potential issues with teaspoon + phantomjs, should teaspoon change it's default driver to something else?

jejacks0n commented 5 years ago

Yes, for sure.

jejacks0n commented 5 years ago

I think we should just build out the selenium setup, specifically focusing on chromedriver.

thbar commented 5 years ago

I second that - on a client's project, the build started failing on CircleCI, I think because PhantomJS was moved to "legacy" (https://circleci.com/docs/2.0/circleci-images/#language-image-variants). I suspect we'll see more of that in the future on other cases.

teeparham commented 5 years ago

For reference, to switch to selenium + chromedriver:

# Gemfile
group :test do
  gem "selenium-webdriver"
end

# teaspoon_env.rb
Teaspoon.configure do |config|
  config.driver = :selenium
  config.driver_options = { client_driver: :chrome }
end
mathias commented 5 years ago

I seem to be caught in a Catch-22 in using Chrome with selenium-webdriver, though.

If I have the gem gem "chromedriver-helper" in my Gemfile, then I can run my Capybara acceptance tests in Rspec. But Teaspoon doesn't like it.

Teaspoon running default suite at http://127.0.0.1:64564/teaspoon/default
bundler: failed to load command: teaspoon (/Users/mgauger/.rbenv/versions/2.5.1/bin/teaspoon)
Selenium::WebDriver::Error::WebDriverError: unable to connect to chromedriver 127.0.0.1:9515
  /Users/mgauger/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/common/service.rb:142:in `connect_until_stable'

If I remove the gem "chromedriver-helper" in the Gemfile, it finds the system Chromedriver (installed with Brew on this mac) and ~runs the Teaspoon suite.~ But Capybara tests fail with errors like:

     Failure/Error: visit '/page'

     Selenium::WebDriver::Error::WebDriverError:
       unable to connect to chromedriver 127.0.0.1:9515

Has anyone else run into this?

Edit: I was wrong above. It isn't actually running my Teaspoon suite in either situation. I also tried this fork to pass in the same Selenium arguments as my Capybara suite gets: gem 'teaspoon', github: 'odedniv/teaspoon', branch: 'selenium-options'

joshm1204 commented 5 years ago

Has anyone looked into headless browsers? I reference this article and would love feedback on if this is a good direction to go. I am new to Teaspoon, so not sure.

https://www.puzzle.ch/de/blog/articles/2018/02/12/phantomjs-is-dead-long-live-headless-browsers

As Karma sounded interesting.

rmm5t commented 5 years ago

@joshm1204 I think the suggested default approach here would be "Alternative 2" in the article you referenced.

joshm1204 commented 5 years ago

Yes, I think a chrome's headless browser for example would be a good solution. Is there any ability to use Chrome's headless browser yet?

rmm5t commented 5 years ago

@joshm1204 In addition to either using chromedriver-helper gem (deprecated) or webdrivers gem (replacement) and configuring the chromedriver version, you can do something like this inside the teaspoon_env.rb:

  config.driver = :selenium

  options = ::Selenium::WebDriver::Chrome::Options.new(args: ["--no-sandbox"])
  options.headless!
  config.driver_options = { client_driver: :chrome, client_driver_opts: { options: options } }
la-ruby commented 4 years ago

i'm using a modified version of ^ snippet to, like solidus does at solidus/backend/spec/teaspoon_env.rb. otherwise a chrome window appears , which shouldn't if it was truly headless.

  config.driver = :selenium
  config.driver_options = {
    client_driver: :chrome,
    selenium_options: {
      options: Selenium::WebDriver::Chrome::Options.new(
        args: %w(headless disable-gpu window-size=1920,1440),
      ),
    },
  }