我是使用Protractor测试Angular js app的新手。 点击它时我有一个提交按钮,窗口上会弹出Toaster Message。
要提交的按钮如下。
<button title="Add the Expense Claim" ng-show="addExpDetailsShow" class="btn btn-primary btn-sm" ng-click="addExpenseDetails()">Add</button>
&#13;
Toaster div如下所示
<div class="toast-top-right" id="toast-container"><div style="" class="toast toast-error"><button class="toast-close-button">×</button><div class="toast-message">Select Expense Type.<br>Amount should be between 0.10 to 100000000.</div></div></div>
&#13;
现在我需要验证烤面包机是否显示,需要验证烤面包机信息。我正在使用茉莉来编写我的测试用例。通过谷歌搜索我写下面的代码。
it('adding expense', function(){
element(by.xpath(".//*[@id='navbar-collapse']/ul[1]/li[2]/a")).click();
element(by.xpath(".//*[@id='main-container']/div[1]/div/div/div[3]/div/button[1]")).click();
element(by.css('[ng-click="addExpenseDetails()"]')).click();
toast = $$('.toast toast-error');
browser.manage().timeouts().implicitlyWait(1000);
expect(toast.getAttribute('value')).toEqual('some value');
expect(toast.isDisplayed()).toBe(true);
});
答案 0 :(得分:1)
验证烤面包机类似于验证量角器中的任何其他元素。然而,挑战是在时间范围内验证它出现和消失。要验证其详细信息,请尝试等待其外观然后验证它。这是怎样的 -
it('adding expense', function(){
var EC = protractor.ExpectedConditions;
element(by.css('[ng-click="addExpenseDetails()"]')).click()
//Verify toast after click event returns promise
.then(function(){
toast = $('.toast toast-error');
browser.wait(EC.visibilityOf(toast), 20000) //wait until toast is displayed
.then(function(){
expect(toast.getAttribute('value')).toEqual('some value');
});
});
});
希望这有帮助。
答案 1 :(得分:1)
it('adding expense', function(){
var EC = browser.ExpectedConditions;
element(by.css('[ng-click="addExpenseDetails()"]')).click()
//Verify toast after click event returns promise
.then(function(){
toast = $('.toast-message');
browser.wait(EC.visibilityOf(toast), 20000) //wait until toast is displayed
.then(function(){
expect(toast.getText()).toEqual('some value');
});
});
});