Skip to content

Commit

Permalink
Fixed negative cases and running behavior for hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
gevorg-vardanyan-im committed May 24, 2024
1 parent 1f8d2e4 commit 2b047bc
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 120 deletions.
5 changes: 3 additions & 2 deletions frameworks/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ export default defineConfig({
testDir: "./tests",
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
["list"],
// ["list"],
// ["dot"],
["../../index.js"]
],
globalTimeout: 60 * 60 * 1000,

// /* Run tests in files in parallel */
// fullyParallel: true,
fullyParallel: false,

// /* Fail the build on CI if you accidentally left test.only in the source code. */
// forbidOnly: !!process.env.CI,
Expand Down
224 changes: 205 additions & 19 deletions frameworks/playwright/tests/example.spec.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,229 @@
const { test, expect } = require("@playwright/test");
import it from "@playwright/test";
import { setTimeout } from "timers/promises";
const dummyTimeout = 700;

// test.afterEach(async ({ page }) => {
// await page.waitForTimeout(300);
// });

test.describe.only("Existing test cases in suite", function () {
it("@C402 verify 142 + 142", async ({ page }) => {
await test.step("C402 Step 1", async () => {
console.log("C402 Step 1");
// await setTimeout(5000);
expect(10 + 10).toEqual(20);
test.describe("Existing test cases in suite", function() {
it("with no case id: 1111111111111", async ({ page }) => {
await test.step("Step 1", async () => {
// console.log("C256 Step 1");
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("C402 Step 2", async () => {
console.log("C402 Step 2");
// await setTimeout(5000);
expect(20 + 30).toEqual(50);
await test.step("Step 2", async () => {
// console.log("C256 Step 2");
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
// await setTimeout(5000);
// expect(142 + 142).toEqual(284);
});

it("@C403 Verify 144 + 144", async ({ page }) => {
// await setTimeout(5000);
it("with no case id: 222222222222", async ({ page }) => {
await test.step("Step 1", async () => {
// console.log("C256 Step 1");
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("Step 2", async () => {
// console.log("C256 Step 2");
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
});


it("with no case id: 3333333333", async ({ page }) => {
await test.step("Step 1", async () => {
// console.log("C256 Step 1");
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("Step 2", async () => {
// console.log("C256 Step 2");
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
});


it("@C4 444444444", async ({ page }) => {
await test.step("Step 1", async () => {
// console.log("C256 Step 1");
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("Step 2", async () => {
// console.log("C256 Step 2");
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
});


it("@C5 555555555", async ({ page }) => {
await test.step("Step 1", async () => {
// console.log("C256 Step 1");
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("Step 2", async () => {
// console.log("C256 Step 2");
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
});


it("@C6 666666666", async ({ page }) => {
await test.step("Step 1", async () => {
// console.log("C256 Step 1");
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("Step 2", async () => {
// console.log("C256 Step 2");
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
});


it("@C7 777777777", async ({ page }) => {
await test.step("Step 1", async () => {
// console.log("C256 Step 1");
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("Step 2", async () => {
// console.log("C256 Step 2");
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
});


it("@C8 888888888", async ({ page }) => {
await test.step("Step 1", async () => {
// console.log("C256 Step 1");
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("Step 2", async () => {
// console.log("C256 Step 2");
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
});


it("@C9 999999999", async ({ page }) => {
await test.step("Step 1", async () => {
// console.log("C256 Step 1");
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("Step 2", async () => {
// console.log("C256 Step 2");
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
});


it("@C10 000000000", async ({ page }) => {
await test.step("Step 1", async () => {
// console.log("C256 Step 1");
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("Step 2", async () => {
// console.log("C256 Step 2");
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
});


it("@C256 verify 1 + 1", async ({ page }) => {
await test.step("Step 1", async () => {
await setTimeout(dummyTimeout);
expect(1 + 1).toEqual(2);
});
await test.step("Step 2", async () => {
await setTimeout(dummyTimeout);
expect(2 + 3).toEqual(5);
});
});

it("@C277 Verify 2 + 2 [known issue]", async ({ page }) => {
await test.step("C403 Step 1", async () => {
console.log("Step 1");
expect(50 + 50).toEqual(100);
await setTimeout(dummyTimeout);
expect(50 + 50).toEqual(500);
});
});

it("@C278 Verify 3 + 3", async ({ page }) => {
await setTimeout(dummyTimeout);
expect(1 + 2).toEqual(3);
});

it("@C279 Verify 4 + 4", async ({ page }) => {
await setTimeout(dummyTimeout);
expect(1 + 2).toEqual(3);
});

it("@C280 Verify 5 + 5", async ({ page }) => {
await setTimeout(dummyTimeout);
expect(1 + 2).toEqual(3);
});

it("@C281 Verify 6 + 6", async ({ page }) => {
await setTimeout(dummyTimeout);
expect(1 + 2).toEqual(3);
});

it("@C282 Verify 7 + 7", async ({ page }) => {
await setTimeout(dummyTimeout);
expect(1 + 2).toEqual(3);
});

it("@C283 Verify 8 + 8", async ({ page }) => {
await setTimeout(dummyTimeout);
expect(1 + 2).toEqual(3);
});

it("@C284 Verify 9 + 9", async ({ page }) => {
await setTimeout(dummyTimeout);
expect(1 + 2).toEqual(3);
});

it("@C285 Verify 10 + 10", async ({ page }) => {
await setTimeout(dummyTimeout);
expect(1 + 2).toEqual(3);
});

it("@C286 Verify 11 + 11", async ({ page }) => {
await setTimeout(dummyTimeout);
expect(1 + 2).toEqual(3);
});

it("@C287 Verify 12 + 12", async ({ page }) => {
await setTimeout(dummyTimeout);
expect(1 + 2).toEqual(3);
});

});

test.describe("Non existing test cases in suite", function () {
test("@C1 has title", async ({ page }) => {
test.describe("Non existing test cases in suite", function() {
test("has title", async ({ page }) => {
await page.goto("https://playwright.dev/");
await expect(page).toHaveTitle(/Playwright/);
});

test("@C2 get started link", async ({ page }) => {
test("get started link", async ({ page }) => {
await page.goto("https://playwright.dev/");
await page.getByRole("link", { name: "Get started" }).click();
await expect(
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class PlaywrightTestRailReporter {
await this.caller.onBegin(config, suite);
}

async onTestBegin(test) {
await this.caller.onTestBegin(test);
}

async onTestEnd(test, result) {
await this.caller.onTestEnd(test, result);
}
Expand Down
32 changes: 23 additions & 9 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const TestRail = require("@dlenroc/testrail");
const path = require("path");
const schedule = require('node-schedule');
const getLogger = require('./logger.js');
const logger = getLogger('[playwright reporter(base)]');
const logger = getLogger();


const DEFAULT_CONFIG_FILENAME = 'testrail.config.js';
Expand All @@ -25,8 +25,10 @@ const case_ids = [];
const copiedTestResults = [];
const expectedFailures = {};


class BaseClass {
constructor() {
// TODO: fix naming
this.tesrailConfigs = {
base_url: base_url,
user: user,
Expand All @@ -49,6 +51,13 @@ class BaseClass {
this.rule = this.tesrailConfigs.testRailUpdateInterval <= 59
? `*/${this.tesrailConfigs.testRailUpdateInterval} * * * * *`
: `*/${Math.round(this.tesrailConfigs.testRailUpdateInterval / 60)} * * * *`;

// TODO: complete related functionality
// this variable is used to decide
// if we need to create a new run in TestRail
this.needToCreateRun = true;

this.runURL = '';
}

addRunToTestRail = async (case_ids) => {
Expand Down Expand Up @@ -79,21 +88,23 @@ class BaseClass {
name: `${this.tesrailConfigs.create_new_run.run_name}`
+ ` ${today.getDate()}-${monthAbbreviation}`
+ `-${today.getFullYear()}`
+ ` ${today.getHours()}:${today.getMinutes()}:${seconds}`,
+ ` ${today.toTimeString().split(' ')[0]}`,
description: "TestRail automatic reporter module",
include_all: this.tesrailConfigs.create_new_run.include_all,
case_ids: case_ids
});
};

async updateTestRailResults(testRailResults, runId, runUrl) {
logger.debug('TestRail results amount:\n', testRailResults.length)
async updateTestRailResults(testRailResults, runId) {
// logger.debug('Test rail results:\n', testRailResults)
if (testRailResults.length === 0) {
logger.warn('No new results to update in TestRail. Skipping...');
logger.warn(
'No new results or added test cases'
+ ' to update in TestRail. Skipping...'
);
return;
}
logger.info('Adding run results to TestRail');
logger.info(`Adding run results(${testRailResults.length}) to TestRail`);
// console.table(
// {
// testRailResults: testRailResults,
Expand Down Expand Up @@ -145,9 +156,6 @@ class BaseClass {
await this.tr_api.addResultsForCases(runId, res)
.then(() => {
logger.info('Test result added to TestRail successfully!');
if (runUrl) {
logger.info('New Run url:\n', runUrl, '\n')
}
})
.catch((error) => {
logger.error('Failed to add test result')
Expand Down Expand Up @@ -195,6 +203,12 @@ class BaseClass {
return "Test Passed within " + result.duration + " ms"
}
}

logRunURL() {
if (this.runURL != '') {
logger.info(`TestRail Run URL:\n${this.runURL}`);
}
}
}

module.exports = { BaseClass, testResults, case_ids, copiedTestResults };
29 changes: 24 additions & 5 deletions src/logger.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
const log4js = require('log4js');
const logLevel = process.env.LOG_LEVEL || 'info';

function getLogger(loggerName) {
const logger = log4js.getLogger(loggerName);
// Set default log level to info
logger.level = process.env.LOG_LEVEL || "info";
return logger;
log4js.configure({
appenders: {
out: {
type: 'stdout',
layout: {
type: 'pattern',
pattern: '%[%d{dd-MM-yy hh:mm:ss} | %p | %f{1}:%l%] - %m',
}
}
},
categories: {
default: {
appenders: ['out'],
useCallStack: true,
enableCallStack: true,
level: logLevel
}
}
});


function getLogger() {
return log4js.getLogger();
}

module.exports = getLogger;
Loading

0 comments on commit 2b047bc

Please sign in to comment.