Dojo intern set firefox profile name

后端 未结 2 1303
小蘑菇
小蘑菇 2021-01-16 00:26

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

environments: [
    { browserName: \'firefox\',firefox_p         


        
相关标签:
2条回答
  • 2021-01-16 01:00

    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.

    0 讨论(0)
  • 2021-01-16 01:19

    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
                });
            });
        });
    };
    
    0 讨论(0)
提交回复
热议问题