2

I am using Protractor for a non-Angular page and wanting to find the CKEditor instance on the page to then set data for. I can do this in Chrome console via:

CKEDITOR.instances.html_editor.setData("Hello")

In my test for the page, I have the code below:

it('should enter text in editor successfully', function() {

    var composerPage = new ComposerPage();

    browser.executeScript('return window.CKEDITOR');    
    window.CKEDITOR.instances.html_editor.setData( 'Hello' );        

  });

However, the error returned is:

Error: Failed: Cannot read property 'instances' of undefined

I've already had a look at this Stack Overflow question here: Protractor: How to access global variables that we have inside our application? but didn't really help get me unstuck.

Any suggestions as to how I can define the CKEditor instance and set data would be helpful!

Community
  • 1
  • 1
Ryan Drake
  • 359
  • 3
  • 17

1 Answers1

1

Use browser.executeScript() to set the editor's data:

var value = 'Hello';
browser.executeScript(function (arguments) {
    window.CKEDITOR.instances.html_editor.setData(arguments[0]); 
}, value); 
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Still getting ```Cannot read property 'instances' of undefined``` . Any other suggestions perhaps? – Ryan Drake May 17 '15 at 23:35
  • @RyanDrake how about `browser.executeScript("window.CKEDITOR.instances.html_editor.setData(arguments[0]);", value);`? – alecxe May 18 '15 at 09:50
  • Same error. It causes all the tests to fail in this case. – Ryan Drake May 18 '15 at 23:55
  • @RyanDrake how does it fail? Are you sure you can access `CKEDITOR` through `window.CKEDITOR`? – alecxe May 19 '15 at 11:16
  • 1
    Eventually got it working! Protractor wasn't working as intended with Angular v1.3.3, so updated to v1.3.15 (latest stable build) yesterday and it's now looking good. Thanks Alex! – Ryan Drake May 20 '15 at 01:12
  • @alecxe , I'm getting an error Cannot read property 'setData' of undefined – rajana sekhar Sep 09 '15 at 05:06
  • I got it to working by reading the instance by the name in the title field. var statamentDes = 'Hello'; browser.executeScript(function (arguments) { var name = "editor1" // split title to get this window.CKEDITOR.instances[name].setData(arguments); }, statamentDes); – Madhu Jun 14 '19 at 08:54