Back to template gallery


Example of running Cypress tests and saving their results on the Apify platform. JSON results are saved to Dataset, videos to Key-value store.





Use cases






1// Apify SDK - toolkit for building Apify Actors (Read more at
2import { Actor } from 'apify';
3import fs from 'fs';
5// Component and E2E testing library (
6import cypress from 'cypress';
7// File system traversing library (
8import { globby } from 'globby';
9// Apify logging utility library
10import log from '@apify/log';
11// Library for console logging tables
12import 'console.table';
14// this is ESM project, and as such, it requires you to specify extensions in your relative imports
15// read more about this here:
16// import { router } from './routes.js';
18// Helper function to run tests from specific test file with given configuration from INPUT.json
19const runOneSpec = (spec) =>{ config: input, spec });
21// The init() call configures the Actor for its environment. It's recommended to start every Actor with an init()
22await Actor.init();
24// Define the configuration to start the cypress test with - get it from the input of the Actor or use a default config.
25const input = await Actor.getInput() || { baseUrl: "", video: true };`Running tests with following input: ${JSON.stringify(input)}`);
28// Get cypress test files from ./cypress/e2e that end with
29const tests = await globby('./cypress/e2e/*');`Getting tests: ${tests}`);
32const testsResultsSummary = [];
34// Opens an instance of Key-value store (read more
35const kvs = await Actor.openKeyValueStore();
36// Opens an instance of Dataset (read more
37const dataset = await Actor.openDataset();
39// Run tests one by one
40for (const test of tests) {
41    const result = await runOneSpec(test);
42    let keyValueStoreLink;
43    // Save video recording of the test to Key-value store
44    if (result?.config?.video) {
45        const baseName = test.split('/').pop();
46        const file = `./cypress/videos/${baseName}.mp4`;
47        const kvsKeyName = baseName.replaceAll('.', '-');
48        // Saves video to Key-value store under kvsKeyName (read more at
49        await kvs.setValue(kvsKeyName, fs.readFileSync(file), { contentType: 'video/mp4' });
50        keyValueStoreLink = kvs.getPublicUrl(kvsKeyName);
51    }
53    // Transform the test results
54    const transformedResult = {
55        testSuiteTitle: result.runs[0].tests ? result.runs[0].tests[0].title[0] : result.runs[0].spec.baseName,
56        totalPassed: result.totalPassed,
57        totalPending: result.totalPending,
58        totalFailed: result.totalFailed,
59        totalSkipped: result.totalSkipped,
60        totalDuration: result.totalDuration,
61        videoLink: keyValueStoreLink,
62        rawData: result,
63    };
65    // Save transformed test results to Dataset (read more at
66    await dataset.pushData(transformedResult);
67    testsResultsSummary.push(transformedResult);
70// Create a loggable test summary
71const summary = testsResultsSummary
72    .map((test) => {
73        return {
74            spec: test?.testSuiteTitle,
75            passes: test?.totalPassed,
76            failures: test?.totalFailed,
77            pending: test?.totalPending,
78            skipped: test?.totalSkipped,
79            duration: test?.totalDuration,
80        };
81    });
83// Log the summary as a table
84console.table('Summary', summary);
86// Gracefully exit the Actor process. It's recommended to quit all Actors with an exit()
87await Actor.exit();

Cypress test template

Run your Cypress tests on the Apify Platform effectively and easily. The template provides the necessary setup for running the Cypress tests. You can change the Cypress configuration in the input, which is defined by the input schema. The template uses globby library to fetch the Cypress test files and run them within the Actor. The video recordings are stored in Key-value store and the comprehensive test results are stored in the Dataset.

Included features

  • Apify SDK - toolkit for building Actors
  • Input schema - define and easily validate a schema for your Actor's input
  • Dataset - store structured data where each object stored has the same attributes
  • Cypress - JavaScript Component and E2E testing library

How it works

You can easily run your tests on the Apify Platform, just copy-paste your test files into cypress/e2e folder. The tests' names need to end with

You can also customize the test run by specifying other options in the input, e.g. the screen size, video recording, or the default command timeout.

After running the tests, the Apify platform stores the results in a comprehensive way - datasets for JSON results, and key-value store for videos. You can view the results directly on the platform or download them to your local machine using a REST API.

Resources on Cypress test

Already have a solution in mind?

Sign up for a free Apify account and deploy your code to the platform in just a few minutes! If you want a head start without coding it yourself, browse our Store of existing solutions.