Ruby on rails 用tinyMce填写
我想用Cucumber和selenium驱动程序在带有Tinymce编辑器的页面中填充文本,以进行功能自动化测试。我可以打开图像对话框,但无法填充其中的文本字段。我知道Tinymce有一个嵌入的Iframe标记,其中包含其他html。 我使用了以下步骤,但不起作用Ruby on rails 用tinyMce填写,ruby-on-rails,selenium,tinymce,cucumber,Ruby On Rails,Selenium,Tinymce,Cucumber,我想用Cucumber和selenium驱动程序在带有Tinymce编辑器的页面中填充文本,以进行功能自动化测试。我可以打开图像对话框,但无法填充其中的文本字段。我知道Tinymce有一个嵌入的Iframe标记,其中包含其他html。 我使用了以下步骤,但不起作用 When /^I fill in the xpath "([^"]*)" with "([^"]*)"$/ do |xpath, value| find(:xpath, xpath).set 'value' end 及 我得到一
When /^I fill in the xpath "([^"]*)" with "([^"]*)"$/ do |xpath, value|
find(:xpath, xpath).set 'value'
end
及
我得到一个错误,因为
无法找到图像的xpath
PFA以供参考。我认为您应该切换到chrome并使用以下方法:
看起来firefox对此有一个已知的bug。这对我来说很有效
When ^I enter (.+) in textbox of tinymce iframe having id as (.+)$ do |any_details,tiny_id|
within_frame("#{tiny_id}") do
fill_in("image_name", :with =>any_details)
end
end
另外,要在编辑器中选择整个文本进行自动化,请使用以下命令:c
When ^I select the entire textarea content in the editor$ do
evaluate_script("tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);")
end
试试这个:
When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
sleep 0.5 until page.evaluate_script("tinyMCE.get('#{field}') !== null")
js = "tinyMCE.get('#{field}').setContent('#{val}')"
page.execute_script(js)
end
作为参考,请查看此这是对我有用的:
page.execute_script('tinymce.get("my_element").setContent("updated content");')
忘了提了,但我用的是Chrome。
page.execute_script('tinymce.get("my_element").setContent("updated content");')