【问题标题】:Getting client side script to run in zombie.js让客户端脚本在zombie.js中运行
【发布时间】:2014-04-10 21:56:51
【问题描述】:

我正在使用 Zombie.js 来测试 Cucumber-js,但我似乎无法让我的客户端脚本运行。

访问页面:

this.browser.visit("http://localhost/boic",function(e, browser,status,errors){

        console.log('status',status);
        console.log('error',errors);
        console.log('console',browser.text("H1"));
});

返回状态 200,没有错误,并正确显示 H1 文本。但是,如果我包含一个脚本来更改页面中的 H1 代码:

<script>
$('H1').html('hello world');
</script>

H1文本保持不变,没有全局变量可以通过browser.window访问...

谢谢!

【问题讨论】:

    标签: zombie.js


    【解决方案1】:

    在调用脚本之前,您是否在页面中加载了 jQuery?

    还有 runScripts 浏览器选项,但默认为 true。

    但我会建议运行一个外部 phantom.js 进程并通过 webdriver 界面。仅仅因为我花了 6 个月的时间试图让僵尸做我想做的事,而 phantomjs 让这一切变得简单。 http://phantomjs.org/release-1.8.htmlhttps://github.com/LearnBoost/soda

    【讨论】:

      【解决方案2】:

      我同意 Jon Biz。僵尸很难使用。许多使用可能包含小错误的 JS 库的站点在僵尸浏览器遇到它们时会导致它崩溃(我认为节点失败) - 如果您设置了 runScripts 选项。这使得它很难用于任何需要外部 JS 的应用程序/站点 - 即大多数。

      我还建议切换到 Phantomjs。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-06-05
        • 1970-01-01
        • 2020-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多