froth-webdriverio-framework 0.1.30 → 0.1.32

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,54 +1,50 @@
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, keyvalue) {
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');
13
+ }
14
+ console.log('Fetching data with token:', token);
15
+
16
+ const response = await fetch(url, {
17
+ method: 'GET',
18
+ headers: {
19
+ 'Authorization': `Bearer ${token}`,
20
+ }
21
+ });
22
+
23
+ if (!response.ok) {
24
+ const errorText = await response.text();
25
+ console.error('Data fetch failed response:', errorText);
26
+ throw new Error(`HTTP error! status: ${response.status}`);
19
27
  }
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}`);
26
- }
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
28
 
29
+ const data = await response.json();
30
+ console.log('Data:', data);
31
+ // Convert the key-value data to a JSON string
32
+ const jsonData = JSON.stringify(data.key_value_data);
36
33
 
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
- // }
34
+ // Log the JSON data to the console
35
+ console.log("JSON Data:", jsonData);
43
36
 
37
+ process.env.BUFFER = JSON.stringify(jsonData);
44
38
 
45
- return jsonData;
46
- } catch (error) {
47
- console.error('Error fetching data:', error);
39
+ return jsonData;
40
+ } catch (error) {
41
+ console.error('Error fetching data:', error);
42
+ }
43
+ }else{
44
+ console.error('Error fetching data: Invalid ID');
48
45
  }
49
- }
50
-
51
46
 
47
+ }
52
48
  module.exports = getDataById;
53
49
 
54
50
  // Execute the main function
@@ -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.30",
3
+ "version": "0.1.32",
4
4
  "readme": "WendriverIO Integration with [BrowserStack]",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",