0

I am trying to run cucumber maven tests on gitlab ci using selenium grid, from the output I have observed that containers for grid setup are up and running.

But I am not able to run my cucumber tests using maven.

Below is my docker-compose.yml

version: "3"
services:
  chrome:
    image: selenium/node-chrome:110.0
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  edge:
    image: selenium/node-edge:110.0
    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

  firefox:
    image: selenium/node-firefox:110.0
    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

  selenium-hub:
    image: selenium/hub:latest
    container_name: selenium-hub
    depends_on:
      - java-maven
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

  java-maven:
    image: maven:3.8-openjdk-11

When I tried with below gitlab-ci.yml

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"

stages:
  - test
  
services:
  - docker:20.10.16-dind

test:
  stage: test
  image: docker:latest
  before_script:
    - docker-compose up -d
    - sleep 10
  script:
    - mvn ${MAVEN_OPTS} test -Dcucumber.filter.tags=${FEATURE_TAG} 
  artifacts:
    when: always
    name: "report"
    paths:
      - test-output/*
    expire_in: 1 h

I got "mvn: not found" error.

So I tried to run it inside the java-maven service by changing snippet of script section in the above yml with the below snippet:

docker run -it --rm -v "$(pwd)":/opt/maven -w /opt/maven maven:3.8-openjdk-11 mvn ${MAVEN_OPTS} test -Dcucumber.filter.tags=${FEATURE_TAG}

When I tried to run it like that, the job got stuck for a while and afterwards it responded with "the input device is not a TTY".

Kindly requesting to help me resolve the issue and run the tests successfully.

1 Answer 1

1

The problem appears to be with the command you're using to execute Maven inside the java-maven service.

Instead of running the command within the docker run command, you may define it in the GitLab CI job's script section, as seen below:

 script:
  - docker-compose up -d
  - sleep 10
  - docker run --rm --network host -v "$(pwd)":/app -w /app maven:3.8-openjdk-11 mvn ${MAVEN_OPTS} test -Dcucumber.filter.tags=${FEATURE_TAG}

Now, we're putting the current working directory ($(pwd)) within the container at /app and then running the Maven command inside the container. We're also using the —network host option to guarantee that the container can communicate with the Selenium Grid containers operating on the host network.

Additionlly, ensure that mvn is installed locally on your workstation or in the GitLab runner image that you are using. If mvn is not found, you may install it using the following command:

apt-get update && apt-get install -y maven

Install mvn before running the tests by include this command in the before script section.

I hope that help

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.