我有一个如下所示的 upload.js 测试脚本——
casper.test.comment('upload test!');
var casper=require('casper').create({
waitTimeout: 30000, //max out upload time
});
var fileName='/Users/steven/test.png';
casper.start('http://steven.dev/', function () {
casper.thenClick('#btn_upload', function () {
this.test.assertUrlMatch ('http://steven.dev/upload', 'on upload page ');
});
casper.then(function(){
this.evaluate(function(fileName)
{__utils__.findOne('input[type="file"]').setAttribute('value',fileName)},
{fileName:fileName});
this.echo('Name='+this.evaluate(function() {return
__utils__.findOne('input[type="file"]').getAttribute('name')}));
this.echo('Value='+this.evaluate(function() {return
__utils__.findOne('input[type="file"]').getAttribute('value')}));
this.page.uploadFile('input[type="file"]',fileName);
});
casper.then(function() {
this.click('#submit_button');
});
casper.waitForSelector('.upload_progress', function() {
this.echo('uploading...');
});
casper.waitForText("Done!", function() {
this.echo('success!');
});
casper.then(function() {
this.test.assertVisible ('#tools','see tools');
});
casper.run(function() {
this.test.done(2);
this.exit();
});
当我使用--xunit
参数运行这个测试时casperjs test upload.js --xunit=log.xml
,它只是运行测试而不导出日志文件。我的套件中有两个其他测试可以很好地导出文件。哇!