Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/js-cypress/.actor/input_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "string",
"description": "Base url for the tests.",
"editor": "textfield",
"prefill": "https://apify.com"
"prefill": "https://example.com"
},
"viewportWidth": {
"title": "Viewport width",
Expand Down
2 changes: 2 additions & 0 deletions templates/js-cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Run your [Cypress tests](https://www.cypress.io/) on the Apify Platform effectiv

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 `-spec.cy.js`.

The bundled example specs visit [`https://example.com`](https://example.com) — a stable site reserved for documentation — so the demo passes reliably out of the box. Point the tests at your own site by setting the `baseUrl` input (or editing `baseUrl` in `cypress.config.js`); `cy.visit('/')` then resolves against it.

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.
Expand Down
3 changes: 2 additions & 1 deletion templates/js-cypress/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
// to be able to run the tests locally for Apify CLI versions 17.0.0 and older
baseUrl: 'https://apify.com',
// Defaults to a stable demo site; override it via the Actor `baseUrl` input.
baseUrl: 'https://example.com',
},
});
8 changes: 5 additions & 3 deletions templates/js-cypress/cypress/e2e/first-spec.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
describe('first tests suite', () => {
it('visit Apify main page', () => {
it('visits the homepage', () => {
// `baseUrl` is configured in cypress.config.js (and overridable from the
// Actor input), so cy.visit('/') hits whatever site you point it at.
cy.visit('/');
cy.log('Visiting Apify main page');
cy.contains('div', 'Apify').should('exist');
cy.log('Visiting the homepage');
cy.contains('h1', 'Example Domain').should('be.visible');
});
});
14 changes: 8 additions & 6 deletions templates/js-cypress/cypress/e2e/second-spec.cy.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
describe('second tests suite', () => {
it('visit apify store', () => {
cy.visit('/store');
cy.log('Visiting Apify Store, clicking on Actor');
cy.contains('.ActorStoreItem-title', 'Web Scraper').should('be.visible').click();
cy.log('Asserting store Actor redirect');
cy.url().should('eq', 'https://apify.com/apify/web-scraper');
it('finds the outbound link', () => {
cy.visit('/');
cy.log('Locating the outbound link by its target');
// Select the link by its href attribute rather than its text. This is
// robust to copy changes on the page (the visible label may differ) and
// demonstrates asserting on an attribute instead of clicking through to
// another domain, which Cypress restricts across origins.
cy.get('a[href*="iana.org"]').should('be.visible');
});
});
8 changes: 8 additions & 0 deletions templates/js-cypress/cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@
// You can read more here:
// https://on.cypress.io/guides/configuration#section-global
// ***********************************************************

// By default Cypress fails the test if the visited page throws an uncaught
// exception (e.g. a minified React hydration error like #418:
// https://react.dev/errors/418). For an end-to-end demo we only care that the
// page loads and our assertions pass, not that the site's own JavaScript is
// bug-free, so we swallow page-level exceptions and let the test continue.
// Remove this if you want your own tests to fail on the visited site's errors.
Cypress.on('uncaught:exception', () => false);
2 changes: 1 addition & 1 deletion templates/js-cypress/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { globby } from 'globby';
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://apify.com', video: true };
const input = (await Actor.getInput()) || { baseUrl: 'https://example.com', 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
Expand Down
Loading