Synchronous external JS loading with zombie.js
Asked Answered
D

1

6

The problem:

I'm using zombie.js to test my client-side javascript, but I am running into a problem. Zombie.js does not provide synchronous <script> tag execution, and, in fact seems to not execute external JS files at all. A basic test confirms this:

<script type="text/javascript" src="test1.js"></script>
<script type="text/javascript" src="test2.js"></script>
<script type="text/javascript" src="test3.js"></script>

<script type="text/javascript">
   console.log("Inline javascript.");
</script>

Each test#.js contains a single line: console.log("TEST#.JS");

When I render this in a regular browser, the console displays the expected:

TEST1.JS
TEST2.JS
TEST3.JS
Inline javascript.

But when I run it with zombie.js, I only see a single line Inline javascript.

Here's what I have tried to get around the issue:

  1. using document.createElement to dynamically append a script tag to the document
  2. using document.write to add the script block into the html
  3. using a setTimeout on console.log("Inline javascript") in combination with 1 and 2 to give the test scripts some time to load.

Is there any way to resolve this issue, besides placing the JS code from all my external JS files into a huge <script> block?

Determiner answered 29/7, 2012 at 19:55 Comment(2)
Have you considered PhantomJS as an alternative to Zombie?Anxiety
Yeah, I started out with PhantomJS, but there are several bugs that (i.e. navigator.onLine is always false, etc.) that made me move away from it.Determiner
X
3

Are you sure the browser object has the "runScripts" option set to true? If not you can use the following syntax:

browser.visit('... your page url ...', { runScripts: true }, function (e, b) { 
    console.log('executing callback'); 
});
Xenos answered 18/9, 2013 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.