Search code examples
javascriptphantomjscodeceptionredactor

WYSIWYG Redactor not working in PhantomJS


I am trying to test my webpage using Codeception and PhantomJS, and everything works great except one annoying thing. WYSIWYG Redactor is not loaded by PhantomJS and all other javascript is not executed at all. I tried to isolate the problem by creating a very simple webpage with just Redactor in it:

<html>
<head>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="redactor/redactor.js"></script>
    <link rel="stylesheet" type="text/css" media="screen, projection" href="redactor/redactor.css">
    <script>
        $(function()
        {
            $('#redactor').redactor();
        });
    </script>
</head>
<body>
<textarea name="" id="redactor" cols="30" rows="10"></textarea>
</body>
</html>

And then I have this simple test script that I give to PhantomJS:

var page = require('webpage').create();
page.open('http://localhost/redactor/', function(status) {
  console.log("Status: " + status);
  if(status === "success") {
    page.render('example.png');
  }
  phantom.exit();
});

Result in example.png should be simple webpage with Redactor loaded, but instead I got PhantomJS error:

TypeError: 'undefined' is not an object (evaluating 'tags.length')
http://localhost/redactor/redactor/redactor.js:6928

So I tried to fix redactor by putting if(tags === undefined) return;, but there are like 3-4 these bugs, always with undefined problem. When I fixed all of them I get webpage where is just textarea, but no WYSIWYG. In browser its rendered fine (FF, Chrome, Opera, ...), but in PhantomJS its bugged.

What am I doing wrong? Have any of you encoutered same problem?


Solution

  • I had this exact same problem with PhantomJS version 1.9.7.

    Upgrading to 2.0.0 fixed it. I used Homebrew:

    brew update
    brew upgrade phantomjs