Skip to content

JavaScript test runner (Cypress)

A cloud test runner for Cypress that saves results and videos.

Create it locally

$scrapely create my-actor --template js-cypress

Main file

.JS
src/main.js
// Library for console logging tables
import 'console.table';

import fs from 'node:fs';

import { Actor, log } from 'scrapely';
// Component and E2E testing library (read more at https://docs.cypress.io/guides/overview/why-cypress)
import cypress from 'cypress';
// File system traversing library (read more at https://www.jsdocs.io/package/globby)
import { globby } from 'globby';

// this is ESM project, and as such, it requires you to specify extensions in your relative imports
// read more about this here: https://nodejs.org/docs/latest-v18.x/api/esm.html#mandatory-file-extensions
// import { router } from './routes.js';

// The init() call configures the Actor to correctly work with the platform-provided environment - mainly the storage infrastructure. It is necessary that every Actor performs an init() call.
await Actor.init();

// Define the configuration to start the cypress test with - get it from the input of the Actor or use a default config.
const input = (await Actor.getInput()) || { baseUrl: 'https://crawlee.dev', video: true };
log.info(`Running tests with following input: ${JSON.stringify(input)}`);

// Helper function to run tests from specific test file with given configuration from INPUT.json
const runOneSpec = (spec) => cypress.run({ config: input, spec });

// Get cypress test files from ./cypress/e2e that end with spec.cy.js
const tests = await globby('./cypress/e2e/*-spec.cy.js');
log.info(`Getting tests: ${tests}`);

const testsResultsSummary = [];

const kvs = await Actor.openKeyValueStore();
const dataset = await Actor.openDataset();

// Run tests one by one
for (const test of tests) {
    const result = await runOneSpec(test);
    let keyValueStoreLink;
    // Save video recording of the test to Key-value store
    if (result?.config?.video) {
        const baseName = test.split('/').pop();
        const file = `./cypress/videos/${baseName}.mp4`;
        const kvsKeyName = baseName.replaceAll('.', '-');
        await kvs.setValue(kvsKeyName, fs.readFileSync(file), { contentType: 'video/mp4' });
        keyValueStoreLink = kvs.getPublicUrl(kvsKeyName);
    }

    // Transform the test results
    const transformedResult = {
        testSuiteTitle: result.runs[0].tests ? result.runs[0].tests[0].title[0] : result.runs[0].spec.baseName,
        totalPassed: result.totalPassed,
        totalPending: result.totalPending,
        totalFailed: result.totalFailed,
        totalSkipped: result.totalSkipped,
        totalDuration: result.totalDuration,
        videoLink: keyValueStoreLink,
        rawData: result,
    };

    await dataset.pushData(transformedResult);
    testsResultsSummary.push(transformedResult);
}

// Create a loggable test summary
const summary = testsResultsSummary.map((test) => {
    return {
        spec: test?.testSuiteTitle,
        passes: test?.totalPassed,
        failures: test?.totalFailed,
        pending: test?.totalPending,
        skipped: test?.totalSkipped,
        duration: test?.totalDuration,
    };
});

// Log the summary as a table
console.table('Summary', summary);

// Gracefully exit the Actor process. It's recommended to quit all Actors with an exit()
await Actor.exit();

JavaScript test runner (Cypress)

A cloud test runner for Cypress that saves results and videos.

Included features

  • Scrapely SDK — Actor lifecycle, input, storage and proxies
  • Cypress — end-to-end browser tests
  • Input schema — define and validate the Actor's input (.actor/input_schema.json)
  • Dataset schema — structured results with a preview view (.actor/dataset_schema.json)

Getting started locally

npm install
npm run start      # run the Actor

Deploying to Scrapely

Create an Actor from this template in the Scrapely Console (Develop new → template → Git). Scrapely creates a repository in your account, pushes this code, and builds the Actor. Every push to your repository triggers a new build.

G2
4.7/5
Excellent
Trustpilot

The internet is full of data.
Start owning yours.

Scrape.ly gives you the infrastructure, the tooling, and the team to extract, process, and operationalize web data at any scale. Setup takes minutes. The advantage lasts forever.

No credit card. No setup calls.