2016-07-26 43 views
0

我測試發送憑據的API一個登錄頁面,如果失敗或「[email protected]」成功返回無論是「錯誤」。如果響應是成功的,我希望它重定向到另一頁。到目前爲止,這是我寫的,有人可以幫我解決這個問題?因爲現在它顯示請求的結果。離子量角器測試,使得GET請求

描述( '登錄按鈕點擊',()的函數 { 變種的用戶名,密碼,loginbutton

beforeEach(function(){ 
    browser.get('#/loginPage'); 
    username= element(by.id('username')); 
    password= element(by.id('password')); 
    loginButton= element(by.id('loginButton')); 
}); 

it('should validate the credentials for a successful login and display the recommended view', function() { 

    // 
    username.sendKeys('[email protected]'); 
    password.sendKeys('abc12345'); 

    loginButton.click().then(function() 
    { 
     browser.get('http://website.com/api/[email protected]&password=abc12345') 
     expect(browser.driver.getCurrentUrl()).toMatch('/menu.recommendedJobs') 

    },10000) 
}) 

回答

1

您可以使用 「http」 模塊提供的NodeJS發出HTTP請求,然後處理從API呼叫收到的響應。請看下面的例子

var http = require('http'); 

var options = { 
    host: 'example.com', 
    port: 80, 
    path: '/foo.html' 
}; 

http.get(options, function(resp){ 
    resp.on('data', function(chunk){ 
    //do something with chunk 
    }); 
}).on("error", function(e){ 
    console.log("Got error: " + e.message); 
});