-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypress.config.js
148 lines (131 loc) · 4.14 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const { defineConfig } = require('cypress')
const fs = require('fs-extra');
const mysql = require('mysql')
const FactorySeleniumEasy = require('./cypress/fixtures/SeleniumEasyFactory');
let githubActionsKeys = {}
module.exports = defineConfig({
e2e: {
watchForFileChanges: false,
specPattern: ["cypress/e2e/**/*.cy.{js,jsx,ts,tsx}"],
pageLoadTimeout: 90000,
responseTimeout: 45000,
defaultCommandTimeout: 10000,
video: false,
chromeWebSecurity: false,
experimentalSessionAndOrigin: true,
screenshotsFolder: "cypress/results/screenshots",
videosFolder: "cypress/results/videos",
downloadsFolder: "cypress/results/downloads",
supportFile: 'cypress/support/e2e.js',
reporter: "cypress-multi-reporters",
reporterOptions: {
"configFile": "cypress/config/reporter-configs.json"
},
env: {
"TAGS": "not @skip",
"SeleniumEasy": "https://demo.seleniumeasy.com/",
"HeroApp": "https://the-internet.herokuapp.com/",
"expandCollapseTime": 1500,
"jiraProjectKey": "QE",
"metaDataPath" : "cypress/results/reports/metadata/cypress-utils.json",
"DB_CONFIG": {
"wordpress-db": {
"db_name": "wordpress-db",
"base_url": {
"local": "localhost",
"dev": "http://cool-site-db:dev",
"test": "http://cool-site-db:test"
},
"port": {
"local": 3306,
"dev": 3306,
"test": 3306
}
}
},
"username": "[SHOULD BE OVERWRITTEN]",
"password": "[SHOULD BE OVERWRITTEN]",
"ACTION_TEST": "[SHOULD BE OVERWRITTEN]",
},
setupNodeEvents,
}
})
async function setupNodeEvents(on, config) {
//When running in GitHubActions config.env.TEST_TRIGGER will be 'workflow_dispatch' refer to (.github/workflows/qe.yml)
const testTrigger = config.env.TEST_TRIGGER || 'default'
const envKey = config.env.envKey || 'local';
config.env['envKey'] = envKey
if (envKey !== 'local') {
config = getConfigByFile(envKey, config);
}
require('cypress-grep/src/plugin')(config);
cleanReports();
readGitHubSecrets(config);
fixturesFactory(config);
on('task', {
logMsg(msg) {
console.log(msg);
return null;
},
getGithubKeys: () => {
return githubActionsKeys;
},
readJsonMaybe(jsonPath) {
if (fs.existsSync(jsonPath)) {
return fs.readJson(jsonPath);
}
return {}
},
dbExec({dbName, sql}) {
return dbQuery(dbName, sql, config)
}
});
return config;
}
function cleanReports() {
const reportPath = './cypress/results/reports';
if (fs.existsSync(reportPath)) {
fs.rmdirSync('./cypress/results/reports', { recursive: true });
}
};
function getConfigByFile(envKey, config) {
let fileName = `cypress_${envKey}.json`
console.log("Config file: " + fileName);
let rawData = fs.readFileSync(`cypress/config/${fileName}`);
let newConfig = JSON.parse(rawData);
config = {...config, ...newConfig}
return config;
};
function readGitHubSecrets(config) {
githubActionsKeys["process_env_CYPRESS_ACTION_TEST"] = process.env.CYPRESS_ACTION_TEST
githubActionsKeys["config_ACTION_TEST"] = config.env.ACTION_TEST
}
function fixturesFactory(config) {
const cypressEnv = {...config.env}
FactorySeleniumEasy.fixtureFactory(cypressEnv)
}
// sql, dbName, config
function dbQuery(dbName, query, config) {
const envKey = config.env.envKey
// Config options in https://github.com/mysqljs/mysql
const dbConfig = {
"host": config.env.DB_CONFIG[dbName].base_url[envKey],
"port": config.env.DB_CONFIG[dbName].port[envKey],
"user": config.env.DB_USER,
"password": config.env.DB_PASSWORD,
"database": dbName
}
const dbConnection = mysql.createConnection(dbConfig)
dbConnection.connect()
// exec query + disconnect to db as a Promise
return new Promise((resolve, reject) => {
dbConnection.query(query, (error, dbResults) => {
if (error) reject(error)
else {
dbConnection.end()
// console.log(dbResults)
return resolve(dbResults)
}
})
})
}