首页 > 解决方案 > 设置 github 操作以从 2 个不同的存储库在 localhost 上运行 cypress 测试

问题描述

我的前端 (repUI) 和 cypress 测试 (repTest) 在单独的存储库中。我正在尝试通过从 repTest 签出来运行测试。一旦设置了 repUI(安装和构建),localhost:8000就可以运行测试了。

到目前为止,设计了以下工作流程:

name: Cypress E2E Tests on Dev

on:
 workflow_dispatch:
 push:
    branches-ignore: [ main ]
 schedule:
    - cron:  '0 0 * * 1-5'
jobs:
 setup:
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        node-version: [14.x]

    steps:
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    
   # Checkout UI repo 
    - name: Checkout voy-frontend repo
      uses: actions/checkout@v2
      with:
        repository: orgName/xyz-frontend
        path: xyz-frontend 
        ssh-key: ${{ secrets.GIT_SSH_KEY }}
        
   # Install voy-f dependancies
    - name: Install dependancies for application
      run: | 
       cd voy-frontend
       pwd
       npm install
      
    - name: Get npm cache directory
      id: npm-cache-dir
      run: |
        echo "::set-output name=dir::$(npm config get cache)"
    - uses: actions/cache@v2
      id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
      with:
        path: ${{ steps.npm-cache-dir.outputs.dir }}
        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.os }}-node-
   
       
    # Run application
    - name: Run application
      run: | 
       pwd
       cd voy-frontend
       npm run serve
       
 cypress-test:
    name: Test
    needs: setup
    runs-on: ubuntu-latest
    steps:
    # Checkout test automation repo 
    - name: git checkout
      uses: actions/checkout@v2
      with:
        ref: main
        
   # Install cypress dependancies
    - name: Cypress install
      uses: cypress-io/github-action@v2
      
    # Run cypress tests  
    - name: Cypress run - localhost
      run: npm run cy:r -- --env TENANT=${{ secrets.TENANT }},CLIENT_ID=${{ secrets.CLIENT_ID }},CLIENT_SECRET=${{ secrets.CLIENT_SECRET }},ORG_SCOPE=${{ secrets.ORG_SCOPE }},G_SCOPE=${{ secrets.G_SCOPE }}  --spec "cypress/integration/specs/Search.feature" --headless --browser chrome 
      
    - uses: actions/upload-artifact@v2
      if: failure()
      with:
        name: cypress-videos
        path: |
         cypress/reports
         cypress/videos
         cypress/screenshots
        retention-days: 1

问题是,如果我为 repUI 运行构建命令npm run serve,应用程序成功启动,但它没有继续进行,而是等待。如果我注释掉 ,则npm run serve所有其他作业都按应有的方式运行。

这是屏幕截图: 在此处输入图像描述

对于构建,它只花了大约 60 秒,然后等到我取消它。如果我总是再次触发工作,情况也是如此。

cypress-test一旦构建准备好,需要做什么才能继续工作。?

标签: cypressgithub-actions

解决方案


推荐阅读