2017-08-10 111 views
0

我正在测试一个ember 2.13应用程序。我想检索页面标题的值,但是从测试document.title这样做,从测试套件页面抓取标题。 我可能在这里忽略了一个简单的余烬特征。任何提示?从验收测试中从AUT检索document.title - Ember 2

+0

的qunit使用自己的index.html页面,而当你使用'document.title'在它的标题将被检索。除非您正在测试的功能内部动态修改标题,否则只会调用与qunit相关的index.html标题。 – Sumit

+0

这就是我注意到Sumit 33的原因,因此我正在寻找一种方法在测试中检索AUT的文档标题。 – j4v1

回答

0

可能是矫枉过正,但你可以使用http://tim-evans.github.io/ember-page-title/。并测试它像他们这样做:

// Testem appends progress to the title... 
// and there's no way to stop this at the moment 
function title() { 
    return findWithAssert('title', 'head').text().trim().replace(/^\(\d+\/\d+\)/, ''); 
} 

test('the default configuration works', async function (assert) { 
    assert.expect(1); 
    await visit('/posts'); 

    assert.equal(title(), 'My App | Posts'); 
}); 

https://github.com/tim-evans/ember-page-title/blob/master/tests/acceptance/posts-test.js#L17-L28