2016-08-22 9 views
1

私は分度器を学んでいて、それは素晴らしいようです。しかし、私は単一のページのオープニングで仕様のカップルを実行したいと思います。それをどうすれば実現できますか?私の問題は、私のページ上の多くのものがajax経由でロードされ、カスケードによってロードされることです。分度器 - 開かれたブラウザ、待つ、テストを実行する

現在、私はwaitbeforeEachを使用して仕様を実行しています。コードは次のとおりです。

const br = browser; 
const url = 'http://localhost:3000'; 

br.ignoreSynchronization = true; 


describe('Component',() => { 
    beforeEach(() => { br.get(url); }); 

    it ('should be present',() => { 
     expect(element(by.className('news-list__wrapper')).isPresent()).toBe(true); 
    }); 

    it ('should render children',() => { 
     br.wait(() => { 
      return element(by.className('news-block')).isPresent(); 
     }, 2500).then((r) => { if (r) { console.log('\n ✓ Component renders children') } }); 
    }); 

    it ('should render images',() => { 
     br.wait(() => { 
      return element.all(by.className('news-block__img')).first().isPresent(); 
     }, 2500).then((r) => { if (r) { console.log('\n ✓ Component renders images') } }); 
    }); 

    it ('should load images',() => { 
     br.wait(() => { 
      return element(by.className('news-block__image--loaded')).isPresent(); 
     }, 2500).then((r) => { if (r) { console.log('\n ✓ Component loads images') } }); 
    }) 
}) 

私は何ができますか?

答えて

1
あなたはAPIドキュメントを参照することができ、このについての詳細は calls-なAJAX用 browser.wait()

使用ExpectedConditionsからhttp://www.protractortest.org/#/api?view=ProtractorExpectedConditions

const br = browser; 
const url = 'http://localhost:3000'; 
const EC = protractor.ExpectedConditions; 

br.ignoreSynchronization = true; 


describe('Component',() => { 
beforeEach(() => { br.get(url); }); 

it ('should be present',() => { 
    expect(element(by.className('news-list__wrapper')).isPresent()).toBe(true); 
}); 

it ('should render children',() => { 
    br.wait(EC.presenceOf(element(by.className('news-block'))), 2500).then((r) => { if (r) { console.log('\n ✓ Component renders children') } }); 
}); 

it ('should render images',() => { 
    br.wait(EC.presenceOf(element.all(by.className('news-block__img')).first()), 2500).then((r) => { if (r) { console.log('\n ✓ Component renders images') } }); 
}); 

it ('should load images',() => { 
    br.wait(EC.presenceOf(element(by.className('news-block__image--loaded'))), 2500).then((r) => { if (r) { console.log('\n ✓ Component loads images') } }); 
}) 
}) 
1

設定browser.ignoreSynchronization = falseとスクリプトを取得するために、すべてのAJAX呼び出しを待つ作るためにbrowser.waitForAngular()を使用コンプリート。分度器の機能は、ページによって行われたすべての非同期呼び出しが完了するのを待ってから、次のコード行のみを実行することです。

関連する問題