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?

4

1 回答 1

3

您确定浏览器对象的“runScripts”选项设置为 true 吗?如果没有,您可以使用以下语法:

browser.visit('... your page url ...', { runScripts: true }, function (e, b) { 
    console.log('executing callback'); 
});
于 2013-09-18T10:54:32.003 回答