我正在使用 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 访问全局变量...
谢谢!
最佳答案
在调用脚本之前,您是否在页面中加载了 jQuery?
还有 runScripts 浏览器选项,但默认为 true。
但我建议运行外部 phantom.js 进程并通过 webdriver 界面。只是因为我花了 6 个月的时间试图让 zombie 做我想做的事,而 phantomjs 让这一切变得简单。 http://phantomjs.org/release-1.8.html https://github.com/LearnBoost/soda
关于zombie.js - 让客户端脚本在zombie.js 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12047151/