簡體   English   中英

如何讓實習生運行功能測試

[英]How to get The Intern to run Functional Tests

我正在努力將我們的單元/功能測試框架切換到實習生,但我嘗試的所有不同配置導致實習生只運行單元測試而根本沒有完成功能測試。

Selenium Standalone和ChromeDriver確實在4444端口運行。

我有一個配置文件,如下所示:

// Learn more about configuring this file at <https://github.com/theintern/intern/wiki/Configuring-Intern>.
// These default settings work OK for most people. The options that *must* be changed below are the
// packages, suites, excludeInstrumentation, and (if you want functional tests) functionalSuites.
define({
    // The port on which the instrumenting proxy will listen
    proxyPort: 9000,

    // A fully qualified URL to the Intern proxy
    proxyUrl: 'http://localhost:9000/',

    // Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
    // specified browser environments in the `environments` array below as well. See
    // https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and
    // https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities.
    // Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment
    // automatically
    capabilities: {
        'selenium-version': '2.44.0'
    },

    // Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce
    // OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other
    // capabilities options specified for an environment will be copied as-is
    environments: [
    { browserName: 'chrome' }
    ],

    // Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service
    maxConcurrency: 3,

    // Name of the tunnel class to use for WebDriver tests
    tunnel: 'NullTunnel',

    // The desired AMD loader to use when running unit tests (client.html/client.js). Omit to use the default Dojo
    // loader
    useLoader: {
    'host-node': 'requirejs',
    'host-browser': '../../node_modules/requirejs/require.js'
  },

  reporters: ['pretty'],

    // Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader
    // can be used here
    loader: {
        // Packages that should be registered with the loader in each testing environment
        packages: [
      { name: 'controls', location: './js' },
      { name: 'jquery', location: './node_modules/jquery' }
    ]
    },

  // Turn off connection to Sauce Labs
  useSauceConnect: false,

  // Setup for Selenium Webdriver
  webdriver: {
    host: 'localhost',
    port: 4444
  },

    // Non-functional test suite(s) to run in each browser
    suites: [ 'intern-test/unit/_all' ],

    // Functional test suite(s) to run in each browser once non-functional tests are completed
    functionalSuites: [ 'intern-test/functional/_all' ],

    // A regular expression matching URLs to files that should not be included in code coverage analysis
    excludeInstrumentation: /^(?:test|intern-test|node_modules)\//
});

單元和功能測試套件('_all.js')基本上只是在一個地方加載所有單獨的測試模塊,如下所示:

define([
  './module-one-unit-tests',
], function () {
  // This is just used for loading up all tests at once
  console.log('loaded unit tests');
});



define([
  './module-one-functional-tests',
], function () {
  // This is just used for loading up all tests at once
  console.log('loaded functional tests');
});

我有一個單元測試,看起來像這樣:

define([
  'require'
], function(require) {

  var registerSuite = require('intern!object'),
    expect = require('intern/chai!expect');

  console.log('multiselect tests loaded');

  registerSuite({
    name: 'Multiselect (unit)',

    'passing test': function() {
      var str = '';
      expect(str).to.equal('');
    }

  });

  console.log('registered multiselect tests');

});

並且功能測試看起來像這樣:

define([
  'require'
], function (require) {

  var url = 'http://localhost:4000/tests/multiselect',
    registerSuite =   require('intern!object'),
    expect = require('intern/chai!expect'),
    Keys = require('intern/node_modules/leadfoot/keys');

  function addIds() {
    $('#states-multi-shdo').prev().attr('id', 'states-multi-textbox');
    $('#towns-multi-optgroup-shdo').prev().attr('id', 'towns-multi-optgroup-textbox');
    $('#fruits-multi-shdo').prev().attr('id', 'fruits-multi-textbox');
  }

  function getMultiSelectVal(selector) {
    return $(selector).val();
  }

  var STATES = 'states-multi',
    STATES_TEXTBOX = 'states-multi-textbox',
    FRUITS_TEXTBOX = 'fruits-multi-textbox',
    DDLIST = 'dropdown-list';

  registerSuite({
    name: 'Multiselect (functional)',

    setup: function() {
      return this.remote
        .get(require.toUrl(url))
        .setWindowSize(null, 1024, 768)
        .execute(addIds)
        .sleep(100);
    },

    'will not allow more than the "data-maxselected" attribute\'s specified number of selected options in the list': function () {
      return this.remote
        .findById(STATES_TEXTBOX)
          .click()
          .pressKeys([
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.SPACE, Keys.ARROW_DOWN,
            Keys.ESCAPE
          ])
          .end()
        .findById(STATES)
          .getProperty('selectedOptions')
          .then(function (val) {
            console.log(val);
            expect(val.length).to.equal(10);
          });
    }

  });
});

正如我所說,當我使用node_modules/.bin/intern-client config=intern-test/intern.local啟動測試運行node_modules/.bin/intern-client config=intern-test/intern.local ,單元測試運行完全正常,但功能測試無處可尋。

我已經多次搜索功能測試通用配置的實習文檔了,我似乎無法弄清楚我可能會出錯的地方。

誰能告訴我我是怎么搞砸的?

intern-clientNode.js客戶端 ,只在Node.js中運行單元測試。 intern-runner測試運行器 ,它將對遠程瀏覽器執行單元和功能測試。 你需要使用intern-runner ,而不是intern-client

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM