简体   繁体   English

使用Angular JS上传文件-量角器E2E测试

[英]Uploading a file using Angular js - protractor e2e testing

i want to upload a file as an automated test, with the following code, it correctly selects the file & clicks the upload button, however nothing happens after the upload button is clicked, I believe its not triggering the javascript on the page: 我想使用以下代码将文件上传为自动测试,它可以正确选择文件并单击“上传”按钮,但是单击“上传”按钮后没有任何反应,我相信它不会触发页面上的javascript:

var fileUpload = './testFile.txt',
absolutePath = path.resolve('./testFile.txt', fileUpload);
$('input[type="file"]').sendKeys(absolutePath);

element(by.model('documentFile'));

element(by.css('button[ng-click="uploadSelectedFiles()"]')).click();

Is there another method for this? 还有其他方法吗?

EDIT: I have managed to do this, thank you to who helped me, here is my code: 编辑:我设法做到这一点,谢谢谁帮助了我,这是我的代码:

var fileUpload = './testFile.jpg',
            absolutePath = path.resolve('/home/xxx/workspace/xxx/xxx/xxx/xxxxx/test/x/x/x/x/filesToUpload', fileUpload);

        var uploadInput = $('input[type="file"]');
        uploadInput.sendKeys(absolutePath);
        uploadInput.submit();
        element(by.css('button[ng-click="uploadSelectedFiles()"]')).click();

Instead of clicking "upload" button, send keys to the input to set the path and submit the form by clicking Submit button: 不用单击“上传”按钮,而是将键发送到输入以设置路径并通过单击“ Submit按钮来Submit表单:

var uploadInput = $('input[type="file"]');

uploadInput.sendKeys(absolutePath);

var submitButton = element(by.xpath("//input[.='Submit']"));
submitButton.click();

似乎是“ ng-”和“ click”之间的空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM