How to configure the bitbucket pipeline YAML file to add the selenium chrome image (standalone-chrom
Asked by Dheeraj Singla:

I want to run selenium script (Java, Maven \& Selenium) in bitbucket pipeline. For this I want to use a image [selenium/standalone-chrome](https://hub.docker.com/r/selenium/standalone-chrome) from docker hub. But I don't know how to configure my bitbucket-pipelines.yml for this. Currently I am using below yaml file in my project and I am getting below error on bitbucket pipeline -  
**Error**  
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'

System info: host: '2469e757-cd7e-46a6-815f-e4e651a95a17-5cdxg', ip: '10.36.149.209', os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-1035-aws', java.version: '11.0.3'

*** ** * ** ***

**Note**

I am using selenium hub server(<http://localhost:4444/wd/hub>) to host the selenium/standalone-chrome container and its working fine when I am launching from my local. But giving above error when pipeline is running on bitbucket.

*** ** * ** ***

**Bitbucket YAML file**

    image: maven:3.6.0pipelines:  default:    - parallel:        - step:            name: Build and Test            caches:              - maven            script:            #  - mvn -B verify              - ls -l /opt/atlassian/pipelines/agent/build/chromedriver_win32/              - mvn test            after-script:              # Collect checkstyle results, if any, and convert to Bitbucket Code Insights.              - pipe: atlassian/checkstyle-report:0.3.0        - step:            name: Security Scan            script:              # Run a security scan for sensitive data.              # See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security              - pipe: atlassian/git-secrets-scan:0.5.1                definitions:                  services:                    chrome:                      image: selenium/standalone-chrome


Answers:
author: Theodora Boudale
body: Hi [@Dheeraj Singla](/t5/user/viewprofilepage/user-id/5225836),

I'm not familiar with Selenium, but I see that you are not actually using the service you have defined in any step. Additionally, the **definitions:** keyword should be at the same level as **pipelines:** (I am not sure if the indentation looks the same in your yml file, or if it got messed up here during copy-paste).

If selenium is used in the first step, you could try a yml as follows:

```
image: maven:3.6.0

pipelines:
  default:
    - parallel:
      - step:
          name: Build and Test
          services:
            - chrome
          caches:
            - maven
          script:
            # - mvn -B verify
            - ls -l /opt/atlassian/pipelines/agent/build/chromedriver_win32/
            - mvn test
          after-script:
            # Collect checkstyle results, if any, and convert to Bitbucket Code Insights.
            - pipe: atlassian/checkstyle-report:0.3.0
      - step:
          name: Security Scan
          script:
            # Run a security scan for sensitive data.
            # See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
            - pipe: atlassian/git-secrets-scan:0.5.1

definitions:
  services:
    chrome:
      image: selenium/standalone-chrome
```

Just to give you some context, Pipelines builds run in Docker containers. For every step of your build, a Docker container starts (the build container) using the image you have specified in your bitbucket-pipelines.yml file (in your case maven:3.6.0). If you use a service for a step, then a second Docker container will start for the service (using the image you have specified for the service) which will share a network adapter with your build container and open its ports on localhost.

You can have a look at the following guide if you would like to debug this locally with Docker (For step 3, make sure to check Testing with build services before starting the build container locally):

* <https://confluence.atlassian.com/bbkb/debug-pipelines-locally-with-docker-1167698072.html>

Kind regards,  
Theodora


Tags: bitbucket-pipelines

docker

java