PhantomJS有时会给出"parse error"(解析错误)信息.讯息 [英] PhantomJS sometimes gives "parse error" messages

查看:171
本文介绍了PhantomJS有时会给出"parse error"(解析错误)信息.讯息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们公司希望通过我们的CI服务器开始触发我们的QUnit单元测试,并且正在考虑使用PhantomJS作为实现此目标的一种方式.我们首先尝试通过以下脚本以幻像方式打开几个QUnit测试页面:

Our company wants to start triggering our QUnit unit tests through our CI server and are looking at PhantomJS as a means of achieving this goal. We started by just trying to open a couple of our QUnit test pages in phantom via the following script:

var page = require('webpage').create();
var args = require('system').args;

page.onConsoleMessage = function(msg, lineNum, sourceId) {
    console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
page.onError = function(msg, trace) {
    var msgStack = ['ERROR: ' + msg];
    if (trace) {
        msgStack.push('TRACE:');
        trace.forEach(function(t) {
            msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
        });
    }
    console.error(msgStack.join('\n'));
};

page.open(args[1], function(status) {
    phantom.exit();
});

没有什么花哨的内容,几乎是从phantomJS参考页面上逐字复制的.但是,这有时会导致以下输出:

Nothing fancy, almost copied verbatim from the phantomJS reference pages. But alas, this sometimes results in the following output:

ERROR: SyntaxError: Parse error
TRACE:
ERROR: SyntaxError: Parse error
TRACE:
ERROR: SyntaxError: Parse error
TRACE:
ERROR: SyntaxError: Parse error
TRACE:

我已经研究了它,解析错误"是因为PhantomJS认为jQuery变量未初始化,但是事实是,我试图加载到PhantomJS中的页面在Chrome,IE和Firefox上运行良好,所以我看不到任何解析错误(加载jQuery的代码在HEAD标签的顶部是一个无聊的SCRIPT标签,所以那里没有令人兴奋的地方).

I've dug into it and the "parse error" is because PhantomJS thinks that the jQuery variable is uninitialized, but the thing is, the pages I am trying to load in PhantomJS work perfectly fine in Chrome, IE, and Firefox, so there is no parse error that I can see (the code to load jQuery is a boring SCRIPT tag at the top of the HEAD tag, so nothing exciting there).

如果有什么不同,我们的测试将在ASP.NET(aspx)页内,通过内置于开发服务器中的VS2010,IIS8 Express或IIS 6进行测试.下一步是将它们转换为纯HTML以查看如果phantom仍然会抱怨,但这并不是真正有效的解决方案,因为将需要进一步加载ASPX页面(以潜在地使用Phantom进行自动UI测试).

If it makes any difference, our tests are inside ASP.NET (aspx) pages, served through either the VS2010 built in development server, IIS8 Express, or IIS 6. My next step is to turn them into pure HTML to see if phantom will still complain, but that's not really a valid solution since loading up ASPX pages will be a requirement further down the line (to potentially do automated UI tests using Phantom).

关于什么是错的任何想法?不知道还有哪些其他信息对调试此问题有用,但是我将按要求提供它们.我很困惑(特别是因为解析错误"并不是错误消息中最有用的).

Any ideas on what is wrong? Not sure what other pieces of information would be useful to debug this problem, but I will provide them as requested. I am stumped (especially since "parse error" isn't exactly the most useful of error messages).

修改: 这似乎与以下两个WebKit问题有关:

This seems to be related to the following two WebKit issues:

  • https://bugreports.qt.io/browse/QTBUG-16022
  • https://bugs.webkit.org/show_bug.cgi?id=58727

如果我关闭服务器上的GZIP压缩功能似乎还可以,但是我仍然需要对此问题做进一步的研究.

If I turn off GZIP compression on our server it seems to work okay, but I still have to do further research into the issue.

推荐答案

这是PhantomJS中的错误:

This is a bug in PhantomJS: http://code.google.com/p/phantomjs/issues/detail?id=930&start=300

解决方法是暂时关闭GZIP压缩(或从Phantom发送虚假的接受标头来诱骗服务器不发送压缩内容).

The workaround is to turn off GZIP compression for now (or send bogus accept headers from Phantom to trick the server into not sending compressed content).

这篇关于PhantomJS有时会给出"parse error"(解析错误)信息.讯息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆