froth-webdriverio-framework 7.0.27 → 7.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,75 +1,82 @@
1
+ const aes = require('./aesEncryptionDecryption');
2
+
3
+ // Function to get suite details using Bearer token
4
+ async function getSuiteDetails(frothUrl, token, suiteId) {
5
+ // Default response structure
6
+ let jsonData = {
7
+ automation_suite_id: 0,
8
+ automation_suite_name: "",
9
+ test_data_id: 0,
10
+ script_details: [],
11
+ test_sequence: null
12
+ };
13
+
14
+ // Validate suite ID
15
+ if (!suiteId || suiteId === 0) {
16
+ console.error('Invalid suite ID or no suite linked to execution');
17
+ return jsonData;
18
+ }
1
19
 
2
- //const getLoginToken = require('./loginapi')
3
- // Function to get data from the API using the Bearer token
4
- async function getSuiteDetails(frothUrl, token, id) {
5
- let jsondata = {};
6
- if (id != 0 || id != null || id != undefined) {
7
- const url = `${frothUrl}/api/automationsuite-retrieve/${id}/`;
8
-
9
- try {
10
- console.log("URL: " + url)
11
- const response = await fetch(url, {
12
- method: 'GET',
13
- headers: {
14
- 'Authorization': `Bearer ${token}`,
15
- 'Content-Type': 'application/json'
16
-
17
- }
18
- });
19
- if (response.ok) {
20
- const data = await response.json();
21
- // console.log(data)
22
- jsondata.automation_suite_id = data.id == null ? 0 : data.id;
23
- jsondata.automation_suite_name = data.automation_suite_name == null ? "" : data.automation_suite_name;
24
- jsondata.test_data_id = data.test_data_id == null ? 0 : data.test_data_id;
25
- jsondata.script_details = data.script_details == null ? [] : data.script_details;
26
- jsondata.test_sequence = data.test_sequence;
27
-
28
- console.log("json data :" + JSON.stringify(jsondata));
29
-
30
-
20
+ const url = `${frothUrl}/api/automationsuite-retrieve/${suiteId}/`;
21
+ console.log("Fetching Suite Details URL:", url);
31
22
 
32
- } else if (response.status === 401) { // Unauthorized, token expired
33
-
34
- console.log("Unauthorized, token expired" + response.status)
35
- }
36
- else {
37
- const errorText = await response.text();
38
- console.error(`Data fetch failed response in getSuiteDetails: ${response.status}`);
23
+ try {
24
+ const response = await fetch(url, {
25
+ method: 'GET',
26
+ headers: {
27
+ Authorization: `Bearer ${token}`,
28
+ 'Content-Type': 'application/json'
39
29
  }
30
+ });
40
31
 
32
+ let resData = await handleResponse(response, 'getSuiteDetails');
33
+ if (!resData || !resData.data) return jsonData;
41
34
 
35
+ // Decrypt the data
36
+ let decryptedData = await aes.decrpytData(resData.data);
37
+ if (!decryptedData) return jsonData;
42
38
 
43
- } catch (error) {
44
- console.error('Error fetching data:', error);
45
-
39
+ // Parse JSON
40
+ let data;
41
+ try {
42
+ data = JSON.parse(decryptedData);
43
+ } catch (parseError) {
44
+ console.error('Failed to parse decrypted data:', parseError);
45
+ return jsonData;
46
46
  }
47
47
 
48
- } else {
49
- console.error('Error fetching data: Invalid ID or no suite id is linked to execution');
48
+ // Map data to default structure
49
+ jsonData = {
50
+ automation_suite_id: data.id ?? 0,
51
+ automation_suite_name: data.automation_suite_name ?? "",
52
+ test_data_id: data.test_data_id ?? 0,
53
+ script_details: data.script_details ?? [],
54
+ test_sequence: data.test_sequence ?? null
55
+ };
56
+
57
+ console.log("Suite JSON Data:", JSON.stringify(jsonData));
58
+
59
+ } catch (error) {
60
+ console.error('Error while fetching suite details:', error);
50
61
  }
51
- return jsondata;
62
+
63
+ return jsonData;
52
64
  }
53
65
 
54
- // async function main() {
55
- // try {
56
- // const frothUrl = "devapi.frothtestops.com";
57
- // const username = "subhra.subudhi@roboticodigital.com";
58
- // const password = "V2VsY29tZUAxMjM=";
66
+ // Helper function to handle API responses
67
+ async function handleResponse(response, context) {
68
+ if (response.ok) {
69
+ return response.json();
70
+ }
59
71
 
60
- // const token = await getLoginToken(frothUrl, username, password);
61
- // if (!token) {
62
- // throw new Error('Login failed, no token obtained');
63
- // }
72
+ if (response.status === 401) {
73
+ console.error(`🔒 Unauthorized (401) in ${context}`);
74
+ return null;
75
+ }
64
76
 
65
- // const id = 147;
66
- // const data = await getSuiteDetails(frothUrl, token, id);
67
- // console.log("Retrieved JSON Data:", data);
68
- // console.log(data.automation_script_id[0].automation_script_id)
69
- // } catch (error) {
70
- // console.error('Error in main function:', error);
71
- // }
72
- // }
77
+ const errorText = await response.text();
78
+ console.error(`❌ ${context} failed [${response.status}]: ${errorText}`);
79
+ return null;
80
+ }
73
81
 
74
- // main();
75
82
  module.exports = getSuiteDetails;
@@ -104,7 +104,10 @@ const commonHooks = {
104
104
  await setAllDetails.setSuiteDetails();
105
105
  await setAllDetails.setTestDataDetails();
106
106
 
107
- console.log('✅ All Env Varibale set');
107
+ console.log('✅ All Environment Variables:');
108
+ for (const [key, value] of Object.entries(process.env)) {
109
+ console.log(`${key} = ${value}`);
110
+ }
108
111
  },
109
112
 
110
113
  /* ========== BEFORE SESSION ========== */
@@ -153,9 +156,8 @@ const commonHooks = {
153
156
  try {
154
157
  const media = JSON.parse(process.env.MEDIA_FILES);
155
158
  console.log('Total items:', media.length);
156
- if (media.length > 0)
157
- {
158
- bsOpts.uploadMedia=JSON.parse(process.env.MEDIA_FILES)
159
+ if (media.length > 0) {
160
+ bsOpts.uploadMedia = JSON.parse(process.env.MEDIA_FILES)
159
161
  bsOpts['browserstack.uploadMedia'] = JSON.parse(process.env.MEDIA_FILES);
160
162
  }
161
163
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "7.0.27",
3
+ "version": "7.0.29",
4
4
  "readme": "WebdriverIO Integration",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",