google-chrome - 如何使用 Chrome 远程调试 CasperJS?

标签 google-chrome debugging phantomjs remote-debugging casperjs

在 Chrome 中调试 CasperJS 脚本的步骤是什么?我正在尝试在 Windows 8.1 上进行调试。

1) 我的测试 c:\temp\googletestin.js 有:

debugger;

casper.test.begin('Google search retrieves 10 or more results',3, function suite(test) {

    casper.start("http://www.google.com.br/", function() {
        this.echo(">>Number 1");
        test.assertTitle("Google", "Title home page google");

        casper.echo(">>Number 2");
        test.assertExists('form[action="/search"]', "find form search");

        casper.echo(">>Number 3");
        this.fill('form[action="/search"]', {
            q: "casperjs"
        }, true);

        this.echo(">>Number 4");
        casper.capture('test.png', undefined, {
        format: 'png',
        quality: 75
        });

    })

    casper.run(function() {
        test.done();
    });
});

2)打开cmd.exe

3)执行命令行

>casperjs test c:\temp\googletesting.js --remote-debugger-port=9222 --remote-debugger-autorun=yes

ps:测试正常运行到结束

4) 打开 chrome 并输入该 url:http:localhost:9222

5) 页面空白

6) 打开控制台 (f12) 并执行:__run(); 但什么也没有发生

最佳答案

在步骤 3 中,您需要将调试器选项传递到 CasperJS,而不是可通过 casper.cli 访问的脚本中。 。您也不应该让脚本自动启动( --remote-debugger-autorun=yes ),否则它会在您调试它之前运行。正如您正确所述,您可以打开 Chrome/Safari 并调用 __run()触发脚本执行。

casperjs --remote-debugger-port=9222 test yourScript.js

关于google-chrome - 如何使用 Chrome 远程调试 CasperJS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26630979/

相关文章:

javascript - 3d 翻转动画在 chrome 中不起作用

javascript - 如果 onclick 处理程序大小超过 126,则 websocket 会从浏览器客户端重复发送。火狐/Chrome

javascript - 如何在使用 manifest.json 时允许方向旋转?

unit-testing - ng 测试 - 意外 token 'const'

linux - PhantomJS arguments.js 示例 UTF-8 不工作

javascript - 浏览器如何扩展 native JavaScript 环境以添加像 Window 这样的宿主对象?

在使用较旧 API 的设备上进行调试时,Android Studio 会显示来自 compileSdkVersion API 的源代码

java - OperationException 导致错误请求错误

xcode - 在 XCode 4 中调试异常

pdf-generation - 让 PhantomJS 在渲染为 PDF 之前等待整个页面加载