Skip to content

Commit 06117f5

Browse files
authored
feat: add Chrome for Testing to cypress/factory build process (#1371)
* feat: add Chrome for Testing to cypress/factory build process * correct typo * add chrome for testing notes - not availabile for linux/arm64
1 parent db13772 commit 06117f5

File tree

11 files changed

+114
-3
lines changed

11 files changed

+114
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ Cypress officially [supports][Cypress Browser Support] the latest 3 major versio
5555

5656
### Chrome for Testing
5757

58-
[Google Chrome for Testing][Chrome for Testing] is an alternate version of Chrome which is supported by [Cypress 13.17.0](https://docs.cypress.io/app/references/changelog#13-17-0) and above. The [examples/chrome-for-testing](./examples/chrome-for-testing/) directory shows how it can be built into a custom Cypress Docker image.
58+
The [Google Chrome for Testing][Chrome for Testing] browser is supported by [Cypress 13.17.0](https://docs.cypress.io/app/references/changelog#13-17-0) and above.
59+
60+
[cypress/factory](./factory/) provides the parameter [CHROME_FOR_TESTING_VERSION](./factory/README.md#chrome_for_testing_version) to optionally add Chrome for Testing to a custom image. The [examples/chrome-for-testing](./examples/chrome-for-testing/) directory describes an alternate way to install Chrome for Testing into a custom image using the [@puppeteer/browsers command-line utility](https://pptr.dev/browsers-api). At this time, Chrome for Testing is not included in [cypress/browsers](./browsers/) or [cypress/included](./included/) images. Chrome for Testing is currently not available for the `linux/arm64` platform.
5961

6062
### Mozilla geckodriver
6163

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ workflows:
273273
[
274274
test-factory-electron,
275275
test-factory-chrome,
276+
test-factory-chrome-for-testing,
276277
test-factory-chrome-non-root-user,
277278
test-factory-firefox,
278279
test-factory-edge,

examples/chrome-for-testing/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ Note that Chrome for Testing is currently not available for the `linux/arm64` pl
66

77
## Docker
88

9+
The example below downloads Chrome for Testing using [@puppeteer/browsers](https://pptr.dev/browsers-api).
10+
11+
[cypress/factory](../../factory/) also supports building a custom Docker image with Chrome for Testing using the parameter [CHROME_FOR_TESTING_VERSION](../../factory/README.md#chrome_for_testing_version) which must be a full version specification. This is more restrictive than the example below with [@puppeteer/browsers](https://pptr.dev/browsers-api), which has the flexibility of using a version alias, such as `stable` or a short version specification.
12+
913
### Docker build and run
1014

1115
In this example we use a customized `Dockerfile` which bases a new image on `cypress/base`, copies the complete Cypress project into the image, including installed dependencies, then installs the Cypress binary and Chrome for Testing into the image.
1216

13-
The file is [examples/chrome-for-testing/Dockerfile](./Dockerfile). It has the following contents which build a custom Docker image using the `stable` version of Chrome for Testing:
17+
The file is [examples/chrome-for-testing/Dockerfile](./Dockerfile). It has the following contents which build a custom Docker image using the `stable` version of Chrome for Testing, downloaded with [@puppeteer/browsers](https://pptr.dev/browsers-api):
1418

1519
```dockerfile
1620
FROM cypress/base

factory/.env

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ NODE_VERSION="${FACTORY_DEFAULT_NODE_VERSION}"
1818

1919
# Update the FACTORY_VERSION to deploy cypress/factory if you make changes to
2020
# BASE_IMAGE, FACTORY_DEFAULT_NODE_VERSION, YARN_VERSION, factory.Dockerfile or installScripts
21-
FACTORY_VERSION='5.10.0'
21+
FACTORY_VERSION='5.11.0'
2222

2323
# Chrome versions: https://www.ubuntuupdates.org/package/google_chrome/stable/main/base/google-chrome-stable
2424
# Linux/amd64 only
2525
CHROME_VERSION='137.0.7151.68-1'
2626

27+
# Chrome for Testing versions: https://googlechromelabs.github.io/chrome-for-testing/
28+
# not currently used for cypress/browsers and cypress/included images
29+
# Linux/amd64 only
30+
CHROME_FOR_TESTING_VERSION='137.0.7151.70'
31+
2732
# Cypress versions: https://www.npmjs.com/package/cypress
2833
CYPRESS_VERSION='14.4.1'
2934

factory/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change log
22

3+
## 5.11.0
4+
5+
- Added ability to install Google [Chrome for Testing](https://developer.chrome.com/blog/chrome-for-testing/) with `CHROME_FOR_TESTING_VERSION`. Addresses [#1367](https://github.com/cypress-io/cypress-docker-images/issues/1367).
6+
37
## 5.10.0
48

59
- Updated Debian base image to `debian:12.11-slim` using [Debian 12.11](https://www.debian.org/News/2025/20250517), released on May 17, 2025. Addresses [#1352](https://github.com/cypress-io/cypress-docker-images/issues/1352).

factory/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Node.js
66
- Yarn v1 Classic
77
- Chrome
8+
- Chrome for Testing
89
- Firefox
910
- geckodriver
1011
- Edge
@@ -76,6 +77,16 @@ Example: `CHROME_VERSION='131.0.6778.264-1'`
7677

7778
This browser is currently available only for the `Linux/amd64` platform.
7879

80+
### CHROME_FOR_TESTING_VERSION
81+
82+
The version of [Google Chrome for Testing](https://developer.chrome.com/blog/chrome-for-testing/) to install. If the `ARG` variable is unset or an empty string, Chrome for Testing is not installed.
83+
84+
Example: `CHROME_FOR_TESTING_VERSION='137.0.7151.70'`
85+
86+
Refer to [Chrome for Testing availability](https://googlechromelabs.github.io/chrome-for-testing/) for current versions or [available downloads](https://googlechromelabs.github.io/chrome-for-testing/files) for other versions.
87+
88+
The parameter `CHROME_FOR_TESTING_VERSION` can be used for custom-built images based on `cypress/factory`. The browser is however not currently built into `cypress/browsers` or `cypress/included` images and is currently available only for the `Linux/amd64` platform.
89+
7990
### FIREFOX_VERSION
8091

8192
The version of Mozilla Firefox to install. If the `ARG` variable is unset or an empty string, Firefox is not installed. The exact version must be used, no wildcards or shorthands are supported.

factory/docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ services:
8888
- ${REPO_PREFIX-}cypress/chrome:${CHROME_VERSION}
8989
command: google-chrome --version
9090

91+
chrome-for-testing:
92+
image: '${REPO_PREFIX-}cypress/chrome-for-testing'
93+
build:
94+
target: default_image
95+
context: .
96+
args:
97+
NODE_VERSION: ${NODE_VERSION}
98+
FACTORY_VERSION: ${FACTORY_VERSION}
99+
CHROME_FOR_TESTING_VERSION: ${CHROME_FOR_TESTING_VERSION}
100+
tags:
101+
- ${REPO_PREFIX-}cypress/chrome-for-testing:${CHROME_FOR_TESTING_VERSION}
102+
command: chrome --version
103+
91104
edge:
92105
image: ${REPO_PREFIX-}cypress/edge
93106
build:
@@ -154,6 +167,20 @@ services:
154167
- ${REPO_PREFIX-}cypress/cypress-chrome:cypress-${CYPRESS_VERSION}-chrome-${CHROME_VERSION}
155168
command: node -v
156169

170+
cypress-chrome-for-testing:
171+
image: ${REPO_PREFIX-}cypress/cypress-chrome
172+
build:
173+
target: default_image
174+
context: .
175+
args:
176+
NODE_VERSION: ${NODE_VERSION}
177+
FACTORY_VERSION: ${FACTORY_VERSION}
178+
CYPRESS_VERSION: ${CYPRESS_VERSION}
179+
CHROME_FOR_TESTING_VERSION: ${CHROME_FOR_TESTING_VERSION}
180+
tags:
181+
- ${REPO_PREFIX-}cypress/cypress-chrome-for-testing:cypress-${CYPRESS_VERSION}-chrome-for-testing-${CHROME_FOR_TESTING_VERSION}
182+
command: node -v
183+
157184
cypress-edge:
158185
image: ${REPO_PREFIX-}cypress/cypress-edge
159186
build:

factory/factory.Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ ONBUILD ARG CHROME_VERSION
9393

9494
ONBUILD RUN node /opt/installScripts/chrome/install-chrome-version.js ${CHROME_VERSION}
9595

96+
# Install Chrome for Testing: optional
97+
ONBUILD ARG CHROME_FOR_TESTING_VERSION
98+
99+
ONBUILD RUN node /opt/installScripts/chrome-for-testing/install-chrome-for-testing-version.js ${CHROME_FOR_TESTING_VERSION}
100+
96101
# Install Edge: optional
97102
ONBUILD ARG EDGE_VERSION
98103

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#! /bin/bash
2+
3+
# Download locations on https://googlechromelabs.github.io/chrome-for-testing/ - see JSON endpoints
4+
5+
wget --no-verbose -P /tmp/chrome-for-testing https://storage.googleapis.com/chrome-for-testing-public/${1}/linux64/chrome-linux64.zip
6+
unzip /tmp/chrome-for-testing/chrome-linux64.zip -d /tmp/chrome-for-testing
7+
mv /tmp/chrome-for-testing/chrome-linux64 /opt/chrome-for-testing
8+
apt-get update
9+
while read -r pkg
10+
do
11+
apt-get satisfy -y --no-install-recommends "${pkg}"
12+
done < /opt/chrome-for-testing/deb.deps
13+
ln -fs /opt/chrome-for-testing/chrome /usr/local/bin/chrome
14+
rm -rf /tmp/chrome-for-testing
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/node
2+
const { spawn } = require('child_process')
3+
4+
const chromeVersion = process.argv.slice(2)[0]
5+
6+
if (!chromeVersion) {
7+
console.log('No Chrome for Testing version provided, skipping Chrome for Testing install')
8+
process.exit(0)
9+
}
10+
11+
if (process.arch !== 'x64') {
12+
console.log(`Chrome for Testing only available for x64. Not currently available for architecture: ${process.arch}`)
13+
process.exit(0)
14+
}
15+
16+
console.log('Installing Chrome for Testing version: ', chromeVersion)
17+
18+
// Insert logic here if needed to run a different install script based on chrome version.
19+
const install = spawn(`${__dirname}/default.sh`, [chromeVersion], { stdio: 'inherit' })
20+
21+
install.on('error', function (error) {
22+
console.log('child process errored with ' + error.toString())
23+
process.exit(1)
24+
})
25+
26+
install.on('exit', function (code) {
27+
console.log('child process exited with code ' + code.toString())
28+
process.exit(code)
29+
})

0 commit comments

Comments
 (0)