我有一个打开的模式允许上传。模态有一个按钮,用于多个上传,文件上传,上传,取消和确定(选择文件后按,单击上传按钮,然后选择确定返回上一个屏幕)。一切正常,但这是一个非角度的应用程序,所以它不是在选择确定之前等待上传完成。我输入了一个browser.driver.sleep,它给了它足够的时间,但我知道这是一个不可靠的解决方案。有关在选择确定之前如何等待上传完成的任何想法?
测试代码:
this.selectsUploadButton = function () {
this.waitsForElementToBeClickable(uploadButton);
uploadButton.click().then(function () {
browser.driver.sleep(5000);
uploadButtonOkLogo.click();
});
};
html:由于叠加,我得到的错误无法点击。
<div id="uploadLogoDialog" class="modal-dialog" style="display: block;">
<div class="upload-overlay"></div>
<div class="upload-logo-container">
<div class="upload-logo-header">Image must be under 50 MB and in the following formats: .JPG, .GIF, .PNG</div>
<div class="upload-logo-content">
<div class="select-container">
<button class="btn btn-select" data-bind="click: assosiateLogoImage">
<span class="icon icon-select"></span>
<span class="label">Select file</span>
</button>
</div>
<button class="btn btn-upload" data-bind="click: startLogoUpload, disable: logo.isUploaded" disabled="">
<button class="btn btn-ok" data-bind="click: closeUploadLogoDialog">
<div class="upload-progress-container">
<div class="upload-progress" style="display: none;" data-bind="visible: isUploading">
<div class="progress-bar ui-progressbar ui-widget ui-widget-content ui-corner-all" data-bind="progressBar: { value: progressValue }" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
<div class="ui-progressbar-value ui-widget-header ui-corner-left" style="display: none; width: 0%;"></div>
</div>
<div class="percentage" data-bind="text: progressValue() + ' %'">0 %</div>
</div>
</div>
<form id="uploadForm" action="https://iplan.preview.s3.amazonaws.com/" enctype="multipart/form-data" target="uploadIFrame" method="post">
<div class="file-input" data-bind="css: {'ie': isIE}">
<input id="logoFile" type="file" data-bind="event:{ 'change': handleLogoSelection }" name="file">
</div>
</form>
</div>
</div>
<div class="upload-busy" data-bind="visible: isUploading" style="display: none;"></div>
</div>
答案 0 :(得分:2)
此处的最佳选择是等待上传按钮使用量角器与disabled
对象一起使用的wait()
函数获取ExpectedConditions
。 wait()
函数总是等待,直到给定的条件为真,所以你必须提供一个参数,使它在某个时间后变为真(这应该是你想要的值)。这是如何 -
var EC = protractor.ExpectedConditions;
browser.wait(EC.not(EC.elementToBeClickable(uploadButton)),10000).then(function(){
uploadButtonOkLogo.click();
}); //Wait until element is not clickable (checks if element is enabled to decide if its clickable)
或者,您可以编写自己的ExpectedCondition,直到元素未启用,然后在wait函数中使用它。这是如何 -
browser.wait(function(){
return uploadButton.isEnabled().then(function(enabled){
return enabled === false; // wait until element is disabled and if it is disabled then return true
});
}, 10000).then(function(){
uploadButtonOkLogo.click();
});
另一种方法是等到上传进度条达到100%,方法是手动编写自己的ExpectedCondition等待。这是如何 -
browser.wait(function(){
return $('.percentage').getText().then(function(percent){
return percent === '100 %'; //return true only if percentage is 100%
});
}, 10000).then(function(){
uploadButtonOkLogo.click();
});
希望它有所帮助。