在使用ng-file-upload上传文件时我想测试(使用量角器),如果取消它有效。但是,在上载期间,不会评估断言和操作,并且只有在上载完成后,测试才会失败。那是因为我期待像status == upload这样的东西,断言只会在上传后评估,而状态==完成。
我正在使用的版本:
"ng-file-upload": "~10.0.2",
"angular": "~1.4.2",
"gulp-protractor": "~1.0.0"
如何在文件上传期间克服浏览器窗口的暂时模糊(看起来似乎如此)?
这是我走了多远:
HTML:
<div class="btn btn-default" ngf-select ngf-reset-on-click="false" ng-model="upload.file" name="file" id="file" ngf-pattern="application/zip" accept="application/zip">
{{upload.file.name || 'Select location...'}}
</div>
<button class="btn btn-primary" ng-click="upload.upload(upload.file)" ng-disabled="upload.status === 'loading' || !upload.file">
{{upload.status === 'loading' ? 'Uploading...' : 'Upload'}}
</button>
<a ng-click="upload.abort()" class="cancel" ng-class="{'disabled': upload.status !== 'loading'}">Cancel</a>
页面对象:
this.uploadButton = element(by.buttonText('Upload'));
this.cancelButton = element(by.css('.cancel'));
this.selectButton = element.all(by.css('[ngf-select]')).get(0);
this.fileInput = element(by.css('input[type="file"]'));
茉莉:
it('aborts an upload', function() {
var fileToUpload = './valid.zip';
var uploadFilePath = path.resolve(__dirname, fileToUpload);
page.fileInput.sendKeys(uploadFilePath).then(() => {
expect(page.selectButton.getText()).toBe('valid.zip');
expect(page.uploadButton.isEnabled()).toBe(true);
expect(page.cancelButton.getAttribute('class')).toBe('cancel disabled');
// Upload the file
page.uploadButton.click().then(() => {
//expect(page.cancelButton.getAttribute('class')).toBe('cancel');
//page.cancelButton.click().then(() => {
expect(page.cancelButton.getAttribute('class')).toBe('cancel disabled');
//});
});
});
});
使用注释行验证。在浏览器(chrome)中手动显示禁用的类已从按钮中删除,但由于某种原因,它在上传文件时无法验证。
它可以使用一些优化(尤其是页面对象),但我认为它不能解释为什么我会收到超时?