黄瓜测试给出错误 - Selenium :: WebDriver :: Error :: JavascriptError

时间:2014-06-04 08:09:09

标签: tinymce cucumber capybara

我的页面中有一个tinymca的iframe,我想用黄瓜测试填充那个tinymca编辑器。每当我运行我的测试时,它会给我一个jQuery没有定义的错误

在我的Gemfile中

source 'http://rubygems.org'
ruby '2.0.0'

gem 'capybara'
gem 'capybara-mechanize', :git => 'git://github.com/JerryWho/capybara-mechanize.git',      :branch => 'relative-redirects'
gem 'rspec'
gem 'cucumber'
gem 'launchy'
gem 'pry'
gem 'selenium-webdriver' 

这是我的方案

Scenario: admin puts all the valid and require data  
    when Job added with all the valid and require data
    Then I should see the success message.

以下是该测试的步骤

Given(/^I am logged in as a company admin$/) do
   visit('/')
   fill_in "log", :with => "admin@email.com"
   fill_in "pwd", :with => "password"
   click_button "submit"
end

When(/^Job added with all the valid and require data$/) do
   visit('/site/admin/posts/add/')
   within_frame 'questiontextarea_ifr' do
       page.execute_script("jQuery(tinymce.editors[0].setContent('my content hersssssssssse'))")
   end
   click_button "Save"
end

Then(/^I should see the success message\.$/) do
   page.should have_content('Success Your post has been successfully added.')   
end

但它给了我错误jQuery is not defined (Selenium::WebDriver::Error::JavascriptError)

1 个答案:

答案 0 :(得分:2)

这很可能是因为" jQuery未定义",正如消息所示。

请在没有jQuery的情况下尝试通话,但使用原生TinyMCE API

page.execute_script("tinyMCE.activeEditor.setContent('my content hersssssssssse')")

进一步阅读:纯Ruby(不是Capybara)中的Test WYSIWYG editors using Selenium WebDriver