Casperjs测试一个内部站点

casperjs testing an internal site

本文关键字:一个 内部 站点 测试 Casperjs      更新时间:2023-09-26

我正在尝试为内部站点运行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和谷歌网址的代码,标题和屏幕截图工作正常。不知道如何使它工作的内部网站。

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

添加--ignore-ssl-errors=yes效果很好!

casperjs mytestjs //didn't work
capserjs --ignore-ssl-errors=yes mytestjs //worked perfect!

只是为了确保。

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

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

casper代码似乎没有问题。

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

对于在本地主机上运行的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');
}