【发布时间】:2015-12-25 20:26:48
【问题描述】:
我正在对我正在开发的 Angular 应用程序运行一些 CRUD 功能测试。它背后的基本思想是有3个按钮。创建、编辑和删除。请记住,所有这些功能都可以在 UI 中使用。创建和编辑按钮打开一个模式并提交信息。提交该信息后,会弹出一个 SweetAlert 告诉用户它已成功,然后测试单击 OK 按钮。对这 2 种效果很好。
但是,删除按钮存在问题。当它被点击时,它会进入一个屏幕,您可以在 (.cancel) 按钮和 (.confirm) 按钮之间进行选择。它正在查找按钮但不执行 .click() 出于任何原因。所以我可以创建/编辑内容但不能删除它,因为这个按钮不会点击。知道为什么吗?
这是警报的图片: http://i988.photobucket.com/albums/af6/jtbitt/sweetalert_zps7na0nsua.png
以下是此特定页面的测试:
describe('Main CRUD Banners Page', function() {
var create_edit = element.all(by.model('vm.create'));
var remove = element.all(by.css('button[ng- click="vm.deleteMainBanner(banner)"]'));
var modal_title = element(by.css('.modal-header h3'));
var name = element(by.css('input[placeholder="Name"]'));
var author = element(by.css('input[placeholder="Author"]'));
var title = element(by.css('input[placeholder="Title"]'));
var date = element(by.css('input[placeholder="Date"]'));
var submit = element(by.css('button[ng-click="vm.submit()"]'));
var submit_confirmation = element(by.css('p[style="display: block;"]'));
var button_confirmation = element(by.css('.confirm'));
var new_banner_name = element.all(by.binding(' banner.name ')).last();
var new_banner_author = element.all(by.binding(' banner.author ')).last();
var delete_confirm = element(by.buttonText('Yes Delete'));
function createContent(test_name, test_author, test_title, test_date) {
name.sendKeys(test_name);
author.sendKeys(test_author);
title.sendKeys(test_title);
date.sendKeys(test_date);
submit.click();
}
beforeEach(function(){
browser.get('http://localhost:3444/ind_page/content/mainbanner');
});
it('should be logged in on main banner page', function(){
expect(element(by.binding(' app.username ')).getText()).toContain('jonathan');
expect(browser.getCurrentUrl()).toMatch('http://localhost:3444/ind_page/content/mainbanner');
});
it('should open a create modal and submit main banner content', function(){
create_edit.first().click();
//expect(modal_title.getText()).toBe('Create Content');
createContent('test_banner', 'jay', 'Get Fit, Make Money', '12/14/15');
expect(submit_confirmation.getText()).toContain('Complete');
button_confirmation.click();
expect(new_banner_name.getText()).toBe('test_banner');
});
it('should open an edit modal and submit changes to main banner content', function(){
create_edit.last().click();
//expect(modal_title.getText()).toBe('test_banner');
author.clear().sendKeys('test_author');
submit.click();
expect(submit_confirmation.getText()).toContain('Complete');
button_confirmation.click();
expect(new_banner_author.getText()).toBe('test_author');
});
it('should delete main banner content', function(){
remove.last().click()
expect(submit_confirmation.getText()).toContain('You will not be able to recover this record');
delete_confirm.click();
expect(submit_confirmation.getText()).toContain('The record has been deleted');
button_confirmation.click();
});
});
HTML -
<div class="panel panel-primary">
<div class="panel-heading banner-title">Main Banners Posted</div>
<div class="panel-body" style="height:420px;overflow:auto">
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Image</th>
<th>Author</th>
<th>Date</th>
<th><a ng-click="vm.create=true;vm.fields[0].disabled=false;vm.mainBannerManagement()"
ng-model="vm.create">
<span class="glyphicon glyphicon-plus"></span>
</a>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="banner in vm.main_banners | orderBy: 'name'">
<td>{{ banner.name }}</td>
<td>{{ banner.thumbnail_picture_url }}</td>
<td>{{ banner.author }}</td>
<td>{{ banner.date }}</td>
<td>
<button ng-click="vm.create=false;vm.fields[0].disabled=true;vm.mainBannerModelUpdate(banner);vm.mainBannerManagement()"
ng-model="vm.create"
type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-eye-open"></span>
</button>
<button ng-click="vm.deleteMainBanner(banner)" class="btn btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
JS文件中的警报功能-
vm.deleteMainBanner = function(model) {
SweetAlert.swal({
title: 'Delete: Are you sure?',
text: 'You will not be able to recover this record',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes Delete',
cancelButtonText: 'Cancel',
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if(isConfirm === true){
var u = new Generic('content', model.name);
u.delete();
SweetAlert.swal('Deleted!', 'The record has been deleted', 'success');
console.log('hi im deleting shit');
$state.reload();
}
else{
SweetAlert.swal('Cancelled', 'Cancelled Deletion', 'error');
}
});
}
【问题讨论】:
-
目前如何失败?另外,请张贴删除确认“弹出”的HTML代码。谢谢。
-
将 HTML/JS 添加到我的原始帖子中。该测试在技术上并没有失败,至少在测试套件上是这样,但它没有正确地做它应该做的事情。它应该单击确认按钮,它会自动从内容列表中删除该项目。 (当我在 UI 中手动执行此操作时会发生这种情况)。我把一个console.log放在警报碰巧的地方,看看它是否在量角器运行时甚至消失了,而它不是(当我手动执行时它会消失)。
标签: angularjs protractor