运行量角器测试接收错误“ReferenceError:模块未定义”

时间:2014-05-14 21:58:51

标签: node.js angularjs testing protractor angularjs-e2e

我试图在Windows机器上设置Protractor测试。我已经启动并运行了服务器,但是当我进行测试时,它失败并且我收到以下错误: ReferenceError:模块未定义"

我使用PageObject Pattern来构建我的测试&测试框架。

在我的测试文件中,我有:

describe('Ticket', function(){
    var etPage = require('ticket-page.js');

    beforeEach(function () {
        etPage.get();
    });

    it('Should set Action', function(){
        browser.debugger();
        etPage.setTicketId(1);
    });
};

在Ticket-page.js类中

var EquityTicketPage = function () {
    this.ticketWrapper = null;

    this.setTicketId = function(id){
        this.ticketWrapper = driver.element(By.ByCssSelector('[data-ticket-id="' + id + '"]'));
    };

    this.get = function () {
        browser.ignoreSynchronization = true;
        browser.get('http://deleted');
    };
};

modules.exports = new EquityTicketPage();

堆栈跟踪指向" modules.exports = new EquityTicketPage();"在tickets-page.js文件中。我不确定它在这条线上的失败。对于这些文件,可能没有正确设置/引用节点。也许它在我的机器上没有正确设置。

我看到了question,并认为配置可能存在问题。我的node_modules文件夹中没有grunt-karma版本,我也不知道是否需要它。

然后看着这个question我想我的配置文件中可能需要一些内容,并注意到我没有文件部分。文件部分指向代码文件所以我应该没问题。

这是我的配置

// A reference configuration file.
exports.config = {
    // ----- How to setup Selenium -----
    //
    // There are three ways to specify how to use Selenium. Specify one of the
    // following:
    //
    // 1. seleniumServerJar - to start Selenium Standalone locally.
    // 2. seleniumAddress - to connect to a Selenium server which is already
    //    running.
    // 3. sauceUser/sauceKey - to use remote Selenium servers via SauceLabs.
    //
    // If the chromeOnly option is specified, no Selenium server will be started,
    // and chromeDriver will be used directly (from the location specified in
    // chromeDriver)

    // The location of the selenium standalone server .jar file, relative
    // to the location of this config. If no other method of starting selenium
    // is found, this will default to
    // node_modules/protractor/selenium/selenium-server...
    seleniumServerJar: null,
    // The port to start the selenium server on, or null if the server should
    // find its own unused port.
    seleniumPort: null,
    // Chromedriver location is used to help the selenium` standalone server
    // find chromedriver. This will be passed to the selenium jar as
    // the system property webdriver.chrome.driver. If null, selenium will
    // attempt to find chromedriver using PATH.
    chromeDriver: null,
    // If true, only chromedriver will be started, not a standalone selenium.
    // Tests for browsers other than chrome will not run.
    chromeOnly: false,
    // Additional command line options to pass to selenium. For example,
    // if you need to change the browser timeout, use
    // seleniumArgs: ['-browserTimeout=60'],
    seleniumArgs: [
    ],

    // If sauceUser and sauceKey are specified, seleniumServerJar will be ignored.
    // The tests will be run remotely using SauceLabs.
    sauceUser: null,
    sauceKey: null,

    // The address of a running selenium server. If specified, Protractor will
    // connect to an already running instance of selenium. This usually looks like
    // seleniumAddress: 'http://localhost:4444/wd/hub'
    seleniumAddress: 'http://localhost:4444/wd/hub',

    // The timeout for each script run on the browser. This should be longer
    // than the maximum time your application needs to stabilize between tasks.
    allScriptsTimeout: 11000,

    // ----- What tests to run -----
    //
    // Spec patterns are relative to the location of this config.
    specs: [
       'e2e/**/*behaviors-e2e.js'
        //'e2e/**/new-tickets-loading-e2e.js'
    ],

    // Patterns to exclude.
    exclude: [],

    //needs newer version
    suites: {
        all: ['e2e/**/*e2e.js'],
        fillDown: ['e2e/**/*e2e.js']
    },

    // ----- Capabilities to be passed to the webdriver instance ----
    //
    // For a full list of available capabilities, see
    // https://code.google.com/p/selenium/wiki/DesiredCapabilities
    // and
    // https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js
    capabilities: {
        browserName: "internet explorer"
        //browserName: "phantomjs"
    },


    // ----- More information for your tests ----
    //
    // A base URL for your application under test. Calls to protractor.get()
    // with relative paths will be prepended with this.
    //baseUrl: 'http://nyqmoe3.ms.com:6060/vikas/#?sessionId=3c94bba7-4a7d-4443-b779-3909c3f90b4d',

    // Selector for the element housing the angular app - this defaults to
    // body, but is necessary if ng-app is on a descendant of <body>
    rootElement: 'html',

    // A callback function called once protractor is ready and available, and
    // before the specs are executed
    // You can specify a file containing code to run by setting onPrepare to
    // the filename string.
    onPrepare: function() {
        // At this point, global 'protractor' object will be set up, and jasmine
        // will be available. For example, you can add a Jasmine reporter with:
        //     jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter(
        //         'outputdir/', true, true));
    },

    // The params object will be passed directly to the protractor instance,
    // and can be accessed from your test. It is an arbitrary object and can
    // contain anything you may need in your test.
    // This can be changed via the command line as:
    //   --params.login.user 'Joe'
    params: {
        login: {
            user: 'Jane',
            password: '1234'
        }
    },

    // ----- The test framework -----
    //
    // Jasmine is fully supported as a test and assertion framework.
    // Mocha has limited beta support. You will need to include your own
    // assertion framework if working with mocha.
    framework: 'jasmine',

    // ----- Options to be passed to minijasminenode -----
    //
    // See the full list at https://github.com/juliemr/minijasminenode
    jasmineNodeOpts: {
        // onComplete will be called just before the driver quits.
        onComplete: null,
        // If true, display spec names.
        isVerbose: false,
        // If true, print colors to the terminal.
        showColors: true,
        // If true, include stack traces in failures.
        includeStackTrace: true,
        // Default time to wait in ms before a test fails.
        defaultTimeoutInterval: 30000
    },

    // ----- Options to be passed to mocha -----
    //
    // See the full list at http://visionmedia.github.io/mocha/
    mochaOpts: {
        ui: 'bdd',
        reporter: 'list'
    },

    // ----- The cleanup step -----
    //
    // A callback function called once the tests have finished running and
    // the webdriver instance has been shut down. It is passed the exit code
    // (0 if the tests passed or 1 if not).
    onCleanUp: function() {}
};

1 个答案:

答案 0 :(得分:10)

这是一个错字。在页面底部使用module,而不是modules

module.exports = new EquityTicketPage();