froth-webdriverio-framework 1.0.0 → 1.0.2

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.
Files changed (37) hide show
  1. package/api/browsersatckSessionInfo.js +73 -0
  2. package/api/getexecutionDetails.js +130 -0
  3. package/api/getsuiteDetails.js +74 -0
  4. package/api/index.js +18 -0
  5. package/api/loginapi.js +55 -0
  6. package/api/readTestdata.js +61 -0
  7. package/config/android.conf.js +45 -0
  8. package/config/common.mobile.conf.js +48 -0
  9. package/config/commonconfig.js +185 -0
  10. package/config/ios.conf.js +32 -0
  11. package/config/setenvvariable.js +13 -0
  12. package/config/web.conf.bs.js +95 -0
  13. package/config/web.conf.js +70 -0
  14. package/local.log +8 -0
  15. package/mobile/commonMethods/Utils.js +44 -0
  16. package/mobile/commonMethods/clickIfVisible.js +23 -0
  17. package/mobile/commonMethods/getdata.js +38 -0
  18. package/mobile/commonMethods/scrollDownToView.js +12 -0
  19. package/mobile/commonMethods/scrollRightToView.js +12 -0
  20. package/mobile/commonMethods/scrollToBeginning.js +12 -0
  21. package/mobile/commonMethods/scrollToEnd.js +12 -0
  22. package/mobile/commonMethods/scrollToLeft.js +12 -0
  23. package/mobile/commonMethods/scrollToRight.js +12 -0
  24. package/mobile/commonMethods/test.js +19 -0
  25. package/mobile/commonMethods/verifyText.js +28 -0
  26. package/mobile/commonMethods/verifyTextInFieldAttribute.js +17 -0
  27. package/package.json +3 -10
  28. package/.env +0 -4
  29. package/dist/api.bundle.js +0 -3
  30. package/dist/api.bundle.js.LICENSE.txt +0 -252
  31. package/dist/api.bundle.js.map +0 -1
  32. package/dist/config.bundle.js +0 -3
  33. package/dist/config.bundle.js.LICENSE.txt +0 -13
  34. package/dist/config.bundle.js.map +0 -1
  35. package/dist/mobile.bundle.js +0 -3
  36. package/dist/mobile.bundle.js.LICENSE.txt +0 -1
  37. package/dist/mobile.bundle.js.map +0 -1
@@ -0,0 +1,185 @@
1
+ const getDataById = require("../api/readTestdata");
2
+ const exeDetails = require("../api/getexecutionDetails")
3
+ const getLoginToken = require("../api/loginapi");
4
+ const getSuiteDetails = require("../api/getsuiteDetails");
5
+ const { LocalStorage } = require('node-localstorage');
6
+ global.BUFFER = new LocalStorage('./storage');
7
+ const getBSSessionDetails = require("../api/browsersatckSessionInfo")
8
+ // Description: This file contains the common configuration for the webdriverio framework.
9
+ const commonconfig = {
10
+
11
+
12
+ onPrepare: async function (capabilities, specs) {
13
+ BUFFER.setItem("TOTAL_DURATION", 0);
14
+ // This code runs before the test suite starts
15
+ // console.log("organisation url" + process.env.organisation_url);
16
+ // console.log("test data id" + process.env.testdata_id);
17
+ BUFFER.setItem("EXECUTION_ID", process.env.EXECUTION_ID);
18
+ BUFFER.setItem("organisation_url", process.env.organisation_url);
19
+ BUFFER.setItem("SERVICE_USER", "subhra.subudhi@roboticodigital.com");
20
+ BUFFER.setItem("SERVICE_PASSWORD", "V2VsY29tZUAxMjM=");
21
+ BUFFER.setItem("BROWSERSTACK_USERNAME", process.env.BROWSERSTACK_USERNAME);
22
+ BUFFER.setItem("BROWSERSTACK_ACCESS_KEY", process.env.BROWSERSTACK_ACCESS_KEY);
23
+
24
+ const getToken = await getLoginToken(BUFFER.getItem("organisation_url"), BUFFER.getItem("SERVICE_USER"), BUFFER.getItem("SERVICE_PASSWORD"));
25
+ process.env.LOGIN_TOKEN = getToken;
26
+ BUFFER.setItem("LOGIN_TOKEN", getToken)
27
+
28
+ const getExeDetails = await exeDetails.getExecuitonDetails(BUFFER.getItem("organisation_url"), getToken, BUFFER.getItem("EXECUTION_ID"));
29
+ if (getExeDetails.automation_suite_id != null) {
30
+ const getSuiteDetail = await getSuiteDetails(BUFFER.getItem("organisation_url"), getToken, getExeDetails.automation_suite_id);
31
+ if (getSuiteDetail.test_data_id != null) {
32
+ const jsonobject = await getDataById(BUFFER.getItem("organisation_url"), getToken, getSuiteDetail.test_data_id);
33
+ if (jsonobject == null) {
34
+ console.log("Test data is not available");
35
+ }
36
+ else {
37
+ BUFFER.setItem("BUFFER", JSON.stringify(jsonobject))
38
+
39
+ }
40
+ }
41
+ }
42
+ },
43
+
44
+ before: function (capabilities, specs) {
45
+ // Code to run before the test suite starts
46
+ console.log('Starting test suite IN EBFORE HOOK ...');
47
+ // Initialize variables, configure environment, etc.
48
+ },
49
+
50
+
51
+ /**
52
+ * Gets executed before the suite starts (in Mocha/Jasmine only).
53
+ * @param {object} suite suite details
54
+ */
55
+ beforeSuite: function (suite) {
56
+ try {
57
+ console.log("Running suite:", suite.title);
58
+ console.log("Reading test data from the API");
59
+
60
+ getBSSessionDetails("app-automate", BUFFER.getItem("BROWSERSTACK_USERNAME"),
61
+ BUFFER.getItem("BROWSERSTACK_ACCESS_KEY"));
62
+
63
+ } catch (e) {
64
+ console.log("Error in beforeSuite:", e);
65
+ }
66
+ },
67
+
68
+ /**
69
+ * Function to be executed before a test (in Mocha/Jasmine only)
70
+ * @param {object} test test object
71
+ * @param {object} context scope object the test was executed with
72
+ */
73
+ beforeTest: function (test, context) {
74
+ console.log("Test Name:", test.title);
75
+ console.log("File Name:", test.file);
76
+
77
+ },
78
+
79
+ afterStep: function (test, context, { error, result, duration, passed, retries }) {
80
+ // if (passed) {
81
+ // browser.takeScreenshot();
82
+ // }
83
+ },
84
+
85
+ /**
86
+ * Function to be executed after a test (in Mocha/Jasmine only)
87
+ * @param {object} test test object
88
+ * @param {object} context scope object the test was executed with
89
+ * @param {Error} result.error error object in case the test fails, otherwise `undefined`
90
+ * @param {*} result.result return object of test function
91
+ * @param {number} result.duration duration of test
92
+ * @param {boolean} result.passed true if test has passed, otherwise false
93
+ * @param {object} result.retries information about spec related retries, e.g. `{ attempts: 0, limit: 0 }`
94
+ */
95
+ afterTest: function (test, context, { error, result, duration, passed, retries }) {
96
+ console.log(`Test '${test.title}' finished.`);
97
+ BUFFER.setItem("TOTAL_DURATION", Number(BUFFER.getItem("TOTAL_DURATION")) + duration)
98
+ console.log(`Duration: ${duration}ms`);
99
+ console.log(`Passed: ${passed}`);
100
+ if (passed)
101
+ console.log(`Result for '${test.title}' : ${result}`);
102
+ if (error) {
103
+ console.error(`Error: ${error.message}`);
104
+ }
105
+ console.log('---------------------------------------');
106
+ },
107
+ /**
108
+ * Hook that gets executed after the suite has ended (in Mocha/Jasmine only).
109
+ * @param {object} suite suite details
110
+ */
111
+ afterSuite: function (suite) {
112
+ console.log(`Test suite '${suite.title}' has ended.`);
113
+ },
114
+ /**
115
+ * Gets executed after all tests are done. You still have access to all global variables from
116
+ * the test.
117
+ * @param {number} result 0 - test pass, 1 - test fail
118
+ * @param {Array.<Object>} capabilities list of capabilities details
119
+ * @param {Array.<String>} specs List of spec file paths that ran
120
+ */
121
+ after: function (result, capabilities, specs) {
122
+ console.log('All tests are done.');
123
+ const resultdata = result === 0 ? 'Pass' : 'Fail';
124
+ console.log(`Result: ${resultdata}`);
125
+
126
+ const resultdetails = {}
127
+ resultdetails.excution_status = resultdata === 'Pass' ? 'PASSED' : 'FAILED'
128
+ resultdetails.excution_time = convertMillisecondsToTime(BUFFER.getItem("TOTAL_DURATION"))
129
+ exeDetails.updateExecuitonDetails(BUFFER.getItem("organisation_url"), BUFFER.getItem("LOGIN_TOKEN"), BUFFER.getItem("EXECUTION_ID"), resultdetails)
130
+ BUFFER.clear();
131
+ console.log('Local storage has been cleared.');
132
+ // console.log('Capabilities:');
133
+ // console.log(capabilities);
134
+ // console.log('Specs:');
135
+ // console.log(specs);
136
+ },
137
+
138
+ };
139
+
140
+ function convertMillisecondsToTime(msdata) {
141
+ const ms = parseInt(msdata.replace('ms', '').trim());
142
+
143
+ let seconds = Math.floor(ms / 1000);
144
+ let minutes = Math.floor(seconds / 60);
145
+ let hours = Math.floor(minutes / 60);
146
+
147
+ seconds = seconds % 60;
148
+ minutes = minutes % 60;
149
+
150
+ // Pad the values with leading zeros if they are less than 10
151
+ hours = String(hours).padStart(2, '0');
152
+ minutes = String(minutes).padStart(2, '0');
153
+ seconds = String(seconds).padStart(2, '0');
154
+
155
+ return `${hours}:${minutes}:${seconds}`;
156
+ }
157
+
158
+ // async function main() {
159
+ // try {
160
+ // const frothUrl = "devapi.frothtestops.com";
161
+ // const username = "subhra.subudhi@roboticodigital.com";
162
+ // const password = "V2VsY29tZUAxMjM=";
163
+
164
+ // const token = await getLoginToken(frothUrl, username, password);
165
+ // if (!token) {
166
+ // throw new Error('Login failed, no token obtained');
167
+ // }
168
+
169
+ // const id = 208;
170
+ // // const data = await getExecuitonDetails(frothUrl, token, id);
171
+ // // console.log("Retrieved JSON Data:", data);
172
+ // const resultdetails = {};
173
+ // const resultdata="Pass";
174
+ // const duration ="31355ms";
175
+ // resultdetails.excution_status = resultdata === 'Pass' ? 'PASSED' : 'FAILED'
176
+ // resultdetails.excution_time = convertMillisecondsToTime(duration)
177
+ // BUFFER.setItem("EXECUTION_ID",208);
178
+ // await exeDetails.updateExecuitonDetails(frothUrl, token, id,resultdetails);
179
+ // } catch (error) {
180
+ // console.error('Error in main function:', error);
181
+ // }
182
+ // }
183
+
184
+ // main();
185
+ module.exports = commonconfig;
@@ -0,0 +1,32 @@
1
+ // This is the configuration file for iOS devices
2
+ const deepmerge = require('deepmerge')
3
+ const commonmobileconfig = require('./common.mobile.conf');
4
+ const iosconfig = deepmerge.all([commonmobileconfig, {
5
+ services: [
6
+ [
7
+ 'browserstack',
8
+ {
9
+ testObservability: true,
10
+ buildName: "IOS",
11
+ buildIdentifier: 'BUILD',
12
+ browserstackLocal: false,
13
+ opts: {
14
+ forcelocal: false,
15
+ localIdentifier: "webdriverio-appium" },
16
+ app: process.env.BROWSERSTACK_APP_PATH || 'bs://d6588d0899a2ac5c485d4784af9ad28d06b98c44'
17
+ }
18
+ ]
19
+ ],
20
+
21
+ capabilities: [{
22
+ 'bstack:options': {
23
+ deviceName: process.env.DEVICENAME || "iPhone 15 Pro Max1",
24
+ osVersion: process.env.OSVERSION || "17",
25
+ interactiveDebugging: true
26
+ }
27
+ }],
28
+
29
+ }]);
30
+
31
+ module.exports = iosconfig;
32
+
@@ -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();
@@ -0,0 +1,95 @@
1
+ config = {
2
+ // ====================
3
+ // BrowserStack Configuration
4
+ // ====================
5
+ user: 'prabathkumar_qavxGX',
6
+ key: 'RvqEi62rhwa5QwGJtweZ',
7
+ browserstackLocal: true, // Set to true if using BrowserStack Local Testing
8
+ opts: { forceLocal: true },
9
+ // ====================
10
+ // Specify Test Files
11
+ // ====================
12
+
13
+ services: [
14
+ ['browserstack', {
15
+ testObservability: true,
16
+ testObservabilityOptions: {
17
+ user: 'prabathkumar_qavxGX' || process.env.BROWSERSTACK_USERNAME,
18
+ key: 'RvqEi62rhwa5QwGJtweZ' || process.env.BROWSERSTACK_ACCESS_KEY,
19
+ projectName: 'YTL_AF',
20
+ buildName: 'YTL_AF_WEBDRIVERIO',
21
+ buildTag: 'YTL_AF_WEBDRIVERIO',
22
+ },
23
+ }]
24
+ ],
25
+ // ====================
26
+ // Capabilities
27
+ // ====================
28
+ capabilities: [
29
+ {
30
+ browserName: 'chrome', // Choose the browser you want to test
31
+ browserVersion: 'latest', // Specify the browser version
32
+ os: 'Windows', // Specify the operating system
33
+ os_version: '10', // Specify the operating system version
34
+ resolution: '1920x1080', // Specify the screen resolution
35
+ 'browserstack.networkLogs': true, // Enable network logs
36
+ 'browserstack.video': true, // Enable video recording
37
+ },
38
+ // Add more capabilities for other browsers or devices as needed
39
+ ],
40
+
41
+ // ====================
42
+ // Test Configurations
43
+ // ====================
44
+ logLevel: 'info', // Set the log level
45
+ bail: 0, // Set to 1 to stop the test suite after the first test failure
46
+ baseUrl: '', // Specify the base URL of your application
47
+ waitforTimeout: 60000, // Set the timeout for all waitFor* commands
48
+ connectionRetryTimeout: 90000, // Set the timeout in milliseconds for test retries
49
+ connectionRetryCount: 3, // Set the number of times to retry the entire spec file
50
+
51
+ // ====================
52
+ // Framework
53
+ // ====================
54
+ framework: 'mocha', // Use the Mocha framework
55
+ reporters: ['spec',
56
+ // [
57
+ // 'allure',
58
+ // {
59
+ // outputDir: './web-report/allure-result/',
60
+ // disableWebdriverStepsReporting: true,
61
+ // disableWebdriverScreenshotsReporting: false,
62
+ // },
63
+ // ],
64
+ ], // Use the spec reporter
65
+
66
+ // ====================
67
+ // Hooks
68
+ // ====================
69
+ before: function (capabilities, specs) {
70
+ browser.maximizeWindow()
71
+ },
72
+ after: function (capabilities, specs) {
73
+ // Code to run after all tests
74
+ if (error) {
75
+ browser.takeScreenshot();
76
+ }
77
+ },
78
+
79
+ // ====================
80
+ // BrowserStack Options
81
+ // ====================
82
+ browserstackOpts: {
83
+ // BrowserStack-specific options
84
+ },
85
+
86
+ // ====================
87
+ // Mocha Options
88
+ // ====================
89
+ mochaOpts: {
90
+ ui: 'bdd', // Set the test interface to BDD
91
+ timeout: 60000, // Set the timeout for test cases in milliseconds
92
+ },
93
+ };
94
+
95
+ module.exports = config;
@@ -0,0 +1,70 @@
1
+
2
+
3
+ const config = {
4
+
5
+ // ====================
6
+ // Capabilities
7
+ // ====================
8
+ capabilities: [{
9
+ maxInstances: 5,
10
+ browserName: 'chrome',
11
+ acceptInsecureCerts: true,
12
+ }],
13
+
14
+ // ====================
15
+ // Test Configurations
16
+ // ====================
17
+ logLevel: 'info', // Set the log level
18
+ bail: 0, // Set to 1 to stop the test suite after the first test failure
19
+ baseUrl: '', // Specify the base URL of your application
20
+ waitforTimeout: 60000, // Set the timeout for all waitFor* commands
21
+ connectionRetryTimeout: 90000, // Set the timeout in milliseconds for test retries
22
+ connectionRetryCount: 3, // Set the number of times to retry the entire spec file
23
+
24
+ // ====================
25
+ // Framework
26
+ // ====================
27
+ framework: 'mocha', // Use the Mocha framework
28
+ reporters: ['spec'], // Use the spec reporter
29
+ // reporterOptions: {
30
+ // allure: {
31
+ // outputDir: 'allure-results',
32
+ // disableWebdriverStepsReporting: true,
33
+ // disableWebdriverScreenshotsReporting: false,
34
+ // }
35
+ //},
36
+ // ====================
37
+ // Hooks
38
+ // ====================
39
+ before: function (capabilities, specs) {
40
+ // Code to run before the first test
41
+ const currentDate = new Date();
42
+ const timestamp = currentDate.toISOString().replace(/[:.]/g, '');
43
+ browser.saveScreenshot('./screenshot_' + timestamp + '.png');
44
+
45
+ },
46
+ after: function (capabilities, specs) {
47
+ // Code to run to take screenshots
48
+ const currentDate = new Date();
49
+ const timestamp = currentDate.toISOString().replace(/[:.]/g, '');
50
+ browser.saveScreenshot('./screenshot_' + timestamp + '.png');
51
+
52
+
53
+ },
54
+
55
+ // ====================
56
+ // BrowserStack Options
57
+ // ====================
58
+ browserstackOpts: {
59
+ // BrowserStack-specific options
60
+ },
61
+
62
+ // ====================
63
+ // Mocha Options
64
+ // ====================
65
+ mochaOpts: {
66
+ ui: 'bdd', // Set the test interface to BDD
67
+ timeout: 60000, // Set the timeout for test cases in milliseconds
68
+ },
69
+ };
70
+ module.exports = config;
package/local.log ADDED
@@ -0,0 +1,8 @@
1
+
2
+
3
+ Thu Feb 15 2024 20:15:19:833 GMT+0800 (+08) -- Starting configuration console on http://localhost:45454
4
+ Thu Feb 15 2024 20:15:21:656 GMT+0800 (+08) -- [SUCCESS] You can now access your local server(s) in our remote browser
5
+
6
+ Thu Feb 15 2024 20:15:22:756 GMT+0800 (+08) -- Press Ctrl-C to exit
7
+
8
+
@@ -0,0 +1,44 @@
1
+ // This file contains the common methods that are used in the test scripts
2
+ let ScrollToEnd = null;
3
+ let ClickIfVisible=null;
4
+ let VerifyTextInFieldAttribute= null;
5
+ let ScrollToBeginning = null;
6
+ let ScrollToLeft = null;
7
+ let ScrollToRight = null;
8
+ let ScrollDownToView= null;
9
+ let ScrollRightToView= null;
10
+ let verifyText= null;
11
+
12
+ //if(process.env.LOCATION == 'local'){
13
+ ScrollToEnd = require('./ScrollToEnd');
14
+ ClickIfVisible= require('./clickIfVisible');
15
+ VerifyTextInFieldAttribute= require('./verifyTextInFieldAttribute');
16
+ ScrollToBeginning = require('./scrollToBeginning');
17
+ ScrollToLeft = require('./scrollToLeft');
18
+ ScrollToRight = require('./scrollToRight');
19
+ ScrollDownToView= require('./ScrollDownToView');
20
+ ScrollRightToView= require('./ScrollRightToView');
21
+ verifyText= require('./verifyText');
22
+ // }else{
23
+ // ScrollToEnd = require('froth-webdriverio-framework/mobile/commonMethods/scrollToEnd');
24
+ // ClickIfVisible= require('froth-webdriverio-framework/mobile/commonMethods/clickIfVisible');
25
+ // VerifyTextInFieldAttribute= require('froth-webdriverio-framework/mobile/commonMethods/verifyTextInFieldAttribute');
26
+ // ScrollToBeginning = require('froth-webdriverio-framework/mobile/commonMethods/scrollToBeginning');
27
+ // ScrollToLeft = require('froth-webdriverio-framework/mobile/commonMethods/scrollToLeft');
28
+ // ScrollToRight = require('froth-webdriverio-framework/mobile/commonMethods/scrollToRight');
29
+ // ScrollDownToView= require('froth-webdriverio-framework/mobile/commonMethods/scrollDownToView');
30
+ // ScrollRightToView= require('froth-webdriverio-framework/mobile/commonMethods/scrollRightToView');
31
+ // verifyText= require('froth-webdriverio-framework/mobile/commonMethods/verifyText');
32
+ // }
33
+ // Export the functions
34
+ module.exports = {
35
+ ScrollToEnd,
36
+ ClickIfVisible,
37
+ VerifyTextInFieldAttribute,
38
+ ScrollToBeginning,
39
+ ScrollToLeft,
40
+ ScrollToRight,
41
+ ScrollRightToView,
42
+ ScrollDownToView,
43
+ verifyText
44
+ };
@@ -0,0 +1,23 @@
1
+ async function clickIfVisible(elementSelector) {
2
+ try {
3
+ let isDisplayed;
4
+ // Wait for the element to be visible
5
+ await driver.waitUntil(async () => {
6
+ console.log("Waiting for element to be visible");
7
+ const element = await driver.$(elementSelector);
8
+ isDisplayed = await element.isDisplayed();
9
+ console.log("Element is displayed:", isDisplayed);
10
+ if (isDisplayed) {
11
+ // Get the actual text from the element
12
+ const element = await driver.$(elementSelector);
13
+ await element.click();
14
+ console.log("Element is clicked successfully.");
15
+ return ;
16
+ }
17
+ }, { timeout: 30000 });
18
+ } catch (error) {
19
+ console.error("Element not found or not visible within 30 seconds");
20
+ }
21
+ }
22
+
23
+ module.exports = clickIfVisible;
@@ -0,0 +1,38 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const directory = '/Users/subhrasubudhi/WORKSPACES/WEBDRIVERIO/TEST/mobile/Testdata'; // specify your directory path
4
+ async function getdata(filename_propertyname) {
5
+ try {
6
+ console.log('data:', filename_propertyname);
7
+ const parts = filename_propertyname.split(".");
8
+ const property = parts[1];
9
+ console.log('property:', property);
10
+ fileName = parts[0] + '.json';
11
+ console.log('filename:', fileName);
12
+
13
+ const files = await fs.promises.readdir(directory);
14
+ const file = files.find(file => file === fileName);
15
+
16
+ if (file) {
17
+ const filePath = path.join(directory, file);
18
+ const jsonData = await fs.promises.readFile(filePath, 'utf-8');
19
+ const parsedData = JSON.parse(jsonData);
20
+ console.log(parsedData);
21
+ const value = parsedData[property];
22
+ console.log(value);
23
+ return value;
24
+ } else {
25
+ throw new Error(`File '${_filename}' not found in directory '${directory}'.`);
26
+ }
27
+ } catch (error) {
28
+ console.error('Error occurred:', error);
29
+ throw error; // Rethrow the error for the caller to handle.
30
+ }
31
+ }
32
+ module.exports = getdata;
33
+ // Example usage:
34
+ // specify your file name
35
+
36
+ console.log(getdata('data1.env'));
37
+
38
+
@@ -0,0 +1,12 @@
1
+ async function ScrollDownToView(text) {
2
+
3
+ try {
4
+ console.log('Scrolling down until text is found');
5
+ await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView("' + text + '")');
6
+ await driver.pause(3000);
7
+ console.log('Scrolled down completed');
8
+ } catch (error) {
9
+ console.error(error.message);
10
+ }
11
+ }
12
+ module.exports = ScrollDownToView;
@@ -0,0 +1,12 @@
1
+ async function ScrollRightToView(text) {
2
+
3
+ try {
4
+ console.log('Scrolling to right until text is found');
5
+ await $('android=new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().scrollTextIntoView("' + text + '")');
6
+ await driver.pause(3000);
7
+ console.log('Scrolled to right completed');
8
+ } catch (error) {
9
+ console.error(error.message);
10
+ }
11
+ }
12
+ module.exports = ScrollRightToView;
@@ -0,0 +1,12 @@
1
+ async function ScrollToBeginning(maxSwipes,steps) {
2
+
3
+ try {
4
+ console.log('Scrolling to beginning');
5
+ await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollToBeginning('+maxSwipes+','+steps+')');
6
+ await driver.pause(3000);
7
+ console.log('Scrolled to beginning');
8
+ } catch (error) {
9
+ console.error(error.message);
10
+ }
11
+ }
12
+ module.exports = ScrollToBeginning;
@@ -0,0 +1,12 @@
1
+ async function ScrollToEnd(maxSwipes,steps) {
2
+
3
+ try {
4
+ console.log('Scrolling to end');
5
+ await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollToEnd('+maxSwipes+','+steps+')');
6
+ await driver.pause(3000);
7
+ console.log('Scrolled to end');
8
+ } catch (error) {
9
+ console.error(error.message);
10
+ }
11
+ }
12
+ module.exports = ScrollToEnd;
@@ -0,0 +1,12 @@
1
+ async function ScrollToLeft(steps) {
2
+
3
+ try {
4
+ console.log('Scrolling to left');
5
+ await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollable.setAsHorizontalList().scrollBackward('+steps+')');
6
+ await driver.pause(3000);
7
+ console.log('Scrolled to left');
8
+ } catch (error) {
9
+ console.error(error.message);
10
+ }
11
+ }
12
+ module.exports = ScrollToLeft;
@@ -0,0 +1,12 @@
1
+ async function ScrollToRight(steps) {
2
+
3
+ try {
4
+ console.log('Scrolling to right');
5
+ await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollable.setAsHorizontalList().scrollForward('+steps+')');
6
+ await driver.pause(3000);
7
+ console.log('Scrolled to right');
8
+ } catch (error) {
9
+ console.error(error.message);
10
+ }
11
+ }
12
+ module.exports = ScrollToRight;
@@ -0,0 +1,19 @@
1
+ const fs = require("fs");
2
+
3
+ function readAndParseJSON(filename) {
4
+ const [fileName, fileExtension] = filename.split(".");
5
+ const jsonFilePath = fileName + ".json";
6
+ const constantProperty = fileExtension;
7
+
8
+ const filePath = `/Users/subhrasubudhi/WORKSPACES/WEBDRIVERIO/TEST/mobile/Testdata/${jsonFilePath}`;
9
+
10
+ const jsonData = fs.readFileSync(filePath, "utf-8");
11
+ const parsedData = JSON.parse(jsonData);
12
+
13
+ console.log(parsedData);
14
+ const value = parsedData[constantProperty];
15
+ return value;
16
+ }
17
+
18
+ const data1 = readAndParseJSON("data1.env");
19
+ console.log(data1);
@@ -0,0 +1,28 @@
1
+ // Function to verify text in Android app
2
+ async function verifyText(driver, elementSelector, expectedText) {
3
+ try {
4
+ // Wait for the element to be visible
5
+ await driver.waitUntil(async () => {
6
+ const element = await driver.$(elementSelector);
7
+ return await element.isDisplayed();
8
+ }, { timeout: 30000});
9
+
10
+ // Get the actual text from the element
11
+ const element = await driver.$(elementSelector);
12
+ const actualText = await element.getText();
13
+
14
+ // Compare the actual text with the expected text
15
+ if (actualText === expectedText) {
16
+ console.log('Text verification passed. Actual text:', actualText, 'Expected text:', expectedText);
17
+ return true;
18
+ } else {
19
+ console.warn('Text verification failed. Actual text:', actualText, 'Expected text:', expectedText);
20
+ }
21
+ } catch (error) {
22
+ console.error('Error occurred while verifying text:', error);
23
+ }
24
+ }
25
+
26
+ module.exports = verifyText;
27
+
28
+
@@ -0,0 +1,17 @@
1
+
2
+ async function verifyTextInFieldAttribute(element, attribute, expectedText, driver) {
3
+
4
+ try {
5
+ let ele = await driver.$(element);
6
+ // Get the actual text from the specified attribute
7
+ const actualText = await ele.getAttribute(attribute);
8
+
9
+ // Assert that the actual text matches the expected text
10
+ assert.strictEqual(actualText, expectedText, `Expected text: ${expectedText}, Actual text: ${actualText}`);
11
+ console.log('Text verification passed!');
12
+ } catch (error) {
13
+ console.log('Text verification failed:', `Expected text: ${expectedText}, Actual text: ${actualText}`);
14
+ console.error(error.message);
15
+ }
16
+ }
17
+ module.exports = verifyTextInFieldAttribute;