Code Monkey home page Code Monkey logo

cypresse2e's Introduction

Cypress Page Object Model (POM) Framework

This project is built using Page Object Model (POM) using Cypress . It also supports allure reporting and visual testing .

Setup

  • Clone this repository/download the project
  • Navigate to the cloned folder/downloaded folder
  • Install node and npm using
  • Install the dependencies with respect to this project by npm install
    example: npm install cypress --save-dev
    npm i cypress-plugin-snapshots -S // reference: https://github.com/meinaart/cypress-plugin-snapshots

To Run the tests

To make the command line run options easier, added common run options as scripts in package.json file.

For a simple run of all the feature files in normal mode without any video recording, try

npm run test

For a simple run of all the feature files in normal mode with video recording, try

npm run test:video

To run the tests with specific spec file, try

npm run test -- --spec <Path to the spec file>

To Run through thests using Visual UI

npx cypress open 

Headless

To run the tests in headless mode,

npm run test -- --headless

To run the tests in headed mode,

npm run test -- --headed

Workaround for timeout:

Log error: Cypress verification timed out. ,Command timed out after 30000 milliseconds: increase the time out from 30000 to 100000 in verify.js file inside \nodemodules\cypress\lib\tasks alt text

Supports

  • Allure reporting
  • Integration with Jenkins Integration
  • Run Via CLI command
  • Headless run
  • Failed Screenshots
  • Retries of failed tests

How to configure Allure Reports

download allure framework as zip file and add path to the user environment variable
https://github.com/allure-framework/allure2
Configure allure report settings with cypress
npm i -D @shelex/cypress-allure-plugin
Add Allure plugin to cypress plugins. To do that add the following code snippet of allurewriter inside the plugins/index.js file.

const allureWriter = require('@shelex/cypress-allure-plugin/writer');
module.exports = (on, config) => {
allureWriter(on, config);
return config;
}

Then register the command of allure plugin with cypress/support/index.js file
import '@shelex/cypress-allure-plugin';

Add below to the cypress.json file 1.
"projectId": "ProjectName",
"reporter": "cypress-multi-reporters",
"reporterOptions": {
"configFile": "cypress/support/cypress-multi-reporters.json"
}, 2.
"env":{
"allureResultsPath": "allure-results",
"allure": true
}

  1. Create cypress-multi-reporter.json file add following line to this file
    {
    "reporterEnabled": "@mochajs/json-file-reporter, mochawesome"
    }

How to see allure report

  1. Go to the project folder generate allure report using the below command
    allure generate --clean
    allure open --> It will open the report the in browser
    alt text

Jenkins Integration

In Jenkins pipeline, try to add the following snippet to execute the tests,

pipeline {
    agent { docker { image 'cypress/browsers' } }
    stages {
        stage('build') {
            steps {
                sh 'cd project/'
                sh 'npm install'
                sh 'npm run test' # or custom methods
            }
        }
    }
}

Test Cases Breakdown

Step 1: Adding locators as Key and Value Pairs to the project

  1. Add locator methods inside the locators folder structure. Locators are declared in namespaces as key & value failres.so that we can use them in pages to define the reusable methods.Name the page files Ends with <spec_name>Loc.js so that we wont get confused with the file functionality.
export default{
    txt_email:'input[name="email"]',
    txt_password:'input[name="password"]',
    btn_login:'[data-cy="auth__login__email__button"]'
  

}

Adding locator methods and page methods to the project

  1. Add locator methods to get the locator based on get or contains ,page specific methods inside the pages folder structure. Pages are declared in namespaces so that we can directly call them within the tests without any declarations. Name the page files ends with <spec_name>Page.js so that we wont get confused with the file functionality.
export default{

    getTxt_email:function(){
       return cy.get(loginPageLoc.txt_email)
    },
    getTxt_password:function(){
        return cy.get(loginPageLoc.txt_password)
     },
     getBtn_login:function(){
        return cy.get(loginPageLoc.btn_login)
     },
	 }

  1. For each page add make sure a locator page is added and included within the page file. We need to declare the locator identifiers within the locator file and then need to use that in pages.
import loginPageLoc from "../locators/loginPageLoc";

new spec file Creation in the project

  1. Spec files are created by default cypress standard and we could use all the hooks and definitions that are supported by cypress.

  2. Hooks are added Globally within the support/hooks.js which is included in the support/index.js file.

cypresse2e's People

Contributors

oletishiva avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.