如何用capybara和selenium填充tinymce-rails编辑器?
我使用水豚测试tinymceforms有困难。 我正在使用tinymce-rails并且在我的表单中有7个编辑器。 我也使用asciimath插件与tinymce。
一切正常,但我无法编写测试来填写tinymce编辑器。
以下是我的步骤定义代码的外观,与此处描述的内容非常相似:
within_frame("content_ifr") do editor = page.find_by_id('tinymce') editor.native.send_keys 'test' end
问题是当我运行以下内容时:
editor.native.clear # works, clear the editor area, I'm testing this with pry editor.native.send_keys :tab # works, moves focus to next input editor.native.send_keys 'test' # returns "", nothing happens, nothing in editor
如此clear
, send_keys :tab
按预期工作。 但我不能发送任何字符串。 send_keys
函数总是返回空字符串,当我使用send_keys
进行测试时没有任何反应。
这里出了什么问题? 以及如何调试/调查问题?
谢谢。
我知道这是一个古老的问题,但我在试图解决这个问题时才发现它。
虽然最初的问题说他在同一页面上有7个tinymce,但我认为我的解决方案也可能适用于他,但我知道如果有一个像我的情况那样,它会起作用。
在我的请求规范中我使用了这个:
page.execute_script(’$(tinymce.editors [0] .setContent(“我的内容在这里”))’)
page.execute_script告诉它运行jQuery函数。 然后它找到第一个tincymce编辑器并设置内容。
对我来说就像一个魅力。 我想如果有一个以上的可以通过它的位置来调用它。
如此处所述切换到chrome解决了我的问题。
显然这个问题与firefox驱动程序中的错误有关。
我仍然觉得这对firefox来说是一个有效的问题。
尝试切换到包含tinymce textarea输入的iframe,而不是send_keys:
# +session+ is an instance of Capybara::Session class browser = session.driver.browser browser.switch_to.frame(iframe_id) editor.native.send_keys(text) browser.switch_to.default_content
我遇到过同样的问题。 经过一天的战斗,我的测试终于过去了。
我使用的代码是:
within_frame("producto_condiciones_ifr") do editor = page.find_by_id('tinymce') editor.native.send_keys 'filling text' end
第一行是水豚的方法。 传递的参数是iframe的ID。
2号线是必须的。
在第3行中,您希望放置在TinyMCE中的文本