froth-webdriverio-framework 0.1.31 → 0.1.33

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,56 +1,55 @@
1
1
  const login = require('./loginapi.js');
2
2
 
3
3
  // Function to get data from the API using the Bearer token
4
- async function getDataById(frothUrl,id) {
4
+ async function getDataById(frothUrl, id) {
5
5
 
6
- const url = `https://${frothUrl}/api/testdata-retrieve/${id}`;
6
+ if (id != 0) {
7
+ const url = `https://${frothUrl}/api/testdata-retrieve/${id}`;
7
8
 
8
- try {
9
- const token = await login('subhra.subudhi@roboticodigital.com',Buffer.from('V2VsY29tZUAxMjM=','base64').toString('utf-8')); // Wait for the login function to resolve and get the token
10
- if (!token) {
11
- throw new Error('Login failed, no token obtained');
12
- }
13
- console.log('Fetching data with token:', token);
14
-
15
- const response = await fetch(url, {
16
- method: 'GET',
17
- headers: {
18
- 'Authorization': `Bearer ${token}`,
9
+ try {
10
+ const token = await login('subhra.subudhi@roboticodigital.com', Buffer.from('V2VsY29tZUAxMjM=', 'base64').toString('utf-8')); // Wait for the login function to resolve and get the token
11
+ if (!token) {
12
+ throw new Error('Login failed, no token obtained');
19
13
  }
20
- });
21
-
22
- if (!response.ok) {
23
- const errorText = await response.text();
24
- console.error('Data fetch failed response:', errorText);
25
- throw new Error(`HTTP error! status: ${response.status}`);
14
+ const response = await fetch(url, {
15
+ method: 'GET',
16
+ headers: {
17
+ 'Authorization': `Bearer ${token}`,
18
+ }
19
+ });
20
+
21
+ if (!response.ok) {
22
+ const errorText = await response.text();
23
+ console.error('Data fetch failed response:', errorText);
24
+ throw new Error(`HTTP error! status: ${response.status}`);
25
+ }
26
+ const data = await response.json();
27
+ // Convert the key-value data to a JSON string
28
+ const jsonData = data.key_value_data;
29
+ // Convert the array into an object with keys as property names
30
+ const buffer = jsonData.reduce((obj, item) => {
31
+ obj[item.key] = item.value;
32
+ return obj;
33
+ }, {});
34
+ // Set the buffer as an environment variable
35
+ const stringData = JSON.stringify(buffer);
36
+ process.env.BUFFER = stringData;
37
+ console.log('Buffer data:', process.env.BUFFER);
38
+ // const data1 = JSON.parse(process.env.BUFFER);
39
+ // console.log("Data1:", data1.sdfasd);
40
+ return stringData;
41
+
42
+
43
+ } catch (error) {
44
+ console.error('Error fetching data:', error);
26
45
  }
27
-
28
- const data = await response.json();
29
- console.log('Data:', data);
30
- // Convert the key-value data to a JSON string
31
- const jsonData = JSON.stringify(data.key_value_data);
32
-
33
- // Log the JSON data to the console
34
- console.log("JSON Data:", jsonData);
35
-
36
-
37
- // const matchingData = data.key_value_data.find(item => item.key === keyvalue);
38
- // if (matchingData) {
39
- // console.log('value:', matchingData.value);
40
- // } else {
41
- // console.log('value:', "");
42
- // }
43
-
44
-
45
- return jsonData;
46
- } catch (error) {
47
- console.error('Error fetching data:', error);
46
+ } else {
47
+ console.error('Error fetching data: Invalid ID');
48
48
  }
49
- }
50
-
51
49
 
50
+ }
52
51
  module.exports = getDataById;
53
52
 
54
53
  // Execute the main function
55
54
 
56
- //console.log("Retrieved JSON Data from local storage:", getDataById("devapi.frothtestops.com",78, "asdfa"));
55
+ //console.log("Retrieved JSON Data from local storage:", getDataById("devapi.frothtestops.com", 78, "asdfa"));
@@ -1,76 +1,79 @@
1
1
  // Description: This file contains the common configuration for the webdriverio framework.
2
+ const readTestData = require('../api/readTestdata.js');
2
3
  const commonconfig = {
3
- /**
4
- * Gets executed before the suite starts (in Mocha/Jasmine only).
5
- * @param {object} suite suite details
6
- */
7
- beforeSuite: function (suite) {
8
- console.log("Running suite:", suite.title);
9
- },
10
-
11
- /**
12
- * Function to be executed before a test (in Mocha/Jasmine only)
13
- * @param {object} test test object
14
- * @param {object} context scope object the test was executed with
4
+ /**
5
+ * Gets executed before the suite starts (in Mocha/Jasmine only).
6
+ * @param {object} suite suite details
15
7
  */
16
- beforeTest: function (test, context) {
17
- console.log("Test Name:", test.title);
18
- console.log("Context Details:", context.title);
19
- console.log("File Name:", test.file);
20
-
21
- },
22
-
23
- afterStep: function (test, context, { error, result, duration, passed, retries }) {
24
- // if (passed) {
25
- // browser.takeScreenshot();
26
- // }
27
- },
28
- // afterTest: async function (test, context, { error, result, duration, passed, retries }) {
29
- // if (passed) { await browser.takeScreenshot() }
30
- // },
31
- /**
32
- * Function to be executed after a test (in Mocha/Jasmine only)
33
- * @param {object} test test object
34
- * @param {object} context scope object the test was executed with
35
- * @param {Error} result.error error object in case the test fails, otherwise `undefined`
36
- * @param {*} result.result return object of test function
37
- * @param {number} result.duration duration of test
38
- * @param {boolean} result.passed true if test has passed, otherwise false
39
- * @param {object} result.retries information about spec related retries, e.g. `{ attempts: 0, limit: 0 }`
40
- */
41
- afterTest: function (test, context, { error, result, duration, passed, retries }) {
42
- console.log(`Test '${test.title}' finished.`);
43
- console.log(`Duration: ${duration}ms`);
44
- console.log(`Passed: ${passed}`);
45
- if (error) {
46
- console.error(`Error: ${error.message}`);
47
- }
48
- console.log('---------------------------------------');
49
- },
50
- /**
51
- * Hook that gets executed after the suite has ended (in Mocha/Jasmine only).
52
- * @param {object} suite suite details
53
- */
54
- afterSuite: function (suite) {
55
- console.log(`Test suite '${suite.title}' has ended.`);
56
- },
57
- /**
58
- * Gets executed after all tests are done. You still have access to all global variables from
59
- * the test.
60
- * @param {number} result 0 - test pass, 1 - test fail
61
- * @param {Array.<Object>} capabilities list of capabilities details
62
- * @param {Array.<String>} specs List of spec file paths that ran
63
- */
64
- after: function (result, capabilities, specs) {
65
- console.log('All tests are done.');
66
- console.log(`Result: ${result === 0 ? 'Pass' : 'Fail'}`);
67
- console.log('Capabilities:');
68
- console.log(capabilities);
69
- console.log('Specs:');
70
- console.log(specs);
71
- },
72
-
73
- };
74
-
75
- module.exports = commonconfig;
76
-
8
+ beforeSuite: function (suite) {
9
+ console.log("Running suite:", suite.title);
10
+ console.log("Reading test data from the API");
11
+ readTestData(process.env.organisation_url, process.env.testdata_id);
12
+
13
+ },
14
+
15
+ /**
16
+ * Function to be executed before a test (in Mocha/Jasmine only)
17
+ * @param {object} test test object
18
+ * @param {object} context scope object the test was executed with
19
+ */
20
+ beforeTest: function (test, context) {
21
+ console.log("Test Name:", test.title);
22
+ console.log("Context Details:", context.title);
23
+ console.log("File Name:", test.file);
24
+
25
+ },
26
+
27
+ afterStep: function (test, context, { error, result, duration, passed, retries }) {
28
+ // if (passed) {
29
+ // browser.takeScreenshot();
30
+ // }
31
+ },
32
+ // afterTest: async function (test, context, { error, result, duration, passed, retries }) {
33
+ // if (passed) { await browser.takeScreenshot() }
34
+ // },
35
+ /**
36
+ * Function to be executed after a test (in Mocha/Jasmine only)
37
+ * @param {object} test test object
38
+ * @param {object} context scope object the test was executed with
39
+ * @param {Error} result.error error object in case the test fails, otherwise `undefined`
40
+ * @param {*} result.result return object of test function
41
+ * @param {number} result.duration duration of test
42
+ * @param {boolean} result.passed true if test has passed, otherwise false
43
+ * @param {object} result.retries information about spec related retries, e.g. `{ attempts: 0, limit: 0 }`
44
+ */
45
+ afterTest: function (test, context, { error, result, duration, passed, retries }) {
46
+ console.log(`Test '${test.title}' finished.`);
47
+ console.log(`Duration: ${duration}ms`);
48
+ console.log(`Passed: ${passed}`);
49
+ if (error) {
50
+ console.error(`Error: ${error.message}`);
51
+ }
52
+ console.log('---------------------------------------');
53
+ },
54
+ /**
55
+ * Hook that gets executed after the suite has ended (in Mocha/Jasmine only).
56
+ * @param {object} suite suite details
57
+ */
58
+ afterSuite: function (suite) {
59
+ console.log(`Test suite '${suite.title}' has ended.`);
60
+ },
61
+ /**
62
+ * Gets executed after all tests are done. You still have access to all global variables from
63
+ * the test.
64
+ * @param {number} result 0 - test pass, 1 - test fail
65
+ * @param {Array.<Object>} capabilities list of capabilities details
66
+ * @param {Array.<String>} specs List of spec file paths that ran
67
+ */
68
+ after: function (result, capabilities, specs) {
69
+ console.log('All tests are done.');
70
+ console.log(`Result: ${result === 0 ? 'Pass' : 'Fail'}`);
71
+ console.log('Capabilities:');
72
+ console.log(capabilities);
73
+ console.log('Specs:');
74
+ console.log(specs);
75
+ },
76
+
77
+ };
78
+
79
+ module.exports = commonconfig;
@@ -0,0 +1,13 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function setEnvVariablesFromJson() {
5
+ const jsonFilePath = path.resolve(__dirname, 'data.json');
6
+ const jsonData = JSON.parse(fs.readFileSync(jsonFilePath, 'utf-8'));
7
+
8
+ Object.keys(jsonData).forEach(key => {
9
+ process.env[key.toUpperCase()] = jsonData[key];
10
+ });
11
+ }
12
+
13
+ setEnvVariablesFromJson();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "readme": "WendriverIO Integration with [BrowserStack]",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",