-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcypress.config.js
106 lines (103 loc) · 3.07 KB
/
cypress.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// declare var require: any
const { defineConfig } = require('cypress')
//Verify download import
const { isFileExist, findFiles } = require("cy-verify-downloads");
//Excel requirements
const xlsx = require("node-xlsx").default;
const fs = require("fs"); // for file
const path = require("path"); // for file path
//mySQL requirements
const mysql = require("mysql");
//Faker
const { faker } = require("@faker-js/faker");
module.exports = defineConfig({
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
baseUrl: "http://uitestingplayground.com",
setupNodeEvents(on, config) {
//Verify download import
on("task", { isFileExist, findFiles });
//--------------------
//Excel implementation
on("task", {
parseXlsx({ filePath }) {
return new Promise((resolve, reject) => {
try {
const jsonData = xlsx.parse(fs.readFileSync(filePath));
resolve(jsonData);
} catch (e) {
reject(e);
}
});
},
});
//------------------
//mySQL Implementation & Faker
on("task", {
queryDb: (query) => {
return queryTestDb(query, config);
},
});
//--------------------
//---------------------
//Faker
on("task", {
freshUser() {
let user = {
username: faker.name.firstName(),
email: faker.internet.email(),
password: faker.internet.password(),
registeredAt: faker.date.past(),
vehicle: faker.vehicle.vehicle(),
};
return user;
},
});
//--------
},
},
env: {
demoVar: "Hello from the Cypress.Config.Ts",
demoQA: "https://demoqa.com",
theInternet: "https://the-internet.herokuapp.com",
saucedemo: "https://www.saucedemo.com/",
palindromUrl: "https://bartekkustra.github.io/luczniczqa/task-1/",
google: "https://www.google.com",
solidJobs: "https://solid.jobs/offers/it",
//https://www.globalsqa.com/angularjs-protractor-practice-site/
Angular: "https://www.globalsqa.com",
db: {
host: "root",
user: "twozniak",
password: "",
database: "cypressTest",
},
chromeWebSecurity: false,
"reporter": "junit",
"reporterOptions": {
"mochaFile": "results/test-results.xml",
"testCaseSwitchClassnameAndName": false
},
}
})
function queryTestDb(query, config) {
// creates a new mysql connection using credentials from cypress.json env's
const connection = mysql.createConnection(config.env.db);
// start connection to db
connection.connect();
// exec query + disconnect to db as a Promise
return new Promise((resolve, reject) => {
connection.query(query, (error, results) => {
if (error) reject(error);
else {
connection.end();
// console.log(results)
return resolve(results);
}
});
});
}