2016-12-16 19 views
0

私は現在、分度器を使ってテストを書くことを学んでいます。私は固まっており、簡単なログイン/ログアウトテストを書く正しい方法を理解できません。分度器/角度2の制御フロー

describe('Login with dummy user', function() { 
    browser.ignoreSynchronization = true; 
    browser.get('https://localhost:44311'); 
    element(by.id('userNameInput')).sendKeys('blabla'); 
    element(by.id('passwordInput')).sendKeys('blablapassword'); 
    element(by.id('submitButton')).click(); 
    browser.ignoreSynchronization = false; 
    browser.sleep(2000); 

    it('page should have Inventory title', function() { 
     expect(browser.getTitle()).toEqual('Inventory'); 
    }); 

    it(' page should have logout button', function() { 
     var completedAmount = element.all(by.css('.logoutButton')); 
     expect(completedAmount.count()).toEqual(1); 
    }); 

    describe('clicking loging out button', function() { 
     browser.sleep(2000); 
     element(by.css('[href="/account/signout"]')).click(); 

     it('should redirect to account page', function() { 
      expect(browser.getCurrentUrl()).toEqual('https://localhost:44311/account'); 
     }); 

     it('should display a signed out message', function() { 
      expect(element(by.css('text-success')).getText()).toEqual('You have successfully signed out'); 
     }); 
    }); 
}); 

私は2番目の記述はなく、ブラウザがボタンをクリックし、ログアウト、ブラウザを閉じるだけにしてテストを実行し、失敗しない前に、それが実行されます最初の二つのことを期待しています。

+1

'に関連するすべてのコードをキープそれはあなたの 'it'の中にある。あなたは 'it'ブロックの外に何も置くことができないので、' element(by.id( 'userNameInput')))sendKeys( 'blabla');と他のものを 'it' – FCin

+0

に移動します。物事?それとも、複数にするのではなく、1で複数の期待を持つように強制されていますか? –

+0

関数を作成して関数内に繰り返しコードを残すことができますが、各 'it'はその記述の内容をテストする必要があります。あなたがカップルの期待をする必要がある場合は、することができます。 – FCin

答えて

1

私は、それぞれ以下のように機能し、「やっぱ」「それはブロック内のすべてのコードを維持し、「beforeAll」と内部でログイン&ログアウト機能を維持することをお勧め:

describe('Login with dummy user', function() { 
    beforeAll(function() { 
    // Login Steps 
    // ignore synchronization set to true should have nested then statements 
    // since the synchronization is removed. Example: 
    // 
    // element(by.id('userNameInput')).sendKeys('blabla').then(() => { 
    // element(by.id('passwordInput')).sendKeys('blablapassword').then(() => { 
    //  element(by.id('submitButton')).click(); 
    // }); 
    // }); 
    }); 



    it('page should have Inventory title', function() { 
     expect(browser.getTitle()).toEqual('Inventory'); 
    }); 

    it(' page should have logout button', function() { 
     var completedAmount = element.all(by.css('.logoutButton')); 
     expect(completedAmount.count()).toEqual(1); 
    }); 



    afterAll(function() { 
    //Logout steps 
    }); 

}); 
+0

それは働いた。ありがとうございます –

+0

あなたは大歓迎です! –

関連する問題