2013-10-24 52 views
1

提交表單我有以下噶配置噶如何進入輸入字段,並使用jquery

 

// 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('[email protected]') 
    $('#password').val('*******') 
    $('.submitLogin').click()  

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

    }); 
}); 

 

我可以使用瀏覽器browser().navigateTo('/url');

但我不能強迫它提交我的價值觀。任何想法我怎麼能實現它?

回答

1

你需要使用jQuery嗎?如何使用類似以下內容(該示例假定登錄表單的ID爲login)?

using('#login').input('username').enter('[email protected]'); 
using('#login').input('password').enter('*******'); 
element('.submitLogin').click(); 

如果jQuery是必不可少的,你可能會考慮把你的jQuery爲element(...).query(fn)塊。

+0

好的我所做的是使用'element('#login').val('[email protected]')'和你上面提交的登錄描述的一樣。 – Lukasz

+0

由於我忘記了這個問題,我實際上解決了你應得的解決方法@lorcan – Lukasz

+0

偉大的,但請不要標記它,除非答案是正確的(我認爲是這樣)。 – lorcan

相關問題