froth-webdriverio-framework 0.1.28 → 0.1.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.
@@ -0,0 +1,36 @@
1
+ //const fetch = require('node-fetch'); // Import the fetch function
2
+ //const FormData = require('form-data'); // Import the FormData constructor
3
+
4
+
5
+ async function login(email,password) {
6
+ const url = 'https://devapi.frothtestops.com/api/login/';
7
+ const formData = new FormData();
8
+ formData.append('email', email);
9
+ formData.append('password', password);
10
+
11
+ const response = await fetch(url, {
12
+ method: 'POST',
13
+ headers: {
14
+ 'accept': 'application/json',
15
+ // 'X-CSRFToken': 'hSb92VZT0AFMKaekBUSdlZjfHMIzhzvOyk6e5i8ZrVv6B15EtN8WLps3oyV2MOY1'
16
+ },
17
+ body: formData
18
+ });
19
+
20
+ if (response.ok) {
21
+ const data = await response.json();
22
+ console.log('Login successful:', data);
23
+ console.log('Token:', data.access_token);
24
+ return data.access_token;
25
+ } else {
26
+ console.error('Login failed:', response.statusText);
27
+ return null;
28
+ }
29
+
30
+ }
31
+
32
+ module.exports = login;
33
+
34
+
35
+
36
+
@@ -0,0 +1,56 @@
1
+ const login = require('./loginapi.js');
2
+
3
+ // Function to get data from the API using the Bearer token
4
+ async function getDataById(frothUrl,id, keyvalue) {
5
+
6
+ const url = `https://${frothUrl}/api/testdata-retrieve/${id}`;
7
+
8
+ try {
9
+ const token = await login('subhra.subudhi@roboticodigital.com','Welcome@123'); // 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}`,
19
+ }
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
+
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);
48
+ }
49
+ }
50
+
51
+
52
+ module.exports = getDataById;
53
+
54
+ // Execute the main function
55
+
56
+ //console.log("Retrieved JSON Data from local storage:", getDataById("devapi.frothtestops.com",78, "asdfa"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "readme": "WendriverIO Integration with [BrowserStack]",
5
5
  "description": "WebdriverIO and BrowserStack App Automate",
6
6
  "license": "MIT",
@@ -35,6 +35,8 @@
35
35
  "appium-uiautomator2-driver": "^3.2.0",
36
36
  "browserstack-local": "^1.5.5",
37
37
  "deepmerge": "^4.3.1",
38
+ "form-data": "^4.0.0",
39
+ "node-fetch": "^3.3.2",
38
40
  "ts-node": "^10.9.2",
39
41
  "typescript": "^5.4.5"
40
42
  }