1

我有一个登录表单,现在我想做一个集成测试,看看用户在成功登录后是否被重定向到另一个页面。

幕后有授权服务,可通过以下方式触发页面重新加载 $window.location.href = 'home';

首先我有这个:

it('should redirect to /home if credentials are correct', function(){
    browser().navigateTo('/login');
    input('credentials.username').enter('testuser');
    input('credentials.password').enter('testpass');
    element('button.login').click();
    expect(browser().location().path()).toBe("/home");
});

但 AngularJS 测试都失败了 - 作为 Karma 和在浏览器中运行。然后我认为这可能expect为时过早,我sleep(1)在它之前添加了。然后它很好,在测试运行器中我可以在断言之前看到页面刷新。

我认为如果我有 location().path('/home') 可能会更好,但我更喜欢在这一步完全重新加载。

在这种情况下是否应该使用任何设计/测试模式,所以我不必在预期位置更改之前放置 sleep() ?

4

1 回答 1

0

你可以试试这个代码;

it('should redirect to /home if credentials are correct', function(){
    browser().navigateTo('/login');
    input('credentials.username').enter('testuser');
    input('credentials.password').enter('testpass');
    element('button.login').click();
    browser().navigateTo('/home');
});
于 2013-10-28T09:00:36.073 回答