Reputation: 427
I have been running tests on our Selenium Grid and have run into a problem using the same xvfb display over - when I run a batch of 100 tests in parallel, most of which are filling in forms / clicking buttons - some tests get stuck entering in text or clicking on the button. This is not a "wait until element" appears issue, we've done that already.
A user on a separate question had 1 answer to the above: Multiple Instances of Firefox during Selenium Webdriver Testing not handling focus correctly.
The solution there worked for running a local Selenium test using FirefoxBinary. I am running a test on a Selenium Grid, meaning that I am creating a Remote webdriver object (in python):
profile = self.get_local_firefox_profile()
profile.set_preference("browser.startup.homepage", "http://www.google.com");
firefox_capabilities = {
"browserName": "firefox",
'platform': "linux",
"javascriptEnabled": True,
}
self.driver = webdriver.Remote(
selenium_hub_address,
firefox_capabilities,
profile
)
The communication through my selenium grid / hub / node are working fine. I am executing the tests on a Jenkins slave -> test creates the remote webdriver -> request goes to a Selenium hub on server A -> which dispatches the browser / test running on server B.
I start up the Selenium node on server B like this:
/usr/bin/Xvfb :0 -nolisten tcp -ac -cc 4 -screen 0 1200x800x24
# tell browsers the address of the xvfb display
export DISPLAY=:0
java -jar selenium-server-standalone-2.46.0.jar -role node -nodeConfig DefaultNode.json
Then after running into problem - 100 parallel tests using this same display, having trouble with form fills - I've seen various people confirm that we should be running each test in a separate xvfb display to make it better.
I decided to test this theory by adding more screens to DISPLAY :0
/usr/bin/Xvfb :0 -nolisten tcp -ac -cc 4 -screen 0 1200x800x24 -screen 1 1200x800x24
-screen 2 1200x800x24 -screen 3 1200x800x24
My main question is: how do you select DISPLAY 0.1, 0.2, 0.3 in python using a remote selenium driver?
If I ran the tests on the same Jenkins slave (forgetting entirely about the grid; having selenium / xvfb / firefox installed on the slave) it seems like that would work fine like this:
firefox_binary = FirefoxBinary('/usr/bin/firefox')
firefox_binary.add_command_line_options('--display=:' + str(display.display))
Or, running locally, there are other options like xvfb-run, pyvirtualwrapper,etc.
I cannot see a way to do it with a remote Firefox driver. You can't use a FirefoxBinary object on Remote driver creation (it's not serializable for one thing and makes no sense really). Has anyone solved this problem?
Upvotes: 3
Views: 1002
Reputation: 427
After getting our selenium grid up and running, I think the problem I was facing for form fills / text entry not working right was not because of using the same display on xvfb. It was for a few reasons: the execution was much faster, fields were getting cleared after data was entered, some issues existed even locally without the grid.
Switching the displays - as I mentioned above - this is a useful technique if you are running locally. Setting that to work on a selenium grid node seems impossible currently.
Upvotes: 0