1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

system_specで直接javascriptを実行する

Last updated at Posted at 2021-04-19

はじめに

system spec を書いてるときに、javascript が起動しないときがあり直接 javascript を実行できたらエラーを回避できるときがあると思います。

解決法

capybara の execute_script を使うと javascript を実行させることができます。

page.excute_script "console.log('javascript')"

これを利用すると、強引にフォームに値を送り込めます。

page.excute_script "$('#form').val('フォームの値')"

本来は、エラーを解消してテストをパスするべきなので利用はご利用的に

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?