3
votes

i have a tinymca's iframe inside my page and i want to fill_in that tinymca editor with the cucumber test. whenever i run my test it gives me error that jQuery not defined

in my 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' 

here is my scenario

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.

and here is the steps for that test

Given(/^I am logged in as a company admin$/) do
   visit('/')
   fill_in "log", :with => "[email protected]"
   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

but it gives me error jQuery is not defined (Selenium::WebDriver::Error::JavascriptError)

1

1 Answers

2
votes

It's most likely because "jQuery is not defined", as the message suggested.

Please try call without jQuery, but with native TinyMCE API:

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

Further reading: Test WYSIWYG editors using Selenium WebDriver in pure Ruby (not Capybara)