在使用ng-file-upload 上传文件时,我喜欢测试(使用量角器)取消它是否有效。但是,在上传期间不会评估任何断言和操作,只有在上传完成后测试才会失败。那是因为我期待像 status == uploading 这样的东西,其中断言只会在上传后评估,而 status == done。
我正在使用的版本:
"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)中手动很明显禁用的类已从按钮中删除,但由于某种原因,它在上传文件时无法验证。
它可以使用一些优化(尤其是页面对象),但我认为它不能解释为什么我会收到超时?