【问题标题】:Using Protractor with proxypass-based AngularJS app将 Protractor 与基于 proxypass 的 AngularJS 应用程序一起使用
【发布时间】:2016-10-18 15:22:24
【问题描述】:

我正在使用 Protractor 在我的 AngularJS 应用程序上使用 Grunt 实现端到端测试,并且我的应用程序确实使用代理传递来处理 API 调用。结果,在运行测试时,API 调用失败,因为 http://localhost:9000/api 未处理。

我尝试使用grunt-connect-proxy 插件来处理/api 代理通行证,但它只是将(HTTP 代码301)localhost:9000/api 重定向到myserver.com/api,并且不模仿代理通行证的行为(并且应用程序不会也不行)。

这是 Gruntfile 配置:

connect: {
    options: {
        port: 9000,
        hostname: 'localhost',
        base: ['<%= globals.appFolder %>/'],
        logger: 'dev',
    }
},

protractor: {
    options: {
        configFile: 'tests/e2e/protractor.config.js',
        keepAlive: true,
        noColor: false,
        args: {}
    },
    e2e: {
        options: {
           args: {}
        }
    }
}

这是量角器配置文件:

exports.config =  {
    specs: ['./suites/*.js'],
    baseUrl: 'http://localhost:9000',
    maxSessions: 1,
    multiCapabilities: [{
        browserName: 'chrome'
    }],
};

您将如何处理这种情况以让测试在桌面计算机和远程计算机上运行(例如 Jenkins)?

【问题讨论】:

    标签: angularjs protractor proxypass


    【解决方案1】:

    根据 grunt-connect-proxy 上相关的this issue,这是处理 HTTPS 端点时发生的错误。请改用master/ 版本。

    包.json:

    "grunt-connect-proxy": "https://github.com/drewzboto/grunt-connect-proxy#master",
    

    Gruntfile:

    proxies: [{
        context: '/api',
        host: 'myserver.com',
        port: 443,
        https: true
    }]
    

    【讨论】:

      猜你喜欢
      • 2014-05-13
      • 1970-01-01
      • 2017-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多