Firefox Profile
With Selenium WebDriver, it's possible to set a custom Firefox profile, which will be used during your automated tests on TestingBot.
To change preferences and settings within Firefox, you'll need to instantiate a new FirefoxProfile
object and update the properties of the profile.
Change Firefox Profile
In the example below, we'll set the accept language
to Spanish and change the user-agent
header.
require "rubygems"
require "selenium-webdriver"
profile = Selenium::WebDriver::Firefox::Profile.new
profile["general.useragent.override"] = "Custom-Agent" # Change user-agent
profile["intl.accept_language"] = "es" # Setting accept language to Spanish
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
caps["browserName"] = "Firefox"
caps["version"] = "latest"
caps["platform"] = "WIN10"
caps["name"] = "firefox profile example"
driver = Selenium::WebDriver.for(:remote,
:url => "https://API_KEY:API_SECRET@hub.testingbot.com/wd/hub",
:desired_capabilities => caps)
String URL = "https://API_KEY:API_SECRET@hub.testingbot.com/wd/hub";
FirefoxOptions ffOptions = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "Custom-Agent"); // Change user-agent
profile.setPreference("intl.accept_languages", "es"); // Setting accept language to Spanish
ffOptions.setProfile(profile);
ffOptions.setCapability("browserName", "Firefox");
ffOptions.setCapability("version", "latest");
ffOptions.setCapability("platform", "WIN10");
ffOptions.setCapability("name", "firefox profile example");
WebDriver driver = new RemoteWebDriver(new URL(URL), ffOptions);
<require_once('vendor/autoload.php');
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\Firefox\FirefoxProfile;
$profile = new FirefoxProfile();
$profile->setPreference('general.useragent.override', 'Custom-Agent'); // Change user-agent
$profile->setPreference('intl.accept_language', 'es'); // Setting accept language to Spanish
$caps = array(
"version" => "latest",
"browserName" => "Firefox",
"platform" => "WIN10",
"firefox_profile" => $profile,
"name" => "firefox profile example"
);
$web_driver = RemoteWebDriver::create(
"https://API_KEY:API_SECRET@hub.testingbot.com/wd/hub",
$caps
);
import requests
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
# Input capabilities
desired_cap = {
'browserName': 'firefox',
'version': 'latest',
'platform': 'WIN10',
'name': 'firefox profile example'
}
options = Options()
fp = webdriver.FirefoxProfile()
fp.set_preference('general.useragent.override', 'Custom-Agent') # Change user-agent
fp.set_preference('intl.accept_language', 'es') # Setting accept language to Spanish
fp.update_preferences()
options.profile = fp
driver = webdriver.Remote(
command_executor='https://API_KEY:API_SECRET@hub.testingbot.com/wd/hub',
desired_capabilities=desired_cap,
options=options
)
const webdriver = require('selenium-webdriver');
const FirefoxProfile = require("firefox-profile");
const capabilities = webdriver.Capabilities.firefox();
// Input capabilities
capabilities.set("browserName", "firefox");
capabilities.set("platform", "WIN10");
capabilities.set("version", "latest");
capabilities.set("name", "firefox profile example");
const myProfile = new FirefoxProfile();
myProfile.setPreference("general.useragent.override", 'Custom-Agent'); // Change user-agent
myProfile.setPreference("intl.accept_languages", "es"); // Setting accept language to Spanish
myProfile.updatePreferences();
myProfile.encoded(function (err, encodedProfile) {
capabilities.set("firefox_profile", encodedProfile);
var driver = new webdriver.Builder().
usingServer('https://API_KEY:API_SECRET@hub.testingbot.com/wd/hub').
withCapabilities(capabilities).
build();
});
IWebDriver driver;
FirefoxOptions capability = new FirefoxOptions();
capability.AddAdditionalCapability("browserName", "Firefox", true);
capability.AddAdditionalCapability("platform", "WIN10", true);
capability.AddAdditionalCapability("version", "latest", true);
capability.AddAdditionalCapability("name", "firefox profile example", true);
capability.AddAdditionalCapability("key", "your_testingbot_key", true);
capability.AddAdditionalCapability("secret", "your_testingbot_secret", true);
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("general.useragent.override", "Custom-Agent"); // Change user-agent
firefoxProfile.SetPreference("intl.accept_languages", "es"); // Setting accept language to Spanish
capability.Profile = firefoxProfile;
driver = new RemoteWebDriver(
new Uri("https://hub.testingbot.com/wd/hub/"), capability
);