casperjs测试内部网站

时间:2013-03-04 10:25:39

标签: javascript phantomjs casperjs

我正在尝试为内部网站运行casper测试。它在预生产环境上运行,到目前为止的代码是

    var casper = require('casper').create({
                 verbose: true,
                 loglevel:"debug"
                 });

    // listening to a custom event
    casper.on('page.loaded', function() {
              this.echo('The page title is ' + this.getTitle());
              this.echo('value is: '+ this.getElementAttribute
                       ('input[id="edit-capture-amount"]', 
                        'value'));
    });

    casper.start('https://preprod.uk.systemtest.com', function() {
                 this.echo(this.getTitle());
                 this.capture('frontpage.png');
                 // emitting a custom event
                 this.emit('age.loaded.loaded');    
    });

    casper.run();

你可以看到它并不多,但我的问题是地址无法访问。捕获还显示空白页面。不知道我做错了什么。我已经使用cnn和google网址检查了代码,标题和截屏工作正常。不确定如何使其适用于内部网站。

3 个答案:

答案 0 :(得分:2)

我遇到了完全相同的问题。在我的浏览器中,我可以解析网址,但是capserjs不能。我得到的只是about::blank一个网页。

添加--ignore-ssl-errors=yes就像魅力一样!

casperjs mytestjs //didn't work

capserjs --ignore-ssl-errors=yes mytestjs //worked perfect!

答案 1 :(得分:1)

只是为了确定。

您可以从运行casper的计算机上访问preprod.uk.systemtest.com吗?例如,使用ping或wget。

您的计算机和preprod服务器之间是否有代理?或者您的系统是否配置为通过不应用于preprod服务器的代理?

casper代码似乎没问题。

我知道这应该是评论,但我没有足够的声誉来发表评论。

答案 2 :(得分:0)

对于在localhost中运行CasperJs测试,为了测试自定义域/子域/主机,需要定义一些头文件。

在仅传递HOST标头时遇到了一些问题,例如,快照未正确拍摄。

我添加了2个标题,现在我的测试正常运行:

    casper.on('started', function () {
        var testHost = 'preprod.uk.systemtest.com';

        this.page.customHeaders = {
            'HOST': testHost,
            'HTTP_HOST': testHost,
            'SERVER_NAME': testHost
        };
    });

    var testing_url: 'http://localhost:8000/app_test.php';
    casper.start(_testing_url, function() {
    this.echo('I am using symfony, so this should have to show the homepage for the domain: preprod.uk.systemtest.com');
    this.echo('An the snapshot is also working');
    this.capture('casper_capture.png');
}