Angular 6 中的量角器测试用于登录屏幕

Protractor test in Angular 6 for login screen

我是 Angular 6 应用程序 Protractor 测试的新手。我正在尝试为登录页面编写规范测试,如下所示。

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 material) 中显示成功消息并重定向到仪表板页面。

// 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;
        });
    }
}