【问题标题】:Protractor Executing afterEach before the expect has occured量角器在期望发生之前执行 afterEach
【发布时间】:2017-05-25 00:30:45
【问题描述】:

对于我的一生,我无法弄清楚为什么会发生这种情况。基本上,“it”测试正在运行并正确执行,直到期望,此时它立即跳出新页面并执行 afterEach 语句。我尝试过使用 browser.wait,.then,将 afterEach 添加到 'it' browser.sleep 等并得到相同的结果。

那么在量角器方面有更多知识的人知道我如何在运行 afterEach 之前强制它执行期望吗?

 afterEach(function() {
    browser.get(browser.params.urls.base).then(function() {
        $('a[href="/Account/LogOff"]').click();
    });
 });

it('Should use the access code url and login to the content', function() {
    loginPage.registerWithAccessCode();
    loginPage.accessCodeExisting(accessCode, browser.params.user.email, browser.params.user.password);
    loginPage.accessCodeSubmit();

    expect(browser.getCurrentUrl()).toContain('pal/placementtest/welcome');     
});

【问题讨论】:

  • 尝试在提交按钮的回调中编写期望:loginPage.submitButton.click().then(function(){ expect(element(by.id('viewbox').getText())。 toContain('更新值'); });

标签: javascript angular protractor


【解决方案1】:

您是否将其包装在 describe 中?

试试这个结构:

describe('My login scenario', function() {
  beforeEach(function() {
    loginPage.registerWithAccessCode();
    // the rest of your "act" steps...
  });

  it('should...', function() {
    expect(browser.getCurrentUrl()).toContain('pal/placementtest/welcome');
  });

  afterEach(function() {
    // Logout
  });
});

【讨论】:

  • 是的,抱歉 应该添加进去,所以在 it 声明之后移动 afterEach?
  • 嗯,这主要是为了可读性,因为 afterEach 将最后执行。它将您的代码包装在 beforeEach 中,这很重要。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-02
相关资源
最近更新 更多