Cypress
Example of running Cypress tests and saving their results on the Apify platform. JSON results are saved to Dataset, videos to Key-value store.
import { Actor } from 'apify';
import fs from 'fs';
import cypress from 'cypress';
import { globby } from 'globby';
import log from '@apify/log';
import 'console.table';
// run tests from specific test file with given configuration
const runOneSpec = (spec) => cypress.run({ config: input, spec });
await Actor.init();
const input = await Actor.getInput();
log.info(`Running tests with following input: ${JSON.stringify(input)}`);
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();
for (const test of tests) {
const result = await runOneSpec(test);
let keyValueStoreLink;
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);
}
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);
}
const summary = testsResultsSummary
.map((test) => {
return {
spec: test?.testSuiteTitle,
passes: test?.totalPassed,
failures: test?.totalFailed,
pending: test?.totalPending,
skipped: test?.totalSkipped,
duration: test?.totalDuration,
};
});
console.table('Summary', summary);
await Actor.exit();
Cypress template
Example of running Cypress tests and saving their results on the Apify platform. JSON results are saved to Dataset, videos to Key-value store.
Getting Started
Install Apify CLI
Using Homebrew
brew install apify/tap/apify-cli
Using NPM
npm -g install apify-cli
Create a new Actor using this template
apify create my-javascript-actor -t project_cypress
Run the Actor locally
cd my-javascript-actor apify run
Deploy on Apify
Log in to Apify
You will need to provide your Apify API Token to complete this action.
apify login
Deploy your Actor
This command will deploy and build the Actor on the Apify Platform. You can find your newly created Actor under Actors -> My Actors.
apify push
Documentation reference
To learn more about Apify and Actors, take a look at the following resources:
Related templates
A simple JavaScript example of core Actor and Apify SDK features. It reads and validates user input with schema, computes a result and saves it to storage.
A scraper example that uses HTTP requests and Cheerio to parse HTML. It's fast, but it can't run the website's JavaScript or pass JS anti-scraping challenges.
Example of a Puppeteer and headless Chrome web scraper. Headless browsers render JavaScript and are harder to block, but they're slower than plain HTTP.
Web scraper example with Crawlee, Playwright and headless Chrome. Playwright is more modern, user-friendly and harder to block than Puppeteer.
Skeleton project that helps you quickly bootstrap `CheerioCrawler` in JavaScript. It's best for developers who already know Apify SDK and Crawlee.
Empty starter Actor. A blank slate with minimal starting code. Useful for quick scripting without having to delete bunch of stuff from other templates.
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.