mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	docs(ci): add GitHub Actions via containers and sharding example (#15288)
Co-authored-by: Max Schmitt <max@schmitt.mx>
This commit is contained in:
		
							parent
							
								
									7b881cf0fe
								
							
						
					
					
						commit
						5a3f0a7195
					
				@ -130,6 +130,59 @@ Suggested configuration
 | 
				
			|||||||
1. Using `--init` Docker flag or [dumb-init](https://github.com/Yelp/dumb-init) is recommended to avoid special
 | 
					1. Using `--init` Docker flag or [dumb-init](https://github.com/Yelp/dumb-init) is recommended to avoid special
 | 
				
			||||||
   treatment for processes with PID=1. This is a common reason for zombie processes.
 | 
					   treatment for processes with PID=1. This is a common reason for zombie processes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### GitHub Actions (via containers)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GitHub Actions support [running jobs in a container](https://docs.github.com/en/actions/using-jobs/running-jobs-in-a-container) by using the [`jobs.<job_id>.container`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idcontainer) option.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```yml js
 | 
				
			||||||
 | 
					steps:
 | 
				
			||||||
 | 
					  playwright:
 | 
				
			||||||
 | 
					    name: 'Playwright Tests'
 | 
				
			||||||
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
 | 
					    container:
 | 
				
			||||||
 | 
					      image: mcr.microsoft.com/playwright:v1.24.0-focal
 | 
				
			||||||
 | 
					    steps:
 | 
				
			||||||
 | 
					      - uses: actions/checkout@v2
 | 
				
			||||||
 | 
					      - uses: actions/setup-node@v2
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          node-version: '14'
 | 
				
			||||||
 | 
					      - name: Install dependencies
 | 
				
			||||||
 | 
					        run: npm ci
 | 
				
			||||||
 | 
					      - name: Run your tests
 | 
				
			||||||
 | 
					        run: npx playwright test
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Sharding
 | 
				
			||||||
 | 
					* langs: js
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GitHub Actions supports [sharding tests between multiple jobs](https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs) using the [`jobs.<job_id>.strategy.matrix`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) option. The `matrix` option will run a seperate job for every possible combination of the provided options. In the example below, we have 2 `project` values, 10 `shardIndex` values and 1 `shardTotal` value, resulting in a total of 20 jobs to be run.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```yml js
 | 
				
			||||||
 | 
					steps:
 | 
				
			||||||
 | 
					  playwright:
 | 
				
			||||||
 | 
					    name: 'Playwright Tests - ${{ matrix.project }} - Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }}'
 | 
				
			||||||
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
 | 
					    container:
 | 
				
			||||||
 | 
					      image: mcr.microsoft.com/playwright:v1.24.0-focal
 | 
				
			||||||
 | 
					    strategy:
 | 
				
			||||||
 | 
					      fail-fast: false
 | 
				
			||||||
 | 
					      matrix:
 | 
				
			||||||
 | 
					        project: [Chrome, Safari]
 | 
				
			||||||
 | 
					        shardIndex: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 | 
				
			||||||
 | 
					        shardTotal: [10]
 | 
				
			||||||
 | 
					    steps:
 | 
				
			||||||
 | 
					      - uses: actions/checkout@v2
 | 
				
			||||||
 | 
					      - uses: actions/setup-node@v2
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          node-version: '14'
 | 
				
			||||||
 | 
					      - name: Install dependencies
 | 
				
			||||||
 | 
					        run: npm ci
 | 
				
			||||||
 | 
					      - name: Run your tests
 | 
				
			||||||
 | 
					        run: npx playwright test --project=${{ matrix.project }} --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> Note: The `${{ <expression> }}` is the [expression](https://docs.github.com/en/actions/learn-github-actions/expressions) syntax that allows accessing the current [context](https://docs.github.com/en/actions/learn-github-actions/contexts). In this example, we are using the [`matrix`](https://docs.github.com/en/actions/learn-github-actions/contexts#matrix-context) context to set the job variants.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Azure Pipelines
 | 
					### Azure Pipelines
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For Windows or macOS agents, no additional configuration required, just install Playwright and run your tests.
 | 
					For Windows or macOS agents, no additional configuration required, just install Playwright and run your tests.
 | 
				
			||||||
 | 
				
			|||||||
@ -302,6 +302,8 @@ Or if there is a custom folder name:
 | 
				
			|||||||
npx playwright show-report my-report
 | 
					npx playwright show-report my-report
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> The `html` reporter currently does not support merging reports generated across multiple [`--shards`](./test-parallel.md#shard-tests-between-multiple-machines) into a single report. See [this](https://github.com/microsoft/playwright/issues/10437) issue for available third party solutions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### JSON reporter
 | 
					### JSON reporter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user