1

我有以下 Karma 配置


// Karma configuration
// Generated on Thu Oct 24 2013 16:41:13 GMT+0200 (CEST)

module.exports = function(config) {
  config.set({

    // base path, that will be used to resolve files and exclude
    basePath: '',


    // frameworks to use
    frameworks: ['ng-scenario'],


    // list of files / patterns to load in the browser
    files: [
      'lib/jquery.js',
      'test/**/*.js'
    ],


    // list of files to exclude
    exclude: [

    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    reporters: ['progress'],


    // web server port
    port: 9876,

    // cli runner port
    runnerPort: 9100,

    // 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, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['PhantomJS', 'Chrome'],


    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 10000,

    proxies: {
        '/': 'http://localhost:8080/' // Keep this in sync with localhost port in Gruntfile.
    },

    urlRoot: '/_karma_/',

    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
  });
};

我有我的测试用例:


'use strict'

describe("A suite", function() {
  it("contains spec with an expectation", function() {
    browser().navigateTo('/')

    $('#username').val('test@example.com')
    $('#password').val('*******')
    $('.submitLogin').click()       

    expect(browser().location().url()).toBe('/welcome')

  });
});


我可以使用浏览器导航browser().navigateTo('/url');

但我不能强迫它提交我的价值观。有什么想法我怎么能实现它?

4

1 回答 1

1

你需要使用jquery吗?使用类似下面的东西怎么样(这个例子假设登录表单有 id login)?

using('#login').input('username').enter('test@example.com');
using('#login').input('password').enter('*******');
element('.submitLogin').click();

如果 jquery 是必不可少的,您可能会考虑将 jquery 放入一个element(...).query(fn)块中。

于 2013-10-28T09:45:27.093 回答