Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty video in case of fast loading page #216

Closed
danielFesenmeyer opened this issue Jan 20, 2022 · 2 comments
Closed

Empty video in case of fast loading page #216

danielFesenmeyer opened this issue Jan 20, 2022 · 2 comments
Labels

Comments

@danielFesenmeyer
Copy link
Contributor

Description of the problem:
When running a simple test (as shown below) against a fast loading page page such as https://example.org, the recorded video file will be empty. It will just have 262 bytes and when I open it in VLC, there are no playable streams.
When waiting 2 seconds before finishing the test (as shown in the workaround below), the recorded video file contains the expected content: a browser page displaying https://example.org.

If you can't reproduce it with example.org, it should be reproducable with a local default nginx installation (e.g. started with docker). With local nginx, I observed the same behavior.

Btw, I could not reproduce this issue with the url used in lots of your examples: https://bonigarcia.dev/selenium-webdriver-java/

Browser and version: Latest version of Chrome in Docker.

Operating system: 20.04.2-Ubuntu, x86_64

Selenium-Jupiter version: 4.0.1
Selenium-Jupiter use:
Code which produces empty video file:

package org.example;

import io.github.bonigarcia.seljup.DockerBrowser;
import io.github.bonigarcia.seljup.SeleniumJupiter;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openqa.selenium.WebDriver;

import java.time.Duration;

import static io.github.bonigarcia.seljup.BrowserType.CHROME;
import static org.assertj.core.api.Assertions.assertThat;

class RecordingTest {

    @RegisterExtension
    static SeleniumJupiter seleniumJupiter = new SeleniumJupiter();

    @BeforeAll
    static void setup() {
        seleniumJupiter.getConfig().enableRecording();
        seleniumJupiter.getConfig().useSurefireOutputFolder();
    }

    @Test
    void fastLoadingPageRecording(@DockerBrowser(type = CHROME) WebDriver driver) throws Exception {
        driver.navigate().to("https://example.org");

        assertThat(driver.getTitle()).contains("Example");
    }

}

Workaround code which produces non-empty video file:

    @Test
    void fastLoadingPageRecordingWorkaround(@DockerBrowser(type = CHROME) WebDriver driver) throws Exception {
        try {
            driver.navigate().to("https://example.org");

            assertThat(driver.getTitle()).contains("Example");
        } finally {
            Thread.sleep(Duration.ofSeconds(2).toMillis());
        }
    }

Selenium-Jupiter traces:

16:53:01.164 [main] TRACE i.g.b.seljup.SeleniumJupiter - Resolving parameter org.openqa.selenium.WebDriver arg0 (contextId [engine:junit-jupiter]/[class:org.example.RecordingTest], index 0)
16:53:01.171 [main] TRACE i.g.bonigarcia.seljup.config.Config - Property key sel.jup.selenium.server.url not found, using default value
16:53:01.173 [main] TRACE i.g.b.seljup.SeleniumJupiter - Single session false
16:53:02.368 [main] TRACE i.g.b.seljup.CapabilitiesHandler - Getting capabilities for type=interface org.openqa.selenium.WebDriver -- browserType=Optional[CHROME]
16:53:02.388 [main] TRACE i.g.b.seljup.CapabilitiesHandler - Getting options for class org.openqa.selenium.chrome.ChromeOptions
16:53:02.394 [main] TRACE i.g.b.seljup.CapabilitiesHandler - Exception reading preferences of class org.openqa.selenium.chrome.ChromeOptions (org.openqa.selenium.chrome.ChromeOptions.addPreference(java.lang.String, java.lang.Object))
16:53:02.395 [main] TRACE i.g.b.seljup.CapabilitiesHandler - Gathered Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}
16:53:02.403 [main] TRACE i.g.bonigarcia.seljup.OutputHandler - Output folder ./target/surefire-reports/org.example.RecordingTest
16:53:02.404 [main] TRACE i.g.b.seljup.SeleniumJupiter - Put manager io.github.bonigarcia.wdm.managers.ChromeDriverManager@60b4beb4 in map (context id [engine:junit-jupiter]/[class:org.example.RecordingTest])
16:53:02.404 [main] TRACE i.g.b.seljup.SeleniumJupiter - Adding io.github.bonigarcia.wdm.managers.ChromeDriverManager@60b4beb4 to new map (id [engine:junit-jupiter]/[class:org.example.RecordingTest])
16:53:02.415 [main] TRACE i.g.b.wdm.docker.DockerService - Docker image: selenoid/vnc:chrome_97.0
16:53:02.416 [main] DEBUG i.g.b.wdm.cache.ResolutionCache - Resolution chrome-container-latest=97.0 in cache (valid until 17:18:27 20/01/2022 CET)
16:53:02.418 [main] TRACE i.g.bonigarcia.wdm.config.Config - The memory size 256m is equivalent to 268435456 bytes)
16:53:02.421 [main] TRACE i.g.bonigarcia.wdm.config.Config - The memory size 128m is equivalent to 134217728 bytes)
16:53:02.427 [main] INFO  i.g.b.wdm.docker.DockerService - Starting Docker container selenoid/vnc:chrome_97.0
16:53:02.773 [main] TRACE i.g.b.wdm.docker.DockerService - Adding sysadmin capabilty
16:53:02.779 [main] TRACE i.g.b.wdm.docker.DockerService - Using shm size: 268435456
16:53:02.779 [main] TRACE i.g.b.wdm.docker.DockerService - Using network: bridge
16:53:02.779 [main] TRACE i.g.b.wdm.docker.DockerService - Using exposed ports: [4444]
16:53:02.791 [main] TRACE i.g.b.wdm.docker.DockerService - Using mounts: [Mount(type=TMPFS, source=null, target=/tmp, readOnly=null, bindOptions=null, volumeOptions=null, tmpfsOptions=TmpfsOptions(sizeBytes=134217728, mode=null))]
16:53:02.792 [main] TRACE i.g.b.wdm.docker.DockerService - Using envs: [TZ=Etc/UTC, LANG=EN, SCREEN_RESOLUTION=1280x1080x24]
16:53:03.969 [main] TRACE i.g.b.wdm.docker.DockerService - Port list {4444/tcp=[Lcom.github.dockerjava.api.model.Ports$Binding;@56e07a08} -- Exposed port 4444/tcp = [0.0.0.0:49224]
16:53:03.982 [main] TRACE i.g.b.wdm.docker.DockerService - Browser remote URL http://localhost:49224/
16:53:03.983 [main] TRACE i.g.bonigarcia.wdm.WebDriverManager - The Selenium Serverl URL is http://localhost:49224/
16:53:03.986 [main] DEBUG i.g.b.wdm.webdriver.WebDriverCreator - Creating WebDriver object for chrome at http://localhost:49224/ with Capabilities {browserName: chrome, goog:chromeOptions: {args: [--disable-gpu], extensions: []}}
16:53:03.995 [main] TRACE i.g.b.wdm.webdriver.WebDriverCreator - SocketException creating WebDriver object (Connection reset)
16:53:05.016 [main] TRACE i.g.b.wdm.webdriver.WebDriverCreator - Requesting http://localhost:49224/ (the response code is 404)
Jan 20, 2022 4:53:05 PM org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer createTracer
INFO: Using OpenTelemetry for tracing
Jan 20, 2022 4:53:06 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
16:53:06.879 [main] DEBUG i.g.b.wdm.webdriver.WebDriverCreator - The sessionId is e6542eab7e5d7801b27a6fa5fad23a01
16:53:06.887 [main] DEBUG i.g.b.wdm.cache.ResolutionCache - Resolution recorder-container=7.1 in cache (valid until 17:02:54 20/01/2022 CET)
16:53:06.889 [main] TRACE i.g.bonigarcia.wdm.config.Config - The screen resolution 1280x1080x24 corresponds to a video size of 1280x1080
16:53:06.894 [main] INFO  i.g.b.wdm.docker.DockerService - Starting Docker container selenoid/video-recorder:7.1
16:53:06.894 [main] TRACE i.g.b.wdm.docker.DockerService - Adding sysadmin capabilty
16:53:06.894 [main] TRACE i.g.b.wdm.docker.DockerService - Using network: bridge
16:53:06.895 [main] TRACE i.g.b.wdm.docker.DockerService - Using binds: [/home/fed1imb/work/lab/seljupiter-tests/./target/surefire-reports/org.example.RecordingTest:/data:rw]
16:53:06.895 [main] TRACE i.g.b.wdm.docker.DockerService - Using envs: [BROWSER_CONTAINER_NAME=172.17.0.6, FILE_NAME=fastLoadingPageRecording_arg0_chrome_e6542eab7e5d7801b27a6fa5fad23a01.mp4, VIDEO_SIZE=1280x1080, FRAME_RATE=12]
16:53:07.430 [main] INFO  i.g.bonigarcia.wdm.WebDriverManager - Starting recording ./target/surefire-reports/org.example.RecordingTest/fastLoadingPageRecording_arg0_chrome_e6542eab7e5d7801b27a6fa5fad23a01.mp4
16:53:08.678 [main] INFO  i.g.b.wdm.docker.DockerService - Stopping Docker container selenoid/video-recorder:7.1
16:53:08.679 [main] TRACE i.g.b.wdm.docker.DockerService - Stopping container 19a25b4d8a8fb50c7b4633439c8e1f87b890dd52f6738c047a6ec6449ee27781 (timeout 5 seconds)
16:53:09.794 [main] TRACE i.g.b.wdm.docker.DockerService - Removing container 19a25b4d8a8fb50c7b4633439c8e1f87b890dd52f6738c047a6ec6449ee27781
16:53:09.808 [main] TRACE i.g.b.seljup.SeleniumJupiter - Single session false
16:53:09.808 [main] TRACE i.g.b.seljup.SeleniumJupiter - Quitting contextId [engine:junit-jupiter]/[class:org.example.RecordingTest]: (wdmMap={[engine:junit-jupiter]/[class:org.example.RecordingTest]=[io.github.bonigarcia.wdm.managers.ChromeDriverManager@60b4beb4]})
16:53:09.810 [main] DEBUG i.g.bonigarcia.wdm.WebDriverManager - Quitting RemoteWebDriver: chrome on LINUX (e6542eab7e5d7801b27a6fa5fad23a01)
16:53:09.874 [main] INFO  i.g.b.wdm.docker.DockerService - Stopping Docker container selenoid/vnc:chrome_97.0
16:53:09.875 [main] TRACE i.g.b.wdm.docker.DockerService - Stopping container db22964fd1dc5e13eef3764e83822451d7d35403949cead66716c5913748aea9 (timeout 5 seconds)
16:53:10.262 [main] TRACE i.g.b.wdm.docker.DockerService - Removing container db22964fd1dc5e13eef3764e83822451d7d35403949cead66716c5913748aea9
16:53:10.273 [main] TRACE i.g.b.seljup.SeleniumJupiter - Removing managers from map (id [engine:junit-jupiter]/[class:org.example.RecordingTest])
16:53:10.281 [main] TRACE i.g.b.seljup.SeleniumJupiter - Single session false

Error trace: none

@bonigarcia
Copy link
Owner

I also experienced this issue but I think it cannot be solved. I mean, the Docker containers (browser and recorder) need to start. If the elapsed time between the start and the shutdown is too small, the recorder is not able to record properly (the 262 bytes you said).

@danielFesenmeyer
Copy link
Contributor Author

That's a pity. It seems that the testcontainers project solved a similar issue: testcontainers/testcontainers-java#466. But maybe it has a different root cause. Unluckily, I currently don't have time to dig deeper into the topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants