How to close xvfb after using

I run some tests in headless firefox using Xvfb. However, after completing my tests, I want to return to normal display. But I can’t do it. That's what I'm doing.

  • Open terminal
  • sudo xvfb: 10 -ac &
  • export DISPLAY =: 10
  • Running my tests using RobotFramework + Selenium

After step 4, I want to open firefox in the same terminal, but I cannot see it, since it is aimed at: display 10.

I wonder how I can close this (xvfb: 10) so that I can open firefox and view it.

+6
source share
3 answers

A simple solution is to keep the previous DISPLAY value, change it to point to xvfb, and then after running the test, you can return it back to the saved value.

This causes xvfb to work, so you should also get the pid of this process and kill it. Otherwise, if you run this set of steps a dozen times, you will have a dozen xvfb processes running in the background.

+4
source

& at the end of your second command tells Linux to run this command in the background. You can see a list of background commands with $ jobs . Ubuntu16.04 example:

 $ sudo Xvfb :10 -ac & [1] 31294 $ jobs -l [1]+ 31294 Running sudo Xvfb :10 -ac & 

As you can see in the above, jobs -l shows the background job, and the second output column is the PID , which can be used to destroy it like $ sudo kill 31294 .

Another option, which may be cleaner, is to run Xvfb just to run the command you want and exit automatic mode instead of keeping it in the background. So you replace your lines 2,3 and 4 with:

 xvfb-run python my_selenium_tests.py 

Just replace python my_selenium_tests.py any test run method. It will open Xvfb just for that and will close at the end.

0
source

after using xvfb you have to do two things, first kill the process running in the background to do

 $ps -t - 

and find the xvfb PID and then use

  $kill "the number" 

then you must restore the value of the DISPLAY variable that you saved before the assignment

0
source

Source: https://habr.com/ru/post/972594/


All Articles