【问题标题】:Ionic Protractor testing, making get requests离子量角器测试,发出获取请求
【发布时间】:2016-07-26 05:06:44
【问题描述】:

我正在测试一个将凭据发送到 api 的登录页面,如果失败则返回“错误”或成功时返回“user@email.com”。如果响应成功,我希望它重定向到另一个页面。到目前为止,这就是我写的全部内容,有人可以帮我解决这个问题吗?因为现在它显示了请求的结果。

describe('点击登录按钮', function() { var 用户名、密码、登录按钮

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('user@gmail.com');
    password.sendKeys('abc12345');

    loginButton.click().then(function() 
    {
        browser.get('http://website.com/api/login?email=user@gmail.com&password=abc12345')
         expect(browser.driver.getCurrentUrl()).toMatch('/menu.recommendedJobs')

    },10000)
})

【问题讨论】:

    标签: ionic-framework protractor


    【解决方案1】:

    您可以使用 nodeJs 中可用的“http”模块发出 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);
    }); 
    

    【讨论】:

      猜你喜欢
      • 2014-03-08
      • 1970-01-01
      • 2022-06-24
      • 1970-01-01
      • 1970-01-01
      • 2019-08-10
      • 1970-01-01
      • 2015-07-05
      • 1970-01-01
      相关资源
      最近更新 更多