Getting Started - spryker-projects/cypress-boilerplate GitHub Wiki

Overview

This guide will help you get started with Cypress-Boilerplate by walking you through the process of cloning the repository, installing dependencies, and running tests against the Spryker Marketplace B2B demo shop. After confirming the functionality of the tests, you can then integrate Cypress-Boilerplate into your custom project.

❗ If you are new to Cypress:

Prerequisites

Before you begin, ensure you have the following installed on your machine:

â„šī¸ Tips

Node installation

You can install Node.js using NVM (Node Version Manager) if you need different versions of Node.js for different projects.

Step 1: Fork and Clone Cypress-Boilerplate Repository

First, fork the Cypress-Boilerplate repository to your GitHub account. Then clone the forked repository to your local machine.

git clone https://github.com/your-username/cypress-boilerplate.git cypress-boilerplate
cd cypress-boilerplate

Step 2: Install Dependencies

Navigate to the project directory and install the required dependencies.

npm install

Step 3: Clone & install Spryker Marketplace B2B Demo Shop

To run the Cypress-Boilerplate tests against the Spryker Marketplace B2B demoshop, you need to clone and install the demo shop repository.

Step 4: Run Cypress-Boilerplate Tests

Navigate back to the Cypress-Boilerplate directory and run the tests against the Spryker Marketplace B2B demo shop.

cd ../cypress-boilerplate
npx cypress open

In the Cypress Test Runner, select the test suite you want to run. This will execute the tests against the Spryker Marketplace B2B demo shop to ensure they are functional.

Step 5: Run Tests Against Your Custom Project

Now, try running the tests against your custom project. Make sure your project is set up and running locally or on a test environment.

Update Configuration

Ensure that the URLs in your Cypress configuration match the URLs of your custom project. You can update these settings in the .env.local file or relevant configuration files.

Update Test Data

Review and update the test data in the fixtures directory to match your custom project. The fixtures directory contains JSON files with test data that the tests rely on.

  • Locate the relevant fixture files in the cypress/fixtures directory.
  • Update the test data to match the data in your custom project.
// Example: Updating test data in a fixture file

{
  "username": "custom_username",
  "password": "custom_password"
}

Running the Tests

npx cypress run

Troubleshooting

If the tests fail, follow these steps to troubleshoot:

1. Check the Logs

Review the test logs in the Cypress Test Runner or the terminal output for any error messages. This can help identify the cause of the failure.

2. Verify URLs

Ensure that the tests are running against the correct URLs. Check the URLs in your Cypress configuration and compare them with the URLs of your custom project.

3. Update Test Data

Review and update the test data in the fixtures directory to match your custom project. The fixtures directory contains JSON files with test data that the tests rely on.

  • Locate the relevant fixture files in the cypress/fixtures directory.
  • Update the test data to match the data in your custom project.

4. Update Page Object Models

If the UI elements or locators or API endpoints in your custom project differ from those in the Spryker Marketplace B2B demo shop, update the page object models, and/or API endpoints in Cypress-Boilerplate to match your project.

  • Locate the relevant
    • page object files in the cypress/support/page-objects directory.
    • API endpoint files in the cypress/support/glue-endpoints directory.
  • Update the locators to match the elements in your custom project.
  • Update the API endpoints to match your custom project.
// Example: Updating a locator in a page object file

const loginForm = 'form[name="loginForm"]'

export class LoginPage extends AbstractPage {
  getEmailField = (): Cypress.Chainable => {
    return cy.get(loginForm).find('#loginForm_email')
  }
}
// Example: Updating API endpoint

export class AccessTokens extends GlueRequest {
  protected ENDPOINT_NAME = '/access-tokens'

  getCustomerAccessToken = (
    email: string,
    password: string
  ): Cypress.Chainable => {
    return cy.api({
      method: 'POST',
      url: this.GLUE_ENDPOINT,
      headers: {
        'Accept-Language': 'de-DE, de;q=0.9',
      },
      body: {
        data: {
          type: 'access-tokens',
          attributes: {
            username: email,
            password: password,
          },
        },
      },
      failOnStatusCode: false,
    })
  }
}

5. Re-run the Tests

After making the necessary adjustments, re-run the tests to verify that they pass successfully.

npx cypress run

Next Steps

Once the tests are passing against your custom project, you can further customize the Cypress-Boilerplate tests to suit your specific testing requirements. This might include adding new tests, modifying existing tests, or integrating additional testing tools and frameworks.

Happy testing!

âš ī¸ **GitHub.com Fallback** âš ī¸