Skip to content

Commit

Permalink
winson/nodemailer package added
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaybharti committed Jan 25, 2024
1 parent 9a6852a commit 533af57
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 11 deletions.
20 changes: 19 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
"dependencies": {
"@types/mocha": "^10.0.6",
"@types/webdriverio": "^5.0.0",
"appium": "^2.4.1",
"dotenv": "^16.3.1",
"mocha": "^10.2.0",
"nodejs-nodemailer-outlook": "^1.2.4",
"ts-node": "^10.9.2",
"webdriverio": "^8.28.0",
"appium": "^2.4.1"
"winston": "^3.11.0"
}
}
38 changes: 30 additions & 8 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineConfig, devices } from "@playwright/test";
import * as dotenv from "dotenv";
import { on } from "events";

switch (process.env.NODE_ENV) {
case "local":
Expand All @@ -21,16 +22,21 @@ switch (process.env.NODE_ENV) {
}
export default defineConfig({
testDir: "./src",
timeout: 180 * 1000,
expect: { timeout: 180 * 1000 },
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
retries: process.env.CI ? 2 : 1,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
workers: process.env.CI ? 1 : 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
reporter: [
[`./src/utils/report/CustomReporterConfig.ts`],
["html", { open: "always", host: "127.0.0.1", port: 5723 }],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
Expand Down Expand Up @@ -70,12 +76,28 @@ export default defineConfig({
/* Test against branded browsers. */
{
name: "Microsoft Edge",
use: { ...devices["Desktop Edge"], channel: "msedge" },
use: {
...devices["Desktop Edge"],
channel: "msedge",
screenshot: "on",
trace: "on",
video: "on",
headless: false,
viewport: { width: 1920, height: 1080 },
},
},
{
name: "Chrome",
use: {
...devices["Desktop Chrome"],
channel: "chrome",
screenshot: "on",
trace: "on",
video: "on",
headless: false,
viewport: { width: 1920, height: 1080 },
},
},
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
Expand Down
4 changes: 3 additions & 1 deletion src/tests/load/BrowerLoadTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const withTransactionTimer = async (transactionName, events, userActions) => {

async function browserloadTest(page, userContext, events) {
await withTransactionTimer("login", events, async () => {
await page.goto("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login");
await page.goto(
"https://opensource-demo.orangehrmlive.com/web/index.php/auth/login"
);
await page.getByPlaceholder("Username").click();
await page.getByPlaceholder("Username").fill("Admin");
await page.getByPlaceholder("Password").fill("admin123");
Expand Down
65 changes: 65 additions & 0 deletions src/utils/report/CustomReporterConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
FullConfig,
FullResult,
Reporter,
Suite,
TestCase,
TestError,
TestResult,
TestStep,
} from "@playwright/test/reporter";
const winston = require(`winston`);

const console = new winston.transports.Console();
const logger = winston.createLogger({
level: "info",
format: winston.format.json(),
transports: [
// - Write all logs with importance level of `info` or less than it
new winston.transports.File({ filename: "logs/info.log", level: "info" }),
],
});

// Writes logs to console
logger.add(console);

export default class CustomReporterConfig implements Reporter {
constructor(options: { customOption?: string } = {}) {
console.log(`playwright-framework-template ${options.customOption}`);
}

onBegin(config: FullConfig, suite: Suite): void {
logger.info(
`Test Suite Started : ${suite.title} , ${suite.allTests().length} tests`
);
}
onTestBegin(test: TestCase): void {
logger.info(`Test Case Started : ${test.title}`);
}

onTestEnd(test: TestCase, result: TestResult): void {
logger.info(
`Test Case Completed : ${test.title} Status : ${result.status}`
);
}

onStepBegin(test: TestCase, result: TestResult, step: TestStep): void {
if (step.category === `test.step`) {
logger.info(`Executing Step : ${step.title}`);
}
}

onError(error: TestError): void {
logger.error(error.message);
}

onEnd(
result: FullResult
): void | Promise<
| void
| { status?: "passed" | "failed" | "timedout" | "interrupted" | undefined }
| undefined
> {
console.log(`Test Suite Completed : ${result.status}`);
}
}
21 changes: 21 additions & 0 deletions src/utils/report/sendEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var nodeoutlook = require("nodejs-nodemailer-outlook");

function sendEmailReport() {
nodeoutlook.sendEmail({
auth: {
user: "xxxxx",
pass: "password",
},
from: "emailid",
to: "emailid",
subject: "subject",
html: "<b>Pls open attached HTML file</b>",
replyTo: "abhaybharti@gmail.com",
attachments: [
{ filename: "index.html", path: "../../../playwright-report/index.html" },
],
onError: (e: any) => console.log(e),
onSuccess: (i: any) => console.log(i),
});
}
sendEmailReport();

0 comments on commit 533af57

Please sign in to comment.