angular - Angular 6中用于登录屏幕的量角器测试
问题描述
我是 Angular 6 应用程序量角器测试的新手。我正在尝试为登录页面编写规范测试,如下所示。
describe('Protractor Login checing ', function() {
it('should add one and two', function() {
browser.get('http://localhost:4041/login');
element(by.model('username')).sendKeys('admin');
element(by.model('password')).sendKeys('admin');
element(by.id('login')).click();
// Here, What should I check whether authentication has been done or not..
// expect().toEqual('');
});
});
实际上,在我的应用程序中,一旦逻辑成功,我将在snackBar(Angular 材料)中显示成功消息并重定向到仪表板页面。
// Angular 6 application
this.snackBar.open(res.message, '', {
duration: 6000,
});
在这里,我应该如何检查量角器?有人帮我做这个吗?
解决方案
您应该检查是否url
已更改-
describe('Protractor Login checing ', function() {
it('should add one and two', function() {
browser.get('http://localhost:4041/login');
element(by.model('username')).sendKeys('admin');
element(by.model('password')).sendKeys('admin');
element(by.id('login')).click();
browser.wait(waitForUrlChange("http://localhost:4041/dashboard"), 8000, function(){
browser.getCurrentUrl().then(function (currentUrl) {
expect(currentUrl.toEqual("http://localhost:4041/dashboard"));
});
}));
});
function waitForUrlChange(url) {
return function () {
return browser.getCurrentUrl().then(function (currentUrl) {
console.log(currentUrl);
return url === currentUrl;
});
}
}
推荐阅读
- javascript - 如何使 DOM 中的 ES6 模块导出功能可用?
- python - 将单个组中的 pandas 数据帧迭代地附加到 h5 文件
- swift - Xcode 错误不会让我点击注册或登录
- javascript - 在js中禁用一些id
- r - 问:如何应用多重 LASSO 回归?
- windows - 获取内置 Windows 用户帐户的本地化名称的最短方法是什么?
- c - 用户定义的一维数组的加法和平均函数
- python - 每次方法调用都会自动调用 __init__ 吗?
- ruby-on-rails - 检查字符串是否包含 Ruby 中的表情符号
- pandas-groupby - 按国家/地区对所有属性应用 z 分数