2016-12-16 3 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'); 
     }); 
    }); 
}); 

나는 두 번째는 설명하기 전에 처음 두가 실행 것이라고 기대하지만, 브라우저는 버튼, 로그 아웃은, 브라우저를 닫고에만 다음 테스트를 실행하고 실패 할 클릭합니다.

+1

'에 관련된 모든 코드를 유지 그것은'그것'안에 있습니다. 당신은'it' 블록 밖에 아무것도 저장할 수 없으므로'element (by.id ('userNameInput')). sendKeys ('blabla');와 다른 것을'it'에 옮깁니다 – FCin

+0

하지만 어떻게하면 2를 테스트 할 수 있습니까? 소지품? 아니면 그것을 여러 개 갖는 대신 1 개로 여러 개의 기대를해야합니까? –

+0

함수를 만들고 함수 안에 반복 된 코드를 유지할 수 있지만, 각각의 함수는 설명에있는 내용을 테스트해야합니다. 당신이 몇 가지 기대를해야한다면, 당신은 할 수 있습니다. – FCin

답변

1

I는 각각 아래와 같은 기능 "Afterall는" '그'블록 내부의 모든 코드를 유지하고 "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

당신은 오신 것을 환영합니다! –