docker 发射测试 selenium /独立 chrome gitlab-ci

7hiiyaii  于 2023-01-04  发布在  Docker
关注(0)|答案(1)|浏览(137)

"圣诞快乐,亲爱的聪明的参与者“

test-dev:
  stage: test
  script:
    - mkdir -p tests/js/screens/diffs
    - docker run --rm -d --name=browser_$CI_JOB_ID -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome
    - npx mocha tests/js/screenshots-* --timeout 50000
    - npx playwright test tests/js/pw_*
    - php artisan test
    - docker stop browser_$CI_JOB_ID
  artifacts:
    when: always
    name: $CI_COMMIT_SHA
    untracked: true
    paths:
      - tests/js/screens
      - tests/js/report
  cache:
    when: always
    paths:
      - storage/framework
      - vendor/ #composer packages
      - node_modules
      - public
    key:
      files:
        - vendor/ #composer packages
        - composer.lock
  tags:
    - test_new_runner

相同的作业,但正在进行重建

test-dev:
    #  allow_failure: true
      stage: test
      image: selenium/standalone-chrome
      script:
        - mkdir -p tests/js/screens/diffs
    #    - docker run --rm -d --name=browser_$CI_JOB_ID -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome
        - npx mocha tests/js/screenshots-* --timeout 50000
        - npx playwright test tests/js/pw_*
        - php artisan test
    #    - docker stop browser_$CI_JOB_ID
      artifacts:
        when: always
        name: $CI_COMMIT_SHA
        untracked: true
        paths:
          - tests/js/screens
          - tests/js/report
      cache:
        when: always
        paths:
          - storage/framework
          - vendor/ #composer packages
          - node_modules
          - public
        key:
          files:
            - vendor/ #composer packages
            - composer.lock
      tags:
        - test_new_runner

我想删除Docker Launch,因为它失败了,但我不知道如何使用它的图像,但如果我使用图像,我没有npx内,我不知道如何做到这一点,有人能帮助这个吗?

g6baxovj

g6baxovj1#

您可以使用基础映像docker:20.10.16,然后安装npx,然后使用service运行docker dind,然后在Docker中运行selenium浏览器。
例如:

test-dev:
  stage: test
  image: docker:20.10.16  
  services:
    - docker:dind  
  script:
    - apk add --update npm
    - mkdir -p tests/js/screens/diffs
    - docker run --rm -d --name=browser_$CI_JOB_ID -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome
    - npx mocha tests/js/screenshots-* --timeout 50000
    - npx playwright test tests/js/pw_*
    - php artisan test
    - docker stop browser_$CI_JOB_ID 
  artifacts:
    when: always
    name: $CI_COMMIT_SHA
    untracked: true
    paths:
      - tests/js/screens
      - tests/js/report
  cache:
    when: always
    paths:
      - storage/framework
      - vendor/ #composer packages
      - node_modules
      - public
    key:
      files:
        - vendor/ #composer packages
        - composer.lock
  tags:  
    - test_new_runner

希望这个管用。

相关问题