I'm not able to connect the Automation framework to the dockerise application in CI CD pipeline

19 views Asked by At

Actually I am creating a CI CD pipeline by using docker, jenkins, and automation framework. First, I have dockerise the application by using docker compose.yml file in that there are two services first is for application and other is for mysql database. Then this application is running on localhost:5555. Then i have automation framework. I write a dockerfile or docker compose.yml file and the application is running locally so is it feasible to test the application which is on local server under the container? and my script is not accepting the localhost:5555 url but accepting other server urls.

# Use an official Selenium base image with a specific version
FROM selenium/standalone-chrome:latest

# Set the working directory
WORKDIR /usr/src/app

# Copy the test files into the container
COPY . .

# Install dependencies as root
USER root
RUN apt-get update && \
    apt-get install -y \
    default-jre \
    default-jdk \
    maven

# Switch back to the default Selenium user
USER seluser

# Set the entry point for your tests
ENTRYPOINT ["mvn", "test"]

and the docker compose file

version: "3"
services:
  demo-tests:
    build: .
    depends_on:
      - selenium-hub
      - chrome
    environment:
      - SELENIUM_GRID_URL=selenium-hub:4444/wd/hub
    networks:
      - grid-network

  chrome:
    image: selenium/node-chrome:latest
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_NODE_MAX_SESSIONS=1        
      - SE_NODE_MAX_INSTANCES=1 
    networks:
      - grid-network

  firefox:
    image: selenium/node-firefox:latest
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_NODE_MAX_SESSIONS=1    
      - SE_NODE_MAX_INSTANCES=1 
    networks:
      - grid-network

  selenium-hub:
    image: selenium/hub:latest
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"
    environment:  
      - GRID_MAX_SESSION=10           
      - GRID_BROWSER_TIMEOUT=3000 
      - GRID_TIMEOUT=3000 
    networks:
      - grid-network

networks:
  grid-network:
    driver: bridge

but after running the compose file the script is not accepting the http://localhost:5555/ url

@BeforeMethod
    @Parameters("browser")
    public void setup(String browser) {
        try {
            if (browser.equalsIgnoreCase("chrome")) {
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.addArguments("--ignore-certificate-errors");
                //chromeOptions.addArguments("--headless");
                driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), chromeOptions);
            } else if (browser.equalsIgnoreCase("firefox")) {
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), firefoxOptions);
            }

        } catch (Exception e) {

            if (browser.equalsIgnoreCase("chrome")) {
                WebDriverManager.chromedriver().setup();
                ChromeOptions option = new ChromeOptions();
                option.addArguments("--ignore-certificate-errors");
                option.addArguments("--allow-running-insecure-content");
                //option.addArguments("--headless");
                driver = new ChromeDriver(option);
            } else if (browser.equalsIgnoreCase("firefox")) {
                WebDriverManager.firefoxdriver().setup();
                driver = new FirefoxDriver();
            }

        } finally {

            driver.get("http://localhost:5555/");
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(7, TimeUnit.SECONDS);
        }
    }

I am also expecting what will be the actual flow of the CI CD pipeline in the industry by using docker.

0

There are 0 answers