1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

20 commits

Author SHA1 Message Date
yuuji.yaginuma
ada05850f8 Add headless chrome driver to System Tests 2017-10-17 07:35:48 +09:00
yalab
54b18a2149 Exception message for SystemTestCase#get etc.. 2017-10-08 23:48:22 +09:00
Thomas Walpole
ba04b580c6 Use the default Capybara registered puma server configuration 2017-09-18 08:48:52 -07:00
yuuji.yaginuma
52422f2af6 Retrive screenshot in relative path of current directory
In Rails engine `Rails.root `returns the path of the dummy application.
Therefore, there is no `tmp` directly where the test is running, so can
not get the screenshot.
For this reason, instead of directly specifying tmp, retrive screenshot by
relative path from the current directory.

Fixes #30405
2017-08-27 20:44:01 +09:00
yuuji.yaginuma
1fe777ef77 Fix can't modify frozen String error in display_image
Without this, `display_image` raises an error as follwing:

```
RuntimeError: can't modify frozen String
    rails/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:72:in `display_image'
    rails/actionpack/test/dispatch/system_testing/screenshot_helper_test.rb:40:in `block (2 levels) in <class:ScreenshotHelperTest>'
```
2017-08-26 13:42:22 +09:00
Kir Shatrov
dfcc766163 Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
eileencodes
91d22b7832 Don't call register on custom drivers
It's possible for developers toadd a custom driver and then call it
using `driven_by`. Because we were only skipping `register` for
`:rack_test` that meant any custom driver would attempt to be registered
as well.

The three listed here are special because Rails registers them with
special options. If you're registering your own custom driver then you
don't want to separately register that driver.

Fixes #29688
2017-07-08 11:13:28 -04:00
yalab
1aea1ddd2a SystemTestCase undef some IntegrationTest methods because it's confused to use. 2017-07-01 23:29:55 +09:00
Mario Alberto Chávez
9063007538 SystemTesting::Driver can register capybara-webkit and poltergeist
drivers.

When using `driver_by` with capybara-webkit or poltergeist,
SystemTesting::Driver will register the driver while passing
`screen_size` and `options` parameteres.

`options` could contain any option supported by the underlying driver.
2017-06-02 11:24:55 -05:00
Fumiaki MATSUSHIMA
4c94d3e0a0 Set Capybara.app_host through host!
`visit "/"` will visit always "http://127.0.0.1" even when we call `host!`:

```ruby
class SomeTest < ApplicationSystemTest
  def setup
    host! "http://example.com"
  end

  def test_visit
    visit root_url # => visit "http://example.com/"

    visit "/" # => visit "http://127.0.0.1/"
  end
end
```

Because Capybara assumes that host is same as the server if we don't set `Capybara.app_host`:
866c975076/lib/capybara/session.rb (L239)
2017-04-02 21:11:54 +09:00
Fumiaki MATSUSHIMA
24e0fa7c4a Make driven_by overridable
Sometimes we want to use rack_test partially instead of selenium for test speed:

```ruby
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: {url: "http://chrome:4444/wd/hub"}
end

class WithJavaScriptTest < ApplicationSystemTestCase
end

class WithoutJavaScriptTest < ApplicationSystemTestCase
  driven_by :rack_test
end
```

In the abobe case, `WithoutJavaScriptTest` uses selenium because
`SystemTestCase` calls superclass' driver on `#initialize` (`self.class.superclass.driver.use`).

Using `class_attribute` can handle inherited `driven_by`.
2017-03-29 09:04:30 +09:00
Fumiaki MATSUSHIMA
ec99107a29 Pass options to driven_by
Capybara drivers can handle some options such like `url`.

### before

```
# test/test_helper.rb
Capybara.register_driver :remote_chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome, url: "http://example.com/wd/hub")
end

# test/application_system_test_case.rb
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :remote_chrome
end
```

### after

```
# test/application_system_test_case.rb
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: {url: "http://chrome:4444/wd/hub"}
end
```
2017-03-13 19:59:01 +09:00
eileencodes
7c9af60e5c Call system test driver per-instance rather than globally
Previously the system test subclasses would call `driven_by` when the
app booted and not again when the test was initialized which resulted in
the driver from whichever class was called last to be used in tests.

In rails/rails#28144 the `driven_by` method was changed to run `use` on
setup and `reset` on teardown. While this was a viable fix this really
pointed to the problem that system test `driven_by` was a global
setting, rather than a per-class setting.

To alieviate this problem calling the driver should be done on an
instance level, rather than on the global level. I added an `initialize`
method to `SystemTestCase` which will call `use` on the superclass
driver. Running the server has been moved to `start_application` so that
it only needs to be called once on boot and no options from `driven_by`
were being passed to it.

This required a largish rewrite of the tests. Each test needs to utilize
the subclass so that it can properly test the drivers.
`ActionDispatch::SystemTestCase` shouldn't be called directly anymore.
2017-03-09 10:52:05 -05:00
eileencodes
4dbebe487d Refactor system test driver/browser
Since using a browser is only for selenium it doesn't really make sense
to have a separate class for handling it there. This brings a lot of the
if/else out of the main SystemTestCase class and into the Driver class
so we can abstract away all that extra work.
2017-03-09 07:27:40 -05:00
yuuji.yaginuma
2ee4058cc5 Do not take screenshot if driver does not support screenshot
`Capybara::RackTest::Driver` does not support taking screenshots. If call
`#save_screenshot` on `Capybara::RackTest::Driver` will raise the error.

```ruby
Error:
UsersTest#test_visiting_the_index:
Capybara::NotSupportedByDriverError: Capybara::Driver::Base#save_screenshot
```

To prevent errors, if driver does not support screenshot, do not call it.
2017-03-04 17:40:51 +09:00
Lucas Mazza
704853b58b
Change SystemTestCase.driven_by to use setup/teardown hooks
Previously, `driven_by` would change the Capybara configuration when
the test case is loaded, and having multiple test classes with different
`driven_by` configs would fail as the last loaded would be effective.
2017-02-24 13:22:22 -03:00
yuuji.yaginuma
ebaf1e709f Do not take screenshot when test skipped 2017-02-23 22:40:35 +09:00
eileencodes
161cf89e13 Fix default host in setup, move teardown to helper file
* Override integration test default host

Integration tests automatically set the default host to
'http://example.com'. This works fine for integration tests because they
are not real browser sessions, but doesn't work fine for system tests
because they are real browser sessions.

We can override this by setting the `host!` in `before_setup. The
`Capybara.always_include_port` will allow the test to look at
`127.0.0.1:port capybara picks` and properly redirect the test.

Any application can override this by setting the `host!` in
their system test helper. Generally though, applications are going to be
using localhost.

In this commit I also moved the setup and teardown into their own module
for tidiness.

* Move teardown settings into system test case

These configuration options can be put into the system test case file
instead of the generated system tests helper file. This is an
implementation detail and therefore shouldn't be generated with the
template.
2017-02-20 15:07:35 -05:00
eileencodes
983275eb7c Fix screenshot helper to provide correct file name
We only want the file name to include the word `failures` if it failed,
not any time the user wants to take a screenshot during a test run.
2017-02-20 15:07:35 -05:00
eileencodes
1a0ca84a06 Move and rename system tests
* Move system tests back into Action Pack
* Rename `ActionSystemTest` to `ActionDispatch::SystemTestCase`
* Remove private base module and only make file for public
`SystemTestCase` class, name private module `SystemTesting`
* Rename `ActionSystemTestCase` to `ApplicationSystemTestCase`
* Update corresponding documentation and guides
* Delete old `ActionSystemTest` files
2017-02-20 15:07:35 -05:00