2016-02-12 22 views
1

我潜入功能测试,并试图获得工作的几个简单的任务。该应用程序内置在ReactJS中,我决定使用Phantom/Casper。问题是即使是最基本的任务也会失败。测试应用程序作出反应与幻影/卡斯帕

总之,有一个用于测试的伎俩反应与幻影/卡斯帕应用程序?

我已经安装了幻影(2.1.1版)和卡斯帕(V1.1.0-β5)。作为第一次尝试我创建了一个简单的脚本来捕捉图像:

capture.js

var casper = require('casper').create({ 
    viewportSize: { 
    width: 1024, 
    height: 768 
    }, 
    verbose: true, 
    logLevel: "debug" 
}); 

casper.start('http://localhost:9494', function() { 
    console.log("page loaded"); 
}); 

casper.then(function() { 
    this.capture('img.png'); 
    }); 
}); 

casper.run(); 

然后运行该脚本:在浏览器中拉

> casperjs capture.js 

查看localhost:9494的应用程序应该如此。但由此产生的capture()图像是一个空白屏幕。

我也尝试添加一个wait()waitForSelector()waitForResource()无济于事。

下面是在控制台输出:

[info] [phantom] Starting... 
[info] [phantom] Running suite: 2 steps 
[debug] [phantom] opening url: http://localhost:9494/, HTTP GET 
[debug] [phantom] Navigation requested: url=http://localhost:9494/, type=Other, willNavigate=true, isMainFrame=true 
[debug] [phantom] url changed to "http://localhost:9494/" 
[debug] [phantom] Successfully injected Casper client-side utilities 
[info] [phantom] Step anonymous 2/2 http://localhost:9494/ (HTTP 200) page loaded 
[debug] [phantom] Capturing page to /path/to/img.png 
[info] [phantom] Capture saved to /path/to/img.png 
[info] [phantom] Step anonymous 2/2: done in 848ms. 
[info] [phantom] Done 2 steps in 848ms 
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true 
[debug] [phantom] url changed to "about:blank" 
+0

运行到同样的问题。一个正常的网页会很好,只是反应的应用程序不加载 – Boyang

回答

1

不知道你是怎么做到的等待。确保您的捕捉处于等待回调中。我通常使用这样的代码,它经常发生,你需要调整的等待时间才能看到效果。

3秒通常足以抓取公共网站,这就是我使用它的方式。

casper.then(function() { 
    this.wait(3000, function() { 
     this.capture('foo.jpg', undefined, 
      { 
       format: 'jpg', 
       quality: 75 
      }); 
    }); 
}); 
3

您需要巴贝尔,填充工具包NPM添加到您的项目(或任何其他版本的填充工具),然后在你的主index.js(x)的入口点的应用程序,包括这条线在顶部:

import 'babel-polyfill'; 

我们遇到了完全相同的问题,而且这个问题已经解决了我们。
我们已经尝试将babel polyfill作为Casper测试套件的一部分进行注入,但它不起作用。