业力/硒错误 - 试图访问:http://:9876/?id=77115711

karma / selenium error - trying to access: http://:9876/?id=77115711

我运行

karma start

我得到这个:

INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
INFO [launcher]: Launching browser selenium_chrome with concurrency 5
INFO [launcher]: Starting browser chrome via Remote WebDriver
ERROR [karma]: {"message":"[get(\"http://:9876/?id=77115711\")] Error response status: 13, UnknownError - An unknown server-side error occurred while processing the command. Selenium error: unknown error: unhandled inspector error: {\"code\":-32000,\"message\":\"Cannot navigate to invalid URL\"}\n  (Session info: chrome=63.0.3239.84)\n  (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace i...

它似乎正在尝试访问:

http://:9876/?id=77115711

我的 karma.conf.js 文件看起来像:

module.exports = function (config) {

  var webDriverConfig = {
    hostname: 'qsghub-nprd-lnx-01',
    port: 8080
  };

  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['mocha', 'chai', 'sinon'],

    hostname: ip,

    // list of files / patterns to load in the browser
    files: [
      //cdn
      'https://cdnjs.cloudflare.com/ajax/libs/async/2.1.5/async.min.js',
      'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js',
      'https://cdnjs.cloudflare.com/ajax/libs/node-uuid/1.4.7/uuid.js',
      'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-animate.js',
      'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-route.js',
      'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-sanitize.js',
      'https://cdnjs.cloudflare.com/ajax/libs/angular-mocks/1.6.1/angular-mocks.js',

      // local
      './public/lib/angular-ui-router/release/angular-ui-router.js',
      './public/lib/ng-csv/build/ng-csv.js',
      './public/app.js',
      {pattern: './test/unit/mock-json/*.json', watched: true, served: true, included: false},

      process.env.CDT_KARMA_TEST_PATH || './test/unit/**/**/*.spec.js',

    ],

    exclude: [],


    preprocessors: {
      './public/shared/html/**/*.html':['ng-html2js'],
      './public/shared/js/filter/*.js': ['coverage'],
      './public/shared/js/services/*.js': ['coverage'],
      './public/shared/js/directive/*.js': ['coverage'],
      './public/shared/js/directive/**/*.js': ['coverage'],
      './public/pages/**/view/**/*.html':['ng-html2js'],
      './public/pages/**/**/**/*.js': ['coverage']

    },

    ngHtml2JsPreprocessor: {
      // If your build process changes the path to your templates,
      // use stripPrefix and prependPrefix to adjust it.
      stripPrefix: 'public/',
      // prependPrefix: 'public/',

      // // the name of the Angular module to create
      moduleName: "templates"
  },

    coverageReporter: {
      type: 'lcov',
      dir: 'karma-reports',
      subdir: 'coverage'
    },

    sonarQubeUnitReporter: {
      sonarQubeVersion: '5.x',
      outputFile: 'reports/gunit.xml',
      useBrowserName: false
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['spec', 'coverage', 'sonarqubeUnit'],

    // web server port
    host: 'localhost',
    port: 9876,

    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,

    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,

    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    // start these browsers
    customLaunchers: {
      'selenium_chrome': {
      base: 'WebDriver',
      config: webDriverConfig,
      name: 'Karma',
      browserName: 'chrome',
      pseudoActivityInterval: 30000
      }
    },
    browsers: ['selenium_chrome'],

    //  process.env.USER === dftjenkins

    plugins: [
      // we don't need phantomjs, because --headless chrome removes the need for phantomjs
      'karma-chrome-launcher',
      'karma-jasmine',
      'karma-junit-reporter',
      'karma-chai',
      'karma-mocha',
      'karma-sinon',
      'karma-spec-reporter',
      'karma-read-json',
      'karma-coverage',
      'karma-sonarqube-unit-reporter',
      'karma-ng-html2js-preprocessor',
      'karma-webdriver-launcher'

    ],

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: true,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: 5
  })
};

有谁知道我该如何克服这个错误?

在您的配置中某处有以下行

hostname: ip,

ip有值吗?我认为这就是它试图获得 http://:9876/?id=77115711 而不是 http://something.xyz:9876/?id=77115711

的原因

你还有以下几行

// web server port
host: 'localhost',
port: 9876,

尝试将其更改为这些行,或将其省略,因为 localhost9876 是默认值。

// web server port
hostname: 'localhost',
port: 9876,