Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.46.1",
"@types/crypto-js": "^4.2.2",
"@types/node": "^20.8.4"
},
"dependencies": {
"allure-playwright": "^2.15.1",
"cross-env": "^7.0.3",
"crypto-js": "^4.2.0",
"csv-parse": "^5.5.4",
"dotenv": "^16.4.5",
"exceljs": "^4.4.0",
Expand Down
8 changes: 6 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { defineConfig, devices } from '@playwright/test';
import dotenv from "dotenv"
import path from 'path';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// dotenv.config({
// path: process.env.TEST_ENV ? `./env-files/.env.${process.env.TEST_ENV}` : `./env-files/.env.dev`
// })
dotenv.config({
path: process.env.TEST_ENV ? `./env-files/.env.${process.env.TEST_ENV}` : `./env-files/.env.dev`
path: path.resolve('testdata','.env')//"./testdata/.env"
})
/**
* See https://playwright.dev/docs/test-configuration.
Expand Down Expand Up @@ -51,7 +55,7 @@ export default defineConfig({
// Authorization: "Basic YWRtaW46cGFzc3dvcmQxMjM="
},
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
headless: true,
headless: false,
screenshot:'only-on-failure',
video:'retain-on-failure',
trace:'on',
Expand Down
2 changes: 2 additions & 0 deletions testdata/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
encryptedUame = "U2FsdGVkX19Eyw+2pLAvZSyaHnbfcPuIc82HntmtAJ0="
encryptedPwd = "U2FsdGVkX1+0z6XjTSDkCt7Mi6OeJhy1Z+EuHVskfNY="
4 changes: 4 additions & 0 deletions testdata/securedata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encryptedUame":"U2FsdGVkX19Eyw+2pLAvZSyaHnbfcPuIc82HntmtAJ0=",
"encryptedPwd": "U2FsdGVkX1+0z6XjTSDkCt7Mi6OeJhy1Z+EuHVskfNY="
}
44 changes: 44 additions & 0 deletions tests/EncryptionDecryptionWithPlaywright.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {test} from "@playwright/test";
// import CryptoJS from "crypto-js";
import {encryptData, decryptData} from "../util/encrypt-decrypt-util"
import securedata from "../testdata/securedata.json"

test("Encrypt Decrypt Sensitive Data in Playwright",async({page})=>{
await page.goto('https://www.saucedemo.com/');
// const encryptedUserName = CryptoJS.AES.encrypt('standard_user', 'wishinfinite').toString()
// const encryptedUserName = encryptData('standard_user');
// console.log("Encrypted Username - ", encryptedUserName);
// console.log("Encrypted Password - ", CryptoJS.AES.encrypt("secret_sauce", "wishinfinite").toString())
const encryptedUame = "U2FsdGVkX19Eyw+2pLAvZSyaHnbfcPuIc82HntmtAJ0=";
const encryptedPwd = "U2FsdGVkX1+0z6XjTSDkCt7Mi6OeJhy1Z+EuHVskfNY=";

// const SecretKey = process.env.SECRET_KEY ? process.env.SECRET_KEY : "";
// const decryptedUname = CryptoJS.AES.decrypt(encryptedUame, SecretKey).toString(CryptoJS.enc.Utf8);
// const decryptPwd = CryptoJS.AES.decrypt(encryptedPwd, SecretKey).toString(CryptoJS.enc.Utf8);
const decryptedUname = decryptData(encryptedUame);
const decryptPwd = decryptData(encryptedPwd);
console.log(decryptedUname + " - " + decryptPwd);
await page.locator('[data-test="username"]').fill(decryptedUname);
await page.locator('[data-test="password"]').fill(decryptPwd);
await page.locator('[data-test="login-button"]').click();
})

test("Encrypt Decrypt 2", async({page})=>{
const encUname : any = process.env.encryptedUame;
const decryptedUname = decryptData(encUname);
const encPwd :any = process.env.encryptedPwd;
const decryptPwd = decryptData(encPwd);
await page.goto('https://www.saucedemo.com/');
await page.locator('[data-test="username"]').fill(decryptedUname);
await page.locator('[data-test="password"]').fill(decryptPwd);
await page.locator('[data-test="login-button"]').click();
})

test("Encrypt Decrypt 3", async({page})=>{
const decryptedUname = decryptData(securedata.encryptedUame);
const decryptPwd = decryptData(securedata.encryptedPwd);
await page.goto('https://www.saucedemo.com/');
await page.locator('[data-test="username"]').fill(decryptedUname);
await page.locator('[data-test="password"]').fill(decryptPwd);
await page.locator('[data-test="login-button"]').click();
})
12 changes: 0 additions & 12 deletions tests/temp.spec.ts

This file was deleted.

12 changes: 12 additions & 0 deletions util/encrypt-decrypt-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import CryptoJS from "crypto-js";


const secreKey = process.env.SECRET_KEY ? process.env.SECRET_KEY : '';

export function encryptData(data: string){
return CryptoJS.AES.encrypt(data, secreKey).toString();
}

export function decryptData(encData: string){
return CryptoJS.AES.decrypt(encData, secreKey).toString(CryptoJS.enc.Utf8);
}
Loading