Dojo intern set firefox profile name

2020-03-31 04:40发布

问题:

Hi Iam trying to set firefox profile name in environment settings of intern config file.I have tried

environments: [
    { browserName: 'firefox',firefox_profile:'default' },
    {firefox_profile:'default'}
     ],

and

 environments: [
    { browserName: 'firefox',profile:'default' },
    {profile:'default'}
     ],

as well as

 capabilities: {
        'selenium-version': '2.42.0',
        firefox_profile:'default'
    },

as mentioned in Selenium capabilities But still firefox launches with an anonymous profile.

However if I use watir,

 def setup
@browser = Watir::Browser.new :firefox, :profile => 'default'
goto_ecp_console_manage_page
end

browser launches the default profile which is 'kinit-ed'(kerberos)

回答1:

As the Selenium capabilities page you mention points out, the value of firefox_profile must be a Base64-encoded profile. Specifically, you ZIP up a Firefox profile directory, Base64 encode it, and use that string as the value of firefox_profile. The firefox-profile npm package can make this process easier. You'll end up with something like:

environments: [
    { browserName: 'firefox', firefox_profile: 'UEsDBBQACAAIACynEk...'; },
    ...
],

I would recommend storing the profile string in a separate module since it's going to be around 250kb.



回答2:

I used @jason0x43 suggestion to rely on the firefox-profile Node.js module and I've created the following grunt task fireforProfile4selenium. With a simple configuration set into the Gruntfile.js, the plugin writes a file on disk with the Base64 encoded version of a zipped profile!

Here is the grunt configuration:

firefoxProfile4selenium: {
    options: {
        proxy: {
            host: '...',
            port: ...
        },
        bypass: [ 'localhost', '127.0.0.1', '...' ]
    },
    default: {
        files: [{
            dest: 'firefoxProfile.b64.txt'
        }]
    }
}

Here is the plugin:

/*global require, module*/
var fs = require('fs'),
    FirefoxProfile = require('firefox-profile'),
    taskName = 'firefoxProfile4selenium';

module.exports = function (grunt) {
    'use strict';

    grunt.registerMultiTask(taskName, 'Prepares a Firefox profile for Selenium', function () {
        var done = this.async(),
            firefoxProfile = new FirefoxProfile(),
            options = this.options(),
            host = this.options().proxy.host,
            port = this.options().proxy.host,
            bypass = this.options().bypass,
            dest = this.files[0].dest;

        // Set the configuration type for considering the custom settings
        firefoxProfile.setPreference('network.proxy.type', 2);

        // Set the proxy host
        firefoxProfile.setPreference('network.proxy.ftp', host);
        firefoxProfile.setPreference('network.proxy.http', host);
        firefoxProfile.setPreference('network.proxy.socks', host);
        firefoxProfile.setPreference('network.proxy.ssl', host);

        // Set the proxy port
        firefoxProfile.setPreference('network.proxy.ftp_port', port);
        firefoxProfile.setPreference('network.proxy.http_port', port);
        firefoxProfile.setPreference('network.proxy.socks_port', port);
        firefoxProfile.setPreference('network.proxy.ssl_port', port);

        // Set the list of hosts that should bypass the proxy
        firefoxProfile.setPreference('network.proxy.no_proxies_on', bypass.join(','));

        firefoxProfile.encoded(function (zippedProfile) {
            fs.writeFile(dest, zippedProfile, function (error) {
                done(error); // FYI, done(null) reports a success, otherwise it's a failure
            });
        });
    });
};