0

I have got the solutions which is using xvfb to specified a display to selenium, when I test my web program. Envviroments: CentOS6, Selenium2, robotframwork, Firefox. And My steps are:

   startup vncserver specified displaynumber. vncserver :6
   set DISPLAY with same number. DISPLAY=:6
   test my project.
   kill vncserver. vncserver -kill :6

And firefox can startup correctly. Now, I know what to do to startup firefox, but I dont know why. What's the relationship among selenium2, vncserver, xvfb, robotframework? For short, I want to know how selenium2 or robotframework use xserver from vncserver or xvfb. I did not find my answer in http://docs.seleniumhq.org/docs/ and https://github.com/rtomac/robotframework-selenium2library. Anyone knows that? Any references? thx

Nick Dong
  • 3,638
  • 8
  • 47
  • 84
  • I am doing something similar but I use xvfb+robot+selenium. To help you I would need to know 1) what problem are you trying to solve exactly? (is the Centos a VM with no Xwindows? do you want to run your tests headless?) 2) you mention xvfb in your explanation but not in the steps. Does it run on your Centos already? – Laurent Bristiel Sep 18 '13 at 06:59
  • I just configure the enviroments follow a tutorial with steps:`1st_install_vncserver`, `2nd_start_vncserver vncserver :6`, `3rd_install_python`, `4th_install_jdk`, `5th_install_Jenkins`, `6th_start_jenkins`, `7th_install_Xvfb mesa-dri-drivers dbus-x11`, `8th_install_robotframeworkplutin`. And I am confused with vncserver and xvfb. How selenium use vncserver or xvfb to start firefox? Some tutorial only gives steps of the solution but dont tell you why to do like that. My project have run correctly, after I set enviroment variable `DISPLAY=:6`. There is Xwindow in CentOS6. – Nick Dong Sep 18 '13 at 07:34
  • My project works fine after follow this [solution](http://stackoverflow.com/questions/18820410/webdriverexception-message-the-browser-appears-to-have-exited-before-we-could/18822515#18822515). Why did this solution can work? How did selenium know that vncserver has already start, and how did selenium know that variable `DISPLAY` has already been set? – Nick Dong Sep 18 '13 at 07:39

1 Answers1

2

I am not an expert but I will try to give an explanation of how I understand it.

By default, your Centos has no display configured.
It means you can not launch any application that has graphical interface.
So you not launch Firefox.

xvfb and vncserver allow you to set-up such a display. xvfb will create a in-memory display.

Then, "set DISPLAY" will tell your OS which display to use. If you set it to the xvfb you launched, then you are able to launch graphical app on your centos but they will not show up as they are in memory.

Then, for the Robot/Selenium part, they are not aware of all that.
Your Robot Framework test will call Selenium library that will launch Firefox as you would launch it from the command line, so it will be launched on the xvfb display.

So to your question "how did selenium know that variable DISPLAY has already been set?": selenium does not need to know. He sends it to the current DISPLAY and it will be the one you configured.

Hope this helps you to understand.

Laurent Bristiel
  • 6,819
  • 34
  • 52