Build Website in one Job and run Browser Testing

We have a workflow where initially we build the website, then we start the next jobs on the workflow to run the browser testing. Here is the figure:
Screen Shot 2020-09-03 at 5.45.07 PM

We configured the website to be accessible to a specific URL, we ran the wget command to check if its running, and it returns success.

However, when running the wget command on the browser testing job, it fails because the URL is not valid. We need to connect the browser testing job to the build job.

Can you figure out how to connect the testing job to the website on the build job?

Snippet of the config.yml

version: 2.1
references:
  working_directory: &working_directory "/home/docker_image/application/public_html"

  container_config: &container_config
    docker:
      - image: cloudwaysdocker/docker_debian:php74_mariadb103
    working_directory: *working_directory

dependencies:
  cache_directories:
    - ~/.composer/cache
    - /home/docker_image/application/public_html/

jobs:
  build:
    <<: *container_config
    steps:
      - checkout
      - add_ssh_keys:
          fingerprints:
            - "our finger print"
      - run:
          name: "Add .htaccess"
          command: some command
      - run:
          name: "Install Composer packages"
          command: /usr/local/bin/composer install -n -o
      - run:
          name: "Import database"
          environment:
            DB environment
          command: |
            import command
      - run:
          name: 'Append etc/hosts'
          command: echo "127.0.0.1 dev.pomcollegeconsulting.com" | tee --append /etc/hosts
      - run:
          name: 'Check if dev site is running'
          command: wget http://dev.pomcollegeconsulting.com
      # Save workspace for subsequent jobs (i.e. test)
      - persist_to_workspace:
          root: .
          paths:
            - .

  test_automation:
    workin    g_directory: ~/automation
        parameters:
      env:
        description: Define the TestNG xml file to test, either the STAGING(-DsuiteFile=Tests-STAGING.xml) or PROD(-DsuiteFile=Tests-PROD.xml)
        type: string
        default: -DsuiteFile=Tests-STAGING.xml
    docker:
      - image: circleci/openjdk:16-jdk-buster-browsers

    steps:
      - run:
          name: Download Selenium
          command: curl -O http://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar
      - run:
          name: Start Selenium Server
      command: java -jar selenium-server-standalone-3.141.59.jar
      background: true
  - run:
      name: 'Check if dev site is running'
      command: wget http://dev.pomcollegeconsulting.com
  - run:
      name: Clone and run the automation repository
      command: |
          git clone "test repo"
          cd test repo name
          git fetch origin
          mvn clean install << parameters.env >>

  - store_test_results:
      path: test repo/target/surefire-reports

  - store_artifacts:
      path: test repo/target/surefire-reports

workflows:
  version: 2.1
  test:
    jobs:
      - build
      - test_automation:
      name: DEV Chrome
      env: -DsuiteFile=Tests-DEV-Chrome.xml
      requires:
        - build
  - test_automation:
      name: DEV Firefox
      env: -DsuiteFile=Tests-DEV-Firefox.xml
      requires:
        - build

Hello,

It’s not possible for jobs to communicate with each other this way. Everything that your tests need to run must be contained within the job itself. Meaning you cannot start a service in one job and have a different job access the services through local networking.

You could consider removing the build job and have both your test jobs perform the build/test functions in parallel. You could also keep the separation of build/test, but you’ll need to have the website accessible locally in both test jobs. You cannot spin it up in the build job, and then access it from the test jobs.

It may be helpful to try getting the build/test working in a single job first.

Hi @fernfernfern
Thank you for your reply. I tried combining the build/test into 1 job, overall the job failed because of: “mvn: command not found”. The primary container image is a custom PHP image, while the image with maven+browsers is secondary, and the steps are executed on the primary image right?

Can you explain to me how to make the website accessible to both test jobs? I’m a newbie when it comes to this stuff.

Hello,

Yes I understand this can be difficult if you’re new. So it would be good to understand how everything works within a single job first. Once you have it working in a single job, you can duplicate the job, so that it runs your second set of tests in parallel. And once you have that working it should be much easier to break the build steps from the test steps as you wish. But there’s still some things you should understand about jobs first.

Adding more images to your docker section does not stack the resources into the primary container.

    docker:
      - image: cloudwaysdocker/docker_debian:php74_mariadb103
      - image: maven+browsers-image

This does not append the resources in the maven image to the primary container. The primary container image must contain all of the resources needed to produce your build/test. This may require that you build your own custom docker image with all the tools, or you can manually install them at runtime with a run command. The additional images you provide are typically service images, and they are usually database resources or other backend resources required for your app to run. You can read about the differences here in the docs in more detail.

In your case it seems like you only need a primary container image, but it needs additional tools. Either through adding them to your custom image, or manually installing them in your config. That will allow you to call maven and get the build running.

Hi @fernfernfern,
Thanks for the additional clarification with regards to the Primary containers.
As you said, we can use one image for the container and install additional tools, that include the maven and browsers required for testing.

You mentioned earlier that we can make the files from the build job accessible to the test job right? How does this work? Because maybe I can start the website using the files on the build job and run it manually on the test job before proceeding to the actuals browser tests.

Yes it’s possible to pass build artifacts downstream between workflow jobs through the use of workspaces. This is how you can prepare artifacts in one job, and then following jobs can “attach” the workspace to access the artifacts.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.