Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronous external JS loading with zombie.js

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?

like image 450
laker Avatar asked Jul 29 '12 19:07

laker


1 Answers

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'); 
});
like image 78
Lud Avatar answered Oct 05 '22 07:10

Lud