Karma如何输入输入字段并使用jquery提交表单

时间:2013-10-24 22:49:25

标签: automated-tests karma-runner

我关注了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');

导航浏览器

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

1 个答案:

答案 0 :(得分:1)

你需要使用jquery吗?如何使用以下内容(该示例假定登录表单具有标识login)?

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

如果jquery是必不可少的,你可以考虑将你的jquery放入element(...).query(fn)块。