量角器/角度2控制流程

量角器/角度2控制流程

问题描述:

我目前正在学习使用量角器编写测试,我卡住了,无法理解编写简单登录/注销测试的正确方法。量角器/角度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

将您的所有代码相关的'它'在你的'它'里面。你不能将任何东西保留在“块”之外,所以把'element(by.id('userNameInput'))。sendKeys('blabla');'和其他的'it'移到你的''' – FCin

+0

然后我怎么测试2事情呢?或者我*在1中有多个期望,而不是有多个呢? –

+0

你可以制作函数并在函数内部保留重复的代码,但是每个“它”都应该测试它在描述中的含义。如果你必须做出几个期望,你可以。 – FCin

我会建议保持内部“它”阻止所有的代码,并保持里面的“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

不客气! –