SeleniumHQ / docker-selenium

Provides a simple way to run Selenium Grid with Chrome, Firefox, and Edge using Docker, making it easier to perform browser automation
http://www.selenium.dev/docker-selenium/
Other
7.98k stars 2.51k forks source link

Video file is not saving for Microsoft Edge and Firefox in Dynamic grid #1623

Closed sabbir-aust closed 2 years ago

sabbir-aust commented 2 years ago

What happened?

I've copy pasted the exact same code of both the config.toml file and dynamic grid compose file. Then i've run the "docker compose up" command and run a test. According to the configuration, under my project the test recording video for all the browser type should be available along with a "sessionCapabilities.json" file. But it's saving only video for chrome browser. Not the edge and firefox. The scripts are successfully running on all of the browsers. I've also added the capabilities for different browser like this: Firefox: firefoxOptions.setCapability("se:recordVideo", true); Edge: edgeOptions.setCapability("se:recordVideo", true); chrome: chromeOptions.setCapability("se:recordVideo", true);

Command used to start Selenium Grid with Docker

this is the docker compose file: 

# To execute this docker-compose yml file use `docker-compose -f docker-compose-v3-dynamic-grid.yml up`
# Add the `-d` flag at the end for detached execution
# To stop the execution, hit Ctrl+C, and then `docker-compose -f docker-compose-v3-dynamic-grid.yml down`
version: "3"
services:
  node-docker:
    image: selenium/node-docker:4.3.0-20220628
    volumes:
      - ./test/assets:/opt/selenium/assets
      - ./config.toml:/opt/bin/config.toml
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  selenium-hub:
    image: selenium/hub:4.3.0-20220628
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

this is the config.toml file: 

[docker]
# Configs have a mapping between the Docker image to use and the capabilities that need to be matched to
# start a container with the given image.
configs = [
    "selenium/standalone-firefox:4.3.0-20220628", "{\"browserName\": \"firefox\"}",
    "selenium/standalone-chrome:4.3.0-20220628", "{\"browserName\": \"chrome\"}",
    "selenium/standalone-edge:4.3.0-20220628", "{\"browserName\": \"MicrosoftEdge\"}"
]

# URL for connecting to the docker daemon
# Most simple approach, leave it as http://127.0.0.1:2375, and mount /var/run/docker.sock.
# 127.0.0.1 is used because interally the container uses socat when /var/run/docker.sock is mounted
# If var/run/docker.sock is not mounted:
# Windows: make sure Docker Desktop exposes the daemon via tcp, and use http://host.docker.internal:2375.
# macOS: install socat and run the following command, socat -4 TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock,
# then use http://host.docker.internal:2375.
# Linux: varies from machine to machine, please mount /var/run/docker.sock. If this does not work, please create an issue.
url = "http://localhost:2375"
# Docker image used for video recording
video-image = "selenium/video:ffmpeg-4.3.1-20220628"

# Uncomment the following section if you are running the node on a separate VM
# Fill out the placeholders with appropriate values
#[server]
#host = <ip-from-node-machine>
#port = <port-from-node-machine>

Relevant log output

Test is successfully running but only the chrome browser related video is appearing under a folder named with the session id. Not the edge and firefox.

Operating System

Windows 10

Docker Selenium version (tag)

4.3.0-20220628

diemol commented 2 years ago

If it is working for Chrome but not the others then you are definitely not sending the capability. However, please share a complete code sample I can use to reproduce the issue.

sabbir-aust commented 2 years ago

If it is working for Chrome but not the others then you are definitely not sending the capability. However, please share a complete code sample I can use to reproduce the issue.

Here's the capability: @diemol

@Parameters({"mobileOrDesktop", "deviceName", "shop", "environment", "browser"}) public void setUp(ITestContext ctx, String mobileOrDesktop, String deviceName, String shop, String environment, String browser) throws MalformedURLException, InterruptedException {

    String loginUserName;
    String loginPassword;
    propertyReader = new PropertyReader();
    String applicationUrl = "";
    String host = "localhost";

    DesiredCapabilities dc = new DesiredCapabilities();
    String browsers = browser;

    if (browsers.equalsIgnoreCase("firefox")) {
        //dc = DesiredCapabilities.firefox();
        FirefoxOptions firefoxOptions= new FirefoxOptions();
        dc.setBrowserName(browsers);
        firefoxOptions.setCapability("se:recordVideo", true);
        firefoxOptions.merge(dc);
        driver = new RemoteWebDriver(new URL("http://localhost:4444/"),dc);
    }
    else if((browsers.equalsIgnoreCase("MicrosoftEdge"))){
        EdgeOptions edgeOptions = new EdgeOptions();
        dc.setBrowserName(browsers);
        edgeOptions.setCapability("se:recordVideo", true);
        edgeOptions.merge(dc);
        driver = new RemoteWebDriver(new URL("http://localhost:4444/"),dc);
    }
    else if (browsers.equalsIgnoreCase("chrome")) {
        ChromeOptions chromeOptions = new ChromeOptions();
        if (mobileOrDesktop.equalsIgnoreCase("Mobile")) {
            HashMap<String, String> mobileEmulation  = new HashMap<>();
            mobileEmulation.put("deviceName",deviceName);
            chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
            chromeOptions.setCapability("se:recordVideo", true);
            dc.setCapability(ChromeOptions.CAPABILITY,chromeOptions);
        }else{
        dc.setBrowserName(browsers);
        chromeOptions.addArguments("--disable-dev-shm-usage");
        chromeOptions.setCapability("se:recordVideo", true);
        chromeOptions.merge(dc);
        }
        driver = new RemoteWebDriver(new URL("http://localhost:4444/"),chromeOptions);
    }

       String testName = ctx.getCurrentXmlTest().getName();
       dc.setCapability("name", testName);

    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);

}

Here's the xml file:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

diemol commented 2 years ago

For example, String browsers = browser;, where does browser come from?

I cannot copy & paste that to my IDE because there are missing values. I do not know how to use that XML file. Can you please share a single method with all the values already there so I can reproduce the issue? I cannot troubleshoot that code.

sabbir-aust commented 2 years ago

Use this browser capability method in any of your selenium test. @diemol

public void setUp() throws MalformedURLException, InterruptedException {

String loginUserName; String loginPassword; String applicationUrl = ""; String host = "localhost"; DesiredCapabilities dc = new DesiredCapabilities(); String browsers = MicrosoftEdge; if (browsers.equalsIgnoreCase("firefox")) { //dc = DesiredCapabilities.firefox(); FirefoxOptions firefoxOptions= new FirefoxOptions(); dc.setBrowserName(browsers); firefoxOptions.setCapability("se:recordVideo", true); firefoxOptions.merge(dc); driver = new RemoteWebDriver(new URL("http://localhost:4444/"),dc); } else if((browsers.equalsIgnoreCase("MicrosoftEdge"))){ EdgeOptions edgeOptions = new EdgeOptions(); dc.setBrowserName(browsers); edgeOptions.setCapability("se:recordVideo", true); edgeOptions.merge(dc); driver = new RemoteWebDriver(new URL("http://localhost:4444/"),dc); } else if (browsers.equalsIgnoreCase("chrome")) { ChromeOptions chromeOptions = new ChromeOptions(); dc.setBrowserName(browsers); chromeOptions.addArguments("--disable-dev-shm-usage"); chromeOptions.setCapability("se:recordVideo", true); chromeOptions.merge(dc); driver = new RemoteWebDriver(new URL("http://localhost:4444/"),chromeOptions); } String testName = Test; dc.setCapability("name", testName); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS); }

sabbir-aust commented 2 years ago

Hi @diemol , I've added the firefoxoptions and edgeoption to the driver and it's now working. Now it's recording video for all the browser. Now i want to save the video folder with the test name instead of session id. For that i have used this line: chromeOptions.setCapability("se:name", testName); in to the browser parameter. It's showing the test name on to the selenium grid session running page but in my project folder it's saving the folder with the session id.

Here's the browser capability code:

public void setUp() throws MalformedURLException, InterruptedException { DesiredCapabilities dc = new DesiredCapabilities(); String testName = "Demo Test"; String browsers = chrome;

if (browsers.equalsIgnoreCase("chrome")) { ChromeOptions chromeOptions = new ChromeOptions(); dc.setBrowserName(browsers); chromeOptions.addArguments("--disable-dev-shm-usage"); chromeOptions.setCapability("se:recordVideo", true); chromeOptions.setCapability("se:name", testName); chromeOptions.merge(dc); driver = new RemoteWebDriver(new URL("http://localhost:4444/"),chromeOptions); } }

Here's the screenshots: https://prnt.sc/bPXNNBVd8-Gy https://prnt.sc/YafWxOEHgsbP

diemol commented 2 years ago

It is not possible. The test name information will be saved into the capabilities file that is saved. From the you could grab de information and potentially have a dashboard.

I'll close this issue as the initial motivation was not a bug but the capabilities were not being sent correctly.

sabbir-aust commented 2 years ago

It is not possible. The test name information will be saved into the capabilities file that is saved. From the you could grab de information and potentially have a dashboard.

I'll close this issue as the initial motivation was not a bug but the capabilities were not being sent correctly.

@diemol can you please provide some resource or any suggestions on how i can grab the information from the json file and create a dashboard??

diemol commented 2 years ago

I don't have anything concrete. My comment is more generic where anyone who is interested in that information needs to build a dashboard from scratch.