如何使用 Protractor 与 crossbrowsertesting.com 建立本地连接?

How to make local connections to crossbrowsertesting.com with Protractor?

如何在 crosbrowsertesting.com 的本地网络中使用 Protractor 测试我的 Angular 页面?我安装了 "npm i cbt_tunnels",我的 protractor.conf 看起来像这样:

const cbt = require('cbt_tunnels');
export.config= {
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
  directConnect: false,
  seleniumAddress: 'http://<myusername>:<mykey>@hub.crossbrowsertesting.com:80/wd/hub',
  capabilities : {
    name : 'protractor test', // this will show up in the UI
    // these are important :)
    browserName : "firefox",
    browser_api_name : 'FF39', // change this according to what browser you are using
    os_api_name : 'Win10', // change this for the OS you are using
    screen_resolution : '1024x768', // change this for the resolution
    record_video : 'true',
    record_network : 'true',
    record_snapshot : 'true',
    acceptInsecureCerts: 'true',
    tunnel: 'true'

  },
  onComplete: () => {
    browser.quit();
  },

  onPrepare() {
      cbt.start({"username": "<myusername>", "authkey": 
  "<mykey>"}, function (err) {
        if (!err) console.log("cbt success");
      });
    }

我可以在 crossbrowsertesting.com 看到测试 运行,但那里的浏览器显示: waiting for localhost

缺少什么?

正如评论者所说,您需要先启动本地连接,然后才能真正使用本地连接功能。

在这种情况下,您需要使用这一行: 'cbt.start({"username":"USERNAME","authkey":"AUTHKEY"},function(err){ if(!err) do stuff })' 来自文档;一旦正确设置了本地连接,这将允许您自动开始测试。

在这种情况下,do stuff 就是 运行 你的测试的一切(scaffolding/setup 可以在外部完成)。

这才是您真正想要的

const cbt = require('cbt_tunnels');
cbt.start({"username":"USERNAME","authkey":"AUTHKEY"},
    function(err){ 
        if(!err) do stuff 
    });

编辑: 看起来您想在 beforeLaunch 中启动隧道,而不是在 onPrepare 中,并且需要将其设置为承诺。像这样:

  beforeLaunch: () => {
    return new Promise( (resolve, reject) => {
      cbt.start({"username": "<your email here>", "authkey": "<your auth here>"}, function (err) {
        if (!err) {
          console.log("cbt success");
          return resolve();
        }
        return reject(err);
      });
    })
  }