2016-08-02 6 views
0

ボタンをクリックするとローダーの出現をテストするのに何らかのトラブルがあります。分度器とローダーの項目をクリック

私は、次の3つのテストを持っている:私はgetButtonLoadをクリックすると

it('#exigence1 - display a failing message on button fail ',() => { 
    page.navigateTo(); 
    page.getButtonFail().click(); 
    expect(page.getErrorMessage()).toBeTruthy(); 
    }); 

    it('#exigence2 - display a loader on waiting list ',() => { 
    page.navigateTo(); 
    page.getButtonLoad().click(); 
    expect(page.getLoader()).toBeTruthy(); 
    }); 

    it('#exigence3 - display a list of items on message ',() => { 
    page.navigateTo(); 
    page.getButtonLoad().click(); 
    expect(page.getPokeList()).toBeTruthy(); 
    }); 

、私はリモートフェッチ中にローダーを表示します。このローダーがページに表示されていることをテストする必要がありますが、前の2回目のテストは合格しません。私のページ定義で

buttonClick() { 
    this.showError = false; 
    this.displayLoader = true; 
    this.http.get('http://pokeapi.co/api/v2/pokemon/') 
     .map(res => res.json()) 
     .subscribe(res => { 
     this.pokemons = res.results; 
     this.displayLoader = false; 
     }); 
    } 

:私はこのケースを検証するテストを作成する方法を全く知らない

export class ProtractorDemonstrationPage { 
    navigateTo() { 
    return browser.get('/'); 
    } 

    getPokeList() { 
    return element(by.css('.poke-list')).getText(); 
    } 

    getButtonLoad() { 
    return element(by.css('.btn-primary')); 
    } 

    getButtonFail() { 
    return element(by.css('.btn-warn')); 
    } 

    getErrorMessage() { 
    return element(by.css('.panel-danger')).getText(); 
    } 

    getLoader() { 
    return element(by.css('.loader')).getText(); 
    } 
} 

は、ここに私の実装です。

EDIT:クリックすると、次の命令に進む前にその機能が終了するのを関数が待っていることがわかります。ここに私の問題がある。私はクリックする必要があり、非同期のものを待つことなく、直接私のローダーがそこにいることを確認してください。

EDIT 2:ここでは、関数のコードがあります:

load() { 
    this.showError = false; 
    this.displayLoader = true; 
    this.http.get('http://pokeapi.co/api/v2/pokemon/') 
     .map(res => res.json()) 
     .subscribe(res => { 
     this.pokemons = res.results; 
     this.displayLoader = false; 
     }); 
    } 

は問題がpage.getLoader()とあなたの期待する文である

答えて

0

を行います。 page.getLoader()を呼び出すと、その要素のテキストが返されますが、expect文ではこの関数がブール値を返すことを期待しています。

あなたが返すように)(あなたのpage.getLoaderを変更する必要があります。

return element(by.css('.loader')).isDisplayed(); 

または.getTextを(使用し続ける使用を)だけにご期待文を変更します。

expect(page.getLoader()).toBe('This string'); 
+0

ご協力いただきありがとうございますが、それはです働いていない。分裂器は、非同期のものが終わるのを待ってから期待しているようです。私はこれを防ぐ方法がわかりません... – mfrachet

+0

タイミングの問題のようですが、約束を捨てて試してみてください: page.getButtonLoad()。click()。then(function(){ expect(page.getLoader ())。toBeTruthy(); }); – KCaradonna

+0

まだ動作していません:/ – mfrachet