How do I parameterize the baseUrl property of the protractor config file

前端 未结 3 978
感动是毒
感动是毒 2021-01-03 23:51

I need to run my protractor tests in different contexts with different baseUrls in the config files. I don\'t want to use separate config files for each situati

3条回答
  •  孤街浪徒
    2021-01-04 00:20

    The other option is to use gruntfile.js and have it call the protractor config file.

    //gruntfile.js

    module.exports = function (grunt) {
        grunt.registerTask("default", "", function () {
        });
    
        //Configure main project settings
        grunt.initConfig({
            //Basic settings and infor about our plugins
            pkg: grunt.file.readJSON('package.json'),
    
            //Name of plugin
            cssmin: {
            },
    
            protractor: {
                options: {
                    configFile: "conf.js", // Default config file
                    keepAlive: true, // If false, the grunt process stops when the test fails.
                    noColor: false, // If true, protractor will not use colors in its output.
                    args: {
                        baseUrl: grunt.option('baseUrl') || 'http://localhost:6034/'
                    }
                },
                your_target: {   // Grunt requires at least one target to run so you can simply put 'all: {}' here too.
                    options: {
                        configFile: "conf.js", // Target-specific config file
                        args: {
                            baseUrl: grunt.option('baseUrl') || 'http://localhost:63634/'
                        }
                    }
                },
            },
    
            //uglify
            uglify: {
            }
        });
    
        //Load the plugin
        grunt.loadNpmTasks('grunt-contrib-cssmin');
        grunt.loadNpmTasks('grunt-contrib-uglify');
        grunt.loadNpmTasks('grunt-protractor-runner');
    
        //Do the Task
        grunt.registerTask('default', ['cssmin']);
    };
    

    the Protractor config file: conf.js

    exports.config = {
        directConnect: true,
    
        // Capabilities to be passed to the webdriver instance.
        capabilities: {
            'browserName': 'chrome',
            'chromeOptions': {
                args: ['--no-sandbox']
            }
        },
    
        chromeOnly: true,
    
        // Framework to use. Jasmine is recommended.
        framework: 'jasmine',
    
        // Spec patterns are relative to the current working directory when
        // protractor is called.
        specs: ['specs/*/*_spec.js'],
    
        suites : {
          abcIdentity : 'specs/abcIdentity/*_spec.js'  //picks up all the _spec.js files
        },
    
        params: {
            UserName: 'abc@test.com',
            Password: '123'
        },
    
        // Options to be passed to Jasmine.
        jasmineNodeOpts: {
            defaultTimeoutInterval: 30000,
            includeStackTrace: true
        },
    
        onPrepare: function () {
            browser.driver.manage().window().maximize();
            if (process.env.TEAMCITY_VERSION) {
                var jasmineReporters = require('jasmine-reporters');
                jasmine.getEnv().addReporter(new jasmineReporters.TeamCityReporter());
            }
        }
    };
    

    //To run with default url http://localhost:6034

    grunt protractor
    

    //To run with any other url

    grunt protractor --baseUrl:"http://dev.abc.com/"
    

提交回复
热议问题