Getting the most out of PHPUnit and Selenium: Customizing Firefox about:config settings

While conducting Selenium tests remotely with PHPUnit and Firefox, a peculiar issue arises where onChange events do not trigger as they normally would when a user is manually operating the browser. To address this, it has been suggested to enable the focusmanager.testmode option in Firefox's preferences by accessing about:config, as outlined in a Selenium bug report.

The challenge lies in implementing this solution when using PHPUnit, which abstracts away the Selenium internals. I am unsure of how to modify the Firefox settings through PHPUnit, so I seek guidance on how this can be accomplished!

(As each test run generates a fresh browser profile, manual adjustments via about:config are impractical.)

Answer №1

Big shoutout to the amazing team at Selenium for providing this fantastic solution!

Quick Tip

To ensure that your test runs smoothly, add this code snippet to your setUp() function:

// Prepare a Firefox mini-profile with focusmanager.testmode=true in about:config
define('FIREFOX_PROFILE',
'UEsDBAoAAAAAADqAxkSBK46tKgAAACoAAAAIABwAcHJlZnMuanNVVAkAA1BZkVM6WZFTdXgLAAEE
6AMAAARkAAAAdXNlcl9wcmVmKCJmb2N1c21hbmFnZXIudGVzdG1vZGUiLCB0cnVlKTsKUEsBAh4D
CgAAAAAAOoDGRIErjq0qAAAAKgAAAAgAGAAAAAAAAQAAAKSBAAAAAHByZWZzLmpzVVQFAANQWZFT
dXgLAAEE6AMAAARkAAAAUEsFBgAAAAABAAEATgAAAGwAAAAAAA==');

protected function setUp()
{
    $this->setDesiredCapabilities(Array('firefox_profile' => FIREFOX_PROFILE));
}

This will set the focusmanager.testmode property to true.

Detailed Instructions

If you want to customize your Firefox profile settings, follow these steps before running your tests:

  1. Create a new folder and populate it with the necessary files for your Firefox profile, including a file named prefs.js where your custom settings are stored.

  2. In the prefs.js file, add the following line of code:

    user_pref("focusmanager.testmode", true);
    
  3. Compress the folder (ensuring that prefs.js is located at the root) and encode it using base64.

For Linux users, streamline the process by executing the following commands:

mkdir firefox-profile
cd firefox-profile
echo 'user_pref("focusmanager.testmode", true);' >> prefs.js
zip -r ../firefox-profile.zip *
base64 < ../firefox-profile.zip

Finally, use the generated base64 value as the "firefox_profile" capability as per the quick tip above.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issues encountered with Selenium Python when buttons are unresponsive and not generating any errors

The buttons seem unresponsive agree_button = driver.find_element_by_xpath('//*[@id="rightsDeclaration"]') submit = driver.find_element_by_xpath('//*[@id="submit-work"]') def initiate_upload(): agree_button.click() ...

Here is a method to capture the redirected URL (href) of an <a> tag that has "href="javascript: return false"" but leads to a different URL when clicked

I am looking for a way to extract the redirected URL from an anchor tag without actually visiting it. I have tried using `selenium` `get_attribute('href')`, but all I get is "javascript: return false". Is there a method to obtain the redirected U ...

Are DIV elements really impossible to click using selenium Web Driver?

Can DIV elements be clicked using selenium Web Driver? For example, I'm having trouble clicking the delete button in Gmail. https://i.stack.imgur.com/zsyio.png I've been trying to locate the element using the XPATH = //div[@aria-label='De ...

Scanning through the correct sequence of WhatsApp web chat list using the Selenium WebDriver

Is there a way to programmatically retrieve all chat divs in WhatsApp Web in the order they are displayed? Currently, using driver.find_elements_by_class_name('_210SC') seems to only fetch the first 20 or so chats in no particular sequence. It ap ...

Tips for effectively assigning rows to specific test cases

I'm currently facing a challenge where I have a series of TestCase instances and need to assign one username and password from the mainreader.py file for each TC. The issue is that I'm not sure how to achieve this. Each time a TC calls the mainre ...

The wait function in selenium does not seem to be properly delaying for the desired element

On page 1, I need to click one specific element. Then, on page 2, a different element must be clicked after the first one. To ensure this sequence is followed, I applied a wait function for the second element on page 2. wait.until(ExpectedConditions.eleme ...

What is the best way to operate multiple individual browsers simultaneously, each with its own distinct mouse cursor?

My goal is to have my application execute multiple automated processes across different web browsers simultaneously, with a focus on simulating mouse movements in each browser concurrently. I'm uncertain about how to accomplish this. I've explor ...

Update in Jenkins: Alterations to Slave User Access

My Jenkins master is connected to a MAC slave through Java WebStart since SSH is not working. An administrator user named 'qalab' is logged into the machine, which never sleeps. The system information of the node is displayed in the image provid ...

PHP code coverage collection remotely

For our current project, we have set up a system where we run PHPUnit tests using Selenium and Curl on a separate development server. Server B hosts an Apache server which serves the website. To begin the testing process, server A synchronizes the project ...

Searching for text contained within a specific class

I am struggling to locate text inside a class with multiple instances of the same name. I have attempted different methods but can't seem to get it right. HTML: <td class="cells"> searchingValue </td> C# var createdUser = driver ...

Form submission using Jquery not functioning properly in Firefox

Having an issue with the .post() function not working on Firefox, but functioning fine on Chrome. This is the code I am using: function saveD() { frm = $('#saveDetailsForm'); $.post(frm.attr('action'), frm.serialize(), fun ...

What is the best method to use Selenium in Python for replicating an entire website?

My intention to copy the site after authentication led me to use webdriver. from selenium import webdriver import myconnutils import re from time import sleep connection = myconnutils.getConnection() # Using Chrome driver driver = webdriver.Chrome(" ...

How can I use Python Selenium webdriver to input text into a text field using send

Below is the HTML code snippet for the text field: <div tabindex="-1" class="_2bXVy"><div tabindex="-1" class="_3F6QL _2WovP"> <div class="_39LWd" style="visibility: visible;">Type a message</div> <div class="_2S1VP copy ...

What causes Firefox (Mobile) to zoom out of my webpage?

After launching my webpage on Google Chrome mobile (android), everything loads perfectly. However, when trying to access the site using Firefox mobile (android), most pages load in a zoomed-out view. The issue is resolved by opening the drop-down menu, but ...

In Python using Selenium, we can extract dynamic content from a nested span element that lacks a class name

I'm currently attempting to extract dynamic content nested within a span structure. Specifically, I am trying to retrieve the text "dynamic content2" which resides in the second span element (with the class of "second span") and is updated frequently. ...

Having difficulty retrieving the data from an excel spreadsheet

I am encountering an issue where my program is returning values like [[Ljava.lang.String;@490ab905 instead of the actual data present in an excel file, specifically the user names. I have used jxl and data provider, but I am not very familiar with data pro ...

Navigating through frames in Selenium can be a bit tricky,

I am having trouble logging into this website. Upon loading the page, a frame appears. I have attempted to switch to the frame without success. public void logon(String Username,String Password,String trns) { Configuration.driver.get(Configuration.U ...

I encountered an issue with Robot framework where it was unable to retrieve the locator. Despite attempting to copy the xpath, I continued to receive the error message stating "unable to find the locator."

Here are the elements I am currently working on automating an application using Robot framework, Selenium in PyCharm tool. As part of this process, I attempted to define a keyword to click on a sidebar entity named "GCC Intelligence", but encountered the ...

Extracting table information from a webpage with PowerShell

As a newcomer to both PowerShell and HTML, I am venturing into the realm of extracting table data from a webpage using the powerful combination of PowerShell and Selenium webdriver. My approach involves automating the process of launching a specific webpag ...

The function `jQuery .html('<img>')` is not functional in Firefox and Opera browsers

This particular code snippet jq("#description" + tourId).html('<b>Opis: </b> '+ data); has been tested and functions correctly in Internet Explorer, Firefox, and Opera. However, when it comes to this specific piece of code jq("#i ...