量角器在配置文件中定义规范

时间:2015-12-13 01:06:47

标签: javascript angularjs protractor

如何使用量角器完成以下操作?...我最终要做的是在节点中的“specBuilder.js”中构建这些规范,然后在配置文件中传递它们...试图计算尽可能做到这一点。

尝试实现如下语法

https://github.com/angular/protractor/blob/master/docs/api-overview.md

// An example configuration file
exports.config = {
    // The address of a running selenium server.
    seleniumAddress: 'http://localhost:4444/wd/hub',

    // Capabilities to be passed to the webdriver instance.
    capabilities: {
        'browserName': 'chrome'
    },

    // Spec patterns are relative to the configuration file location passed
    // to protractor (in this example conf.js).
    // They may include glob patterns.
    specs: [
        function(){
            describe('angularjs homepage', function() {
                it('should greet the named user', function() {
                    // Load the AngularJS homepage.
                    browser.get('http://www.angularjs.org');

                    // Find the element with ng-model matching 'yourName' - this will
                    // find the <input type="text" ng-model="yourName"/> element - and then
                    // type 'Julie' into it.
                    element(by.model('yourName')).sendKeys('Julie');

                    // Find the element with binding matching 'yourName' - this will
                    // find the <h1>Hello {{yourName}}!</h1> element.
                    var greeting = element(by.binding('yourName'));

                    // Assert that the text element has the expected value.
                    // Protractor patches 'expect' to understand promises.

                    expect(greeting.getText()).toEqual('Hello Julie!');
                });
            });
        },
        function(){
            describe('angularjs homepage', function() {
                it('should greet the named user', function() {
                    // Load the AngularJS homepage.
                    browser.get('http://www.angularjs.org');

                    // Find the element with ng-model matching 'yourName' - this will
                    // find the <input type="text" ng-model="yourName"/> element - and then
                    // type 'Julie' into it.
                    element(by.model('yourName')).sendKeys('Julie');

                    // Find the element with binding matching 'yourName' - this will
                    // find the <h1>Hello {{yourName}}!</h1> element.
                    var greeting = element(by.binding('yourName'));

                    // Assert that the text element has the expected value.
                    // Protractor patches 'expect' to understand promises.

                    expect(greeting.getText()).toEqual('Hello Julie!');
                });
            });
        }
    ],

    // Options to be passed to Jasmine-node.
    jasmineNodeOpts: {
        showColors: true, // Use colors in the command line report.
    }
};

1 个答案:

答案 0 :(得分:0)

我发现的解决方案是提供一个spec文件,例如specBuilder.js。然后,在此文件中,您可以通过使用循环和需要以编程方式定义其余测试。