javaseleniumtestingffmpegfirefox-headless

What is the correct way of running test cases(in headless firefox) in xvfb and record the test cases using ffmpeg


https://malinowski.dev/recording-headless-selenium-tests-to-mp4.html this is the link i am using but i don't even know how to do all these.I don't know whether i should run all the commands in that as a single script or should i run the xvfb command in one terminal and then open a new window for ffmpeg command for x11 grab.So,can anyone elaborate the steps for running test cases in xvfb and record the same.


Solution

    1. create a .sh file(for Linux) and enter the below lines
    xvfb-run --listen-tcp --server-num 93 -s "-ac -screen 0 1920x1080x24" (--command for running the program--) &
    export DISPLAY=:93
    ffmpeg -f x11grab -video_size 1920x1080 -i :93 -codec:v libx264 -r 12 video.mp4
    
    1. Add the below lines in the java program for invoking the driver in the same port as the virtual display is opened
    System.setProperty("webdriver.gecko.driver","/home/saran/Downloads/geckodriver");
    Map<String, String> environment = new HashMap<>();
    environment.put("DISPLAY", ":93");
    GeckoDriverService service = new GeckoDriverService.Builder().usingAnyFreePort().withEnvironment(environment).build();
    driver = new FirefoxDriver(service);
    
    1. Finally execute the .sh file