Wednesday, July 26, 2023

Example of Cypress with BDD framework

Here's an example of how you can use Cypress with a BDD (Behavior-Driven Development) framework like Cucumber.js:

1. Set up your project:

  • Create a new directory for your Cypress tests and navigate to it.
  • Initialize a new npm project: npm init -y
  • Install Cypress: npm install cypress
  • Install Cucumber.js: npm install cucumber

2. Create the required files and folders:

  • Create a new folder called cypress/integration to store your feature files.
  • Inside the integration folder, create a new feature file (e.g., example.feature) and define your BDD scenarios using Gherkin syntax.

3. Write the feature file:

  • Open example.feature and define your BDD scenarios using Gherkin syntax. 
        For Example,


4. Create step definitions:
  • Inside the cypress/integration folder, create a new JavaScript file (e.g., example.steps.js) to define the step definitions for your scenarios.
  • In example.steps.js, import the required Cypress commands and Cucumber's Given, When, and Then functions.
  • Define the step definitions that match the steps in your feature file.

 5. Run the tests:
  • Open the Cypress Test Runner by running npx cypress open.
  • The Cypress Test Runner will open, showing your feature file (example.feature).
  • Click on the feature file to run the tests.

Cypress will execute the steps defined in your feature file using the step definitions you provided. It provides an interactive Test Runner where you can see the execution and results of your tests.


Tuesday, April 25, 2023

NTLM authentication for Cypress

cypress-ntlm-auth

Install the cypress-ntlm-auth package by using the below commands

npm install --save-dev cypress-ntlm-auth

After successfully installing the plugin, we can see the NTLM information in the package.json file






The --save-dev flag stores cypress-ntlm-auth as a development dependency suitable for a testing utility.

Commands

In the file cypress/support/commands.js (or .ts) add this line

import "cypress-ntlm-auth/dist/commands";

Refer to the below example 

Create a function in utility > common.js & use it in another spec file


NOTE: Make sure the HOSTNAME is correct.

See the below example: Import in the spec file and use that function


Now, we are done with our configuration.

The most convenient way to start Cypress with NTLM authentication is

npx cypress-ntlm open

EXAMPLE - Error Message: Not properly configured for NTLM

EXAMPLE - Success Message: Properly configured for NTLM

That is it! Thank you very much for reading!

Refer URL: https://www.npmjs.com/package/cypress-ntlm-auth