Skip to content

Commit

Permalink
fixed release workflow and added cypress example
Browse files Browse the repository at this point in the history
  • Loading branch information
WasiqB committed Sep 15, 2023
1 parent 30509c6 commit c8884c5
Show file tree
Hide file tree
Showing 14 changed files with 15,350 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
- name: Release
run: npm run release.ci -- ${{github.event.inputs.releaseType}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ reports/
.DS_Store
yarn.lock
*.tgz

videos/
screenshots/
downloads/
*.ndjson
9 changes: 9 additions & 0 deletions examples/cypress/.cypress-cucumber-preprocessorrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"json": {
"enabled": true
},
"messages": {
"enabled": false
},
"stepDefinitions": ["cypress/e2e/[filepath].step.{js,ts}"]
}
73 changes: 73 additions & 0 deletions examples/cypress/cucumber-html-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const report = require("multiple-cucumber-html-reporter");
const dayjs = require("dayjs");
const fs = require("fs");

const data = fs.readFileSync("./reports/cypress-report.json", {
encoding: "utf8",
flag: "r",
});
const runInfo = JSON.parse(data);

const osName = () => {
switch (runInfo["osName"]) {
case "win32":
return "windows";
case "linux":
return "ubuntu";
default:
console.log("Undefined OS");
}
};

const browserName = () => {
switch (runInfo["browserName"]) {
case "chrome":
return "Chrome";
case "firefox":
return "Firefox";
case "edge":
return "Edge";
case "webkit":
return "Safari";
default:
console.log("Undefined Browser");
}
};

report.generate({
jsonDir: "./reports/cucumber-json",
reportPath: "./reports",
metadata: {
browser: {
name: browserName(),
version: runInfo["browserVersion"],
},
platform: {
name: osName(),
version: runInfo["osVersion"],
},
},
customData: {
title: "Run Info",
data: [
{ label: "Project", value: "Sample " },
{ label: "Release", value: "1.0.0" },
{ label: "Cypress Version", value: runInfo["cypressVersion"] },
{ label: "Node Version", value: runInfo["nodeVersion"] },
{
label: "Execution Start Time",
value: dayjs(runInfo["startedTestsAt"]).format(
"YYYY-MM-DD HH:mm:ss.SSS"
),
},
{
label: "Execution End Time",
value: dayjs(runInfo["endedTestsAt"]).format("YYYY-MM-DD HH:mm:ss.SSS"),
},
],
},
pageTitle: "Sample",
reportName: "Sample",
displayDuration: true,
displayReportTime: true,
});
73 changes: 73 additions & 0 deletions examples/cypress/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const { defineConfig } = require("cypress");
const fs = require("fs");
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const browserify = require("@badeball/cypress-cucumber-preprocessor/browserify");

function createReportJsonMeta(results) {
fs.writeFileSync(
"./reports/generated/results.json",
JSON.stringify(
{
browserName: results.browserName,
browserVersion: results.browserVersion,
osName: results.osName,
osVersion: results.osVersion,
nodeVersion: results.config.resolvedNodeVersion,
cypressVersion: results.cypressVersion,
startedTestsAt: results.startedTestsAt,
endedTestsAt: results.endedTestsAt,
},
null,
"\t"
)
);
}
async function setupNodeEvents(on, config) {
await preprocessor.addCucumberPreprocessorPlugin(on, config);

on("file:preprocessor", browserify.default(config));
on("after:run", async (results) => {
if (results) {
createReportJsonMeta(results);
let sourcePath = "./reports/cucumber-json";
let oldExtension = "cucumber.json";
let newExtension =
results.browserName + "." + new Date().getTime() + ".json";
fs.readdir(sourcePath, (err, files) => {
if (err) {
cy.log("Issue in the file reading");
return;
}

files.forEach((file) => {
const oldFilePath = `${sourcePath}/${file}`;

if (file.endsWith(`.${oldExtension}`)) {
const newFilePath = `${sourcePath}/${file.replace(
`.${oldExtension}`,
`.${newExtension}`
)}`;
fs.rename(oldFilePath, newFilePath, (err) => {
if (err) {
cy.log("Issue in the file renaming");
}
});
}
});
});
}
});

return config;
}

module.exports = defineConfig({
e2e: {
specPattern: "cypress/e2e/**/*.feature",
setupNodeEvents,
defaultCommandTimeout: 60000,
pageLoadTimeout: 60000,
video: false,
reporter: "json",
},
});
6 changes: 6 additions & 0 deletions examples/cypress/cypress/e2e/gmail/gmail.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Gmail Opening

Scenario: Gmail

Given I open the gmail

7 changes: 7 additions & 0 deletions examples/cypress/cypress/e2e/gmail/gmail.step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="Cypress"/>

import { Given } from "@badeball/cypress-cucumber-preprocessor";

Given("I open the gmail", function () {
cy.visit("https://mail.google.com");
});
6 changes: 6 additions & 0 deletions examples/cypress/cypress/e2e/google/google.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Google Opening

Scenario: Google

Given I open the google

9 changes: 9 additions & 0 deletions examples/cypress/cypress/e2e/google/google.step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="cypress" />

import { Given } from "@badeball/cypress-cucumber-preprocessor";

// Import the necessary modules

Given("I open the google", function () {
cy.visit("https://www.google.co.in");
});
5 changes: 5 additions & 0 deletions examples/cypress/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
25 changes: 25 additions & 0 deletions examples/cypress/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions examples/cypress/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading

0 comments on commit c8884c5

Please sign in to comment.