5

Capybara と Selenium で興味深い問題に遭遇しました。フォームの入力中に JavaScript を有効にする必要がある Capybara リクエスト仕様がいくつかあります。フォームの 1 つは、Redactor リッチ テキスト エディターを使用したテキストエリアです。

<div class="control-group">
<%= f.label :description, "Description", class: "control-label" %>
    <div class="controls">
        <%= f.text_area :description, rows: 10, class: "redactor"%>
    </div>
</div>

テストが実行され、Selenium が起動すると (FF ドライバーと Chrome ドライバーの両方で)、Selenium は次のコマンドで失敗します。

`fill_in "Description", with: "some description"`

返されるエラーは次のとおりです。

Selenium::WebDriver::Error::InvalidElementStateError:
   Element is not currently interactable and may not be manipulated

Selenium が Rich Text Editor/Textarea を認識できなくなったようです。class="redactor"Redactor JS が説明テキスト領域に対してレンダリングをトリガーするものを削除すると、正常に動作します。

私の質問は、1. 記入するための回避策はありますか? 2. あるいは、このテストのためだけに redactor js を無効にすることはできますか?

4

3 に答える 3

3

カピバラには contenteditable div を fill_in する機能が含まれるようです ( https://github.com/jnicklas/capybara/pull/911を参照)。

それまでの間、私は以下を使用します: (シナリオでは :js => true が必要です)

# fill_in_redactor :in => find(".text1"), :with => "Hello world"
def fill_in_redactor(options)
  if options[:in]
    parent = "('#{options[:in]}').find"
  else
    parent = ""
  end

  page.execute_script( "$#{parent}('.redactor_editor').html('#{options[:with]}')" )
  page.execute_script( "$#{parent}('.redactor').html('#{options[:with]}')" )
end

def no_redactor
  page.execute_script("$('.redactor').destroyEditor();");
end
于 2013-01-25T20:45:09.753 に答える