webship-js 1.0.41 → 1.0.42
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.
- package/.circleci/config.yml +1 -1
- package/.github/workflows/github-actions.yml +1 -1
- package/.gitlab-ci.yml +1 -1
- package/.yarn/install-state.gz +0 -0
- package/bitbucket-pipelines.yml +1 -2
- package/examples/test--when--i-scroll-left-right-functionality.html +207 -0
- package/package.json +2 -2
- package/steplist.js +1 -1
- package/tests/features/test--when--i-scroll-left-right.feature +48 -0
- package/tests/step-definitions/webship.js +201 -1
- package/lib/custom-hooks/before-after.js +0 -30
package/.circleci/config.yml
CHANGED
|
@@ -27,7 +27,7 @@ commands:
|
|
|
27
27
|
- run:
|
|
28
28
|
name: Install node js
|
|
29
29
|
command: |
|
|
30
|
-
curl -sL https://deb.nodesource.com/
|
|
30
|
+
curl -sL https://deb.nodesource.com/setup_20.x | sudo bash -
|
|
31
31
|
sudo apt install -y nodejs
|
|
32
32
|
sudo npm install -g yarn
|
|
33
33
|
## Install Java.
|
package/.gitlab-ci.yml
CHANGED
|
@@ -12,7 +12,7 @@ before_script:
|
|
|
12
12
|
- sudo apt-get upgrade -qqy
|
|
13
13
|
- sudo apt-get install -yqq vim links lynx git diffutils htop curl wget p7zip-full unzip zip sed gcc g++ make libfreetype6-dev libaio1 libaio-dev libonig-dev libpng-dev
|
|
14
14
|
- sudo apt-get install -yqq xvfb libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3.0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 libnss3
|
|
15
|
-
- curl -sL https://deb.nodesource.com/
|
|
15
|
+
- curl -sL https://deb.nodesource.com/setup_20.x | sudo bash -
|
|
16
16
|
- sudo apt-get install -y nodejs
|
|
17
17
|
- sudo npm install -g yarn
|
|
18
18
|
- sudo apt-get update
|
|
Binary file
|
package/bitbucket-pipelines.yml
CHANGED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset='utf-8'>
|
|
6
|
+
<title>Complete Horizontal Scroll Functionality Test</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 20px;
|
|
11
|
+
font-family: Arial, sans-serif;
|
|
12
|
+
overflow-x: auto;
|
|
13
|
+
overflow-y: hidden;
|
|
14
|
+
white-space: nowrap;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.container,
|
|
18
|
+
.container input,
|
|
19
|
+
.container button {
|
|
20
|
+
font-size: 26px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.style {
|
|
24
|
+
font-size: 22px;
|
|
25
|
+
line-height: 30px;
|
|
26
|
+
border: 1px solid #ccc;
|
|
27
|
+
padding: 10px;
|
|
28
|
+
margin: 10px;
|
|
29
|
+
background-color: #f9f9f9;
|
|
30
|
+
display: inline-block;
|
|
31
|
+
width: 300px;
|
|
32
|
+
vertical-align: top;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.indicator {
|
|
36
|
+
font-size: 28px;
|
|
37
|
+
font-weight: bold;
|
|
38
|
+
color: #007bff;
|
|
39
|
+
padding: 15px;
|
|
40
|
+
margin: 10px;
|
|
41
|
+
border: 2px solid #007bff;
|
|
42
|
+
background-color: #e7f3ff;
|
|
43
|
+
display: none;
|
|
44
|
+
display: inline-block;
|
|
45
|
+
width: 400px;
|
|
46
|
+
vertical-align: top;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#scrollable-container {
|
|
50
|
+
width: 1000px;
|
|
51
|
+
overflow-x: auto;
|
|
52
|
+
overflow-y: hidden;
|
|
53
|
+
border: 2px solid #333;
|
|
54
|
+
margin: 20px;
|
|
55
|
+
padding: 10px;
|
|
56
|
+
background-color: #f0f0f0;
|
|
57
|
+
display: inline-block;
|
|
58
|
+
vertical-align: top;
|
|
59
|
+
white-space: nowrap;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.scrollable-content {
|
|
63
|
+
width: 1600px;
|
|
64
|
+
height: 200px;
|
|
65
|
+
background: linear-gradient(to right, #ff9999, #99ff99, #9999ff);
|
|
66
|
+
padding: 20px;
|
|
67
|
+
position: relative;
|
|
68
|
+
display: inline-block;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.scroll-marker {
|
|
72
|
+
position: absolute;
|
|
73
|
+
font-size: 18px;
|
|
74
|
+
font-weight: bold;
|
|
75
|
+
background-color: rgba(255, 255, 255, 0.8);
|
|
76
|
+
padding: 5px 10px;
|
|
77
|
+
border-radius: 5px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.scroll-marker.left {
|
|
81
|
+
left: 10px;
|
|
82
|
+
top: 10px;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.scroll-marker.right {
|
|
86
|
+
right: 10px;
|
|
87
|
+
bottom: 10px;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#complete {
|
|
91
|
+
display: none;
|
|
92
|
+
font-size: 32px;
|
|
93
|
+
line-height: 40px;
|
|
94
|
+
color: #28a745;
|
|
95
|
+
font-weight: bold;
|
|
96
|
+
text-align: center;
|
|
97
|
+
padding: 20px;
|
|
98
|
+
border: 3px solid #28a745;
|
|
99
|
+
background-color: #d4edda;
|
|
100
|
+
margin: 20px;
|
|
101
|
+
width: 300px;
|
|
102
|
+
display: inline-block;
|
|
103
|
+
vertical-align: top;
|
|
104
|
+
position: absolute;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#page-wrapper {
|
|
108
|
+
min-width: 4000px;
|
|
109
|
+
white-space: nowrap;
|
|
110
|
+
}
|
|
111
|
+
</style>
|
|
112
|
+
</head>
|
|
113
|
+
|
|
114
|
+
<body>
|
|
115
|
+
<div id="page-wrapper">
|
|
116
|
+
<h1 style="display:inline-block; vertical-align:top; margin-right: 20px;">Horizontal Scrolling Functionality Test Page</h1>
|
|
117
|
+
|
|
118
|
+
<!-- Indicators -->
|
|
119
|
+
<div id="basic-scroll-down" class="indicator">Basic scroll right works</div>
|
|
120
|
+
<div id="basic-scroll-up" class="indicator">Basic scroll left works</div>
|
|
121
|
+
<div id="custom-scroll-down" class="indicator">Custom scroll right works</div>
|
|
122
|
+
<div id="custom-scroll-up" class="indicator">Custom scroll left works</div>
|
|
123
|
+
<div id="scroll-to-top" class="indicator">Scroll to left works</div>
|
|
124
|
+
|
|
125
|
+
<!-- Main content -->
|
|
126
|
+
<div id="container" style="display:inline-block; vertical-align:top;">
|
|
127
|
+
<p class="style">This is the starting content of the page</p>
|
|
128
|
+
<!-- سيتم توليد Content section 1-30 تلقائيًا عبر JavaScript -->
|
|
129
|
+
|
|
130
|
+
<!-- Scroll to right end element (في آخر اليمين فعليًا) -->
|
|
131
|
+
<div id="complete">Scroll to right end works</div>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<!-- Scrollable element container -->
|
|
135
|
+
<div>
|
|
136
|
+
<h2 style="display:inline-block; vertical-align:top;">Scrollable Horizontal Container Test</h2>
|
|
137
|
+
<div id="scrollable-container">
|
|
138
|
+
<div class="scrollable-content">
|
|
139
|
+
<div class="scroll-marker left">Element scroll to left works</div>
|
|
140
|
+
<p style="display:inline-block;">This is a scrollable container with a lot of content inside.</p>
|
|
141
|
+
<p style="display:inline-block;">You can scroll horizontally.</p>
|
|
142
|
+
<div class="scroll-marker right">Element scroll to right works</div>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
</body>
|
|
148
|
+
|
|
149
|
+
<script>
|
|
150
|
+
const container = document.getElementById("container");
|
|
151
|
+
|
|
152
|
+
// توليد 30 قسم لزيادة العرض الأفقي
|
|
153
|
+
for (var i = 1; i <= 30; i++) {
|
|
154
|
+
const section = document.createElement("p");
|
|
155
|
+
section.className = "style";
|
|
156
|
+
section.innerText = "Content section #" + i;
|
|
157
|
+
container.insertBefore(section, document.getElementById("complete"));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let scrollTimeout;
|
|
161
|
+
|
|
162
|
+
window.addEventListener('scroll', function () {
|
|
163
|
+
clearTimeout(scrollTimeout);
|
|
164
|
+
scrollTimeout = setTimeout(function () {
|
|
165
|
+
const scrollX = window.scrollX;
|
|
166
|
+
const windowWidth = window.innerWidth;
|
|
167
|
+
const documentWidth = document.documentElement.scrollWidth;
|
|
168
|
+
|
|
169
|
+
// إخفاء جميع المؤشرات
|
|
170
|
+
document.querySelectorAll('.indicator').forEach(el => el.style.display = 'none');
|
|
171
|
+
|
|
172
|
+
if (scrollX === 0) {
|
|
173
|
+
document.getElementById('scroll-to-top').style.display = 'inline-block';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (scrollX + windowWidth >= documentWidth - 10) {
|
|
177
|
+
document.getElementById('basic-scroll-down').style.display = 'inline-block';
|
|
178
|
+
document.getElementById('complete').style.display = 'inline-block';
|
|
179
|
+
} else {
|
|
180
|
+
document.getElementById('complete').style.display = 'none';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (scrollX >= 450 && scrollX <= 550) {
|
|
184
|
+
document.getElementById('custom-scroll-down').style.display = 'inline-block';
|
|
185
|
+
} else if (scrollX + windowWidth >= documentWidth - 50) {
|
|
186
|
+
if (window.lastScrollDirection === 'left') {
|
|
187
|
+
document.getElementById('custom-scroll-up').style.display = 'inline-block';
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// تتبع الاتجاه
|
|
192
|
+
if (scrollX > (window.lastScrollX || 0)) {
|
|
193
|
+
window.lastScrollDirection = 'right';
|
|
194
|
+
} else {
|
|
195
|
+
window.lastScrollDirection = 'left';
|
|
196
|
+
}
|
|
197
|
+
window.lastScrollX = scrollX;
|
|
198
|
+
}, 100);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const scrollableContainer = document.getElementById('scrollable-container');
|
|
202
|
+
scrollableContainer.addEventListener('scroll', function () {
|
|
203
|
+
console.log('Scrollable container scrolled to (horizontal):', this.scrollLeft);
|
|
204
|
+
});
|
|
205
|
+
</script>
|
|
206
|
+
|
|
207
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webship-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"description": "Webship JS automated functional testing.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"engines": {
|
|
10
10
|
"yarn": ">= 1.6",
|
|
11
|
-
"node": ">=
|
|
11
|
+
"node": ">= 20.0"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"test": "nightwatch --format @cucumber/pretty-formatter --format-options '{\"colorsEnabled\": true}' --format-options '{\"theme\": {\"feature keyword\":[\"bold\",\"blue\"],\"feature name\":[\"blue\",\"underline\"],\"feature description\":[\"blueBright\"],\"scenario keyword\":[\"bold\",\"magenta\"],\"scenario name\":[\"magenta\",\"underline\"],\"step keyword\":[\"bold\",\"green\"],\"step text\":[\"greenBright\",\"italic\"]}}' --format json:./tests/reports/cucumber_report.json; node generate-reports.js;",
|
package/steplist.js
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Feature: Complete scrolling functionality test
|
|
2
|
+
As a tester,
|
|
3
|
+
I want to test all scrolling step definitions to ensure they work correctly.
|
|
4
|
+
|
|
5
|
+
Scenario: Test basic scroll down functionality
|
|
6
|
+
Given I am on "/test--when--i-scroll-left-right-functionality.html"
|
|
7
|
+
When I scroll down
|
|
8
|
+
Then I should see "Basic scroll down works"
|
|
9
|
+
|
|
10
|
+
Scenario: Test basic scroll up functionality
|
|
11
|
+
Given I am on "/test--when--i-scroll-left-right-functionality.html"
|
|
12
|
+
When I scroll to the bottom
|
|
13
|
+
And I scroll up
|
|
14
|
+
Then I should see "Basic scroll up works"
|
|
15
|
+
|
|
16
|
+
Scenario: Test scroll down with custom value
|
|
17
|
+
Given I am on "/test--when--i-scroll-left-right-functionality.html"
|
|
18
|
+
When I scroll down 500
|
|
19
|
+
Then I should see "Custom scroll down works"
|
|
20
|
+
|
|
21
|
+
Scenario: Test scroll up with custom value
|
|
22
|
+
Given I am on "/test--when--i-scroll-left-right-functionality.html"
|
|
23
|
+
When I scroll to the bottom
|
|
24
|
+
And I scroll up 300
|
|
25
|
+
Then I should see "Custom scroll up works"
|
|
26
|
+
|
|
27
|
+
Scenario: Test scroll to top functionality
|
|
28
|
+
Given I am on "/test--when--i-scroll-left-right-functionality.html"
|
|
29
|
+
When I scroll to the bottom
|
|
30
|
+
And I scroll to top
|
|
31
|
+
Then I should see "Scroll to top works"
|
|
32
|
+
|
|
33
|
+
Scenario: Test scroll to bottom functionality
|
|
34
|
+
Given I am on "/test--when--i-scroll-left-right-functionality.html"
|
|
35
|
+
When I scroll to the bottom
|
|
36
|
+
Then I should see "Scroll to bottom works"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
Scenario: Test scroll to top of element
|
|
40
|
+
Given I am on "/test--when--i-scroll-left-right-functionality.html"
|
|
41
|
+
When I scroll to bottom of "#scrollable-container"
|
|
42
|
+
And I scroll to top of "#scrollable-container"
|
|
43
|
+
Then I should see "Element scroll to top works"
|
|
44
|
+
|
|
45
|
+
Scenario: Test scroll to bottom of element
|
|
46
|
+
Given I am on "/test--when--i-scroll-left-right-functionality.html"
|
|
47
|
+
When I scroll to bottom of "#scrollable-container"
|
|
48
|
+
Then I should see "Element scroll to bottom works"
|
|
@@ -1,11 +1,41 @@
|
|
|
1
1
|
const { Given } = require('@cucumber/cucumber');
|
|
2
2
|
const { When } = require('@cucumber/cucumber');
|
|
3
3
|
const { Then } = require('@cucumber/cucumber');
|
|
4
|
-
require('
|
|
4
|
+
const {Before, After, BeforeStep, AfterStep} = require('@cucumber/cucumber');
|
|
5
|
+
|
|
5
6
|
|
|
6
7
|
const axios = require('axios');
|
|
7
8
|
const path = require('path');
|
|
8
9
|
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Safely pauses based on global config.
|
|
13
|
+
* Handles case where browser or globals may be undefined.
|
|
14
|
+
* @param {string} key
|
|
15
|
+
*/
|
|
16
|
+
function safePause(key) {
|
|
17
|
+
const time = (global.browser?.globals?.minimum_wait_time?.[key]) || 0;
|
|
18
|
+
if (time > 0 && global.browser?.pause) {
|
|
19
|
+
global.browser.pause(time);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
Before(function () {
|
|
24
|
+
safePause('before_scenario');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
After(function () {
|
|
28
|
+
safePause('after_scenario');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
BeforeStep(function () {
|
|
32
|
+
safePause('before_step');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
AfterStep(function () {
|
|
36
|
+
safePause('after_step');
|
|
37
|
+
});
|
|
38
|
+
|
|
9
39
|
/**
|
|
10
40
|
* Opens homepage.
|
|
11
41
|
*
|
|
@@ -1337,3 +1367,173 @@ When(/^(I scroll|we scroll|scrolling)? to bottom of "([^"]*)"$/, function(pronou
|
|
|
1337
1367
|
throw new Error(`Failed to scroll to bottom of element "${selector}": ${error.message}`);
|
|
1338
1368
|
}
|
|
1339
1369
|
});
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* Scrolls right the page by a custom number of pixels specified by the user.
|
|
1373
|
+
*
|
|
1374
|
+
* Example #1: And I scroll right
|
|
1375
|
+
* Example #2: When I scroll right 1000
|
|
1376
|
+
* Example #3: And we scrolling right 300
|
|
1377
|
+
* Example #4: When scrolling right 750
|
|
1378
|
+
*
|
|
1379
|
+
*/
|
|
1380
|
+
When(/^(I scroll|we scroll|scrolling)? right( ([^"]*)?)*$/, function(pronounCase, value) {
|
|
1381
|
+
// Parse and validate the scroll value
|
|
1382
|
+
let scrollValue = 350; // default value
|
|
1383
|
+
|
|
1384
|
+
if (value !== null) {
|
|
1385
|
+
scrollValue = parseInt(String(value).trim(), 10);
|
|
1386
|
+
|
|
1387
|
+
// Validate the parsed value
|
|
1388
|
+
if (isNaN(scrollValue)) {
|
|
1389
|
+
throw new Error(`Invalid scroll value: "${value}". Expected a number.`);
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
if (scrollValue < 0) {
|
|
1393
|
+
throw new Error(`Scroll right value must be positive. Received: ${scrollValue}`);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
if (scrollValue > 10000) {
|
|
1397
|
+
console.warn(`Large scroll value detected: ${scrollValue}px. Consider if this is intentional.`);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
// Make the value negative for scrolling right
|
|
1402
|
+
return browser.executeScript(`window.scrollBy( ${scrollValue}, 0);`);
|
|
1403
|
+
});
|
|
1404
|
+
|
|
1405
|
+
/**
|
|
1406
|
+
* Scrolls left the page by a custom number of pixels specified by the user.
|
|
1407
|
+
*
|
|
1408
|
+
* Example #1: And I scroll left
|
|
1409
|
+
* Example #2: When I scroll left 800
|
|
1410
|
+
* Example #3: And we scroll left 500
|
|
1411
|
+
* Example #4: When scrolling left 1200
|
|
1412
|
+
*/
|
|
1413
|
+
When(/^(I scroll|we scroll|scrolling)? left( ([^"]*)?)*$/, function(pronounCase, value) {
|
|
1414
|
+
// Default scroll value
|
|
1415
|
+
let scrollValue = 350;
|
|
1416
|
+
|
|
1417
|
+
if (value !== null) {
|
|
1418
|
+
scrollValue = parseInt(String(value).trim(), 10);
|
|
1419
|
+
|
|
1420
|
+
// Validate the parsed value
|
|
1421
|
+
if (isNaN(scrollValue)) {
|
|
1422
|
+
throw new Error(`Invalid scroll value: "${value}". Expected a number.`);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
if (scrollValue < 0) {
|
|
1426
|
+
throw new Error(`Scroll left value must be positive. Received: ${scrollValue}`);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
if (scrollValue > 10000) {
|
|
1430
|
+
console.warn(`Large scroll value detected: ${scrollValue}px. Consider if this is intentional.`);
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
return browser.executeScript(`window.scrollBy( -${scrollValue},0 );`);
|
|
1435
|
+
});
|
|
1436
|
+
|
|
1437
|
+
/**
|
|
1438
|
+
* Scrolls to the very start of the current page, resetting the scroll position to zero.
|
|
1439
|
+
*
|
|
1440
|
+
* Example #1: When I scroll to start
|
|
1441
|
+
* Example #2: And we scrolling to the start
|
|
1442
|
+
* Example #3: When scrolling to the start of the page
|
|
1443
|
+
*/
|
|
1444
|
+
When(/^(I scroll|we scroll|scrolling)? to( the)* start( of the page)*$/, function(pronounCase, theCase, pageCase) {
|
|
1445
|
+
return browser.executeScript('window.scrollTo(0, window.scrollY);');
|
|
1446
|
+
});
|
|
1447
|
+
|
|
1448
|
+
/**
|
|
1449
|
+
* Scrolls to the end of the current page using the full document height.
|
|
1450
|
+
*
|
|
1451
|
+
* Example #1: When I scroll to the end
|
|
1452
|
+
* Example #2: And we scroll to end
|
|
1453
|
+
* Example #3: When scrolling to the end of the page
|
|
1454
|
+
*/
|
|
1455
|
+
When(/^(I scroll|we scroll|scrolling)? to( the)* end( of the page)*$/, function(pronounCase, theCase, pageCase) {
|
|
1456
|
+
return browser.executeScript('window.scrollTo(document.body.scrollWidth, window.scrollY);');
|
|
1457
|
+
});
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* Scrolls to the start of a specific element identified by a CSS selector, resetting its scroll position to zero.
|
|
1461
|
+
*
|
|
1462
|
+
* Example #1: When I scroll to start of "#off-canvas"
|
|
1463
|
+
* Example #2: And we scroll to start of "#sidebar"
|
|
1464
|
+
* Example #3: When scrolling to start of "#main-container"
|
|
1465
|
+
*/
|
|
1466
|
+
When(/^(I scroll|we scroll|scrolling)? to start of "([^"]*)"$/, function(pronounCase, selector) {
|
|
1467
|
+
// Validate selector
|
|
1468
|
+
if (!selector || selector.trim() === '') {
|
|
1469
|
+
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// Validate selector format (basic check)
|
|
1473
|
+
if (selector.includes('"') || selector.includes("'")) {
|
|
1474
|
+
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
try {
|
|
1478
|
+
// Check if element exists before scrolling
|
|
1479
|
+
const elementExists = browser.executeScript(`
|
|
1480
|
+
return document.querySelector("${selector}") !== null;
|
|
1481
|
+
`);
|
|
1482
|
+
|
|
1483
|
+
if (!elementExists) {
|
|
1484
|
+
throw new Error(`Element with selector "${selector}" not found.`);
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
browser.executeScript(`
|
|
1488
|
+
const element = document.querySelector("${selector}");
|
|
1489
|
+
if (element) {
|
|
1490
|
+
element.scrollTop = 0;
|
|
1491
|
+
}
|
|
1492
|
+
`);
|
|
1493
|
+
|
|
1494
|
+
return browser.pause(2000);
|
|
1495
|
+
} catch (error) {
|
|
1496
|
+
throw new Error(`Failed to scroll to top of element "${selector}": ${error.message}`);
|
|
1497
|
+
}
|
|
1498
|
+
});
|
|
1499
|
+
|
|
1500
|
+
/**
|
|
1501
|
+
* Scrolls to the end of a specific element identified by a CSS selector, moving to its maximum scroll height.
|
|
1502
|
+
*
|
|
1503
|
+
* Example #1: When I scroll to end of "#off-canvas"
|
|
1504
|
+
* Example #2: And we scrolling to end of "#sidebar"
|
|
1505
|
+
* Example #3: When scrolling to end of "#main-container"
|
|
1506
|
+
*/
|
|
1507
|
+
When(/^(I scroll|we scroll|scrolling)? to end of "([^"]*)"$/, function(pronounCase, selector) {
|
|
1508
|
+
// Validate selector
|
|
1509
|
+
if (!selector || selector.trim() === '') {
|
|
1510
|
+
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
// Validate selector format (basic check)
|
|
1514
|
+
if (selector.includes('"') || selector.includes("'")) {
|
|
1515
|
+
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
try {
|
|
1519
|
+
// Check if element exists before scrolling
|
|
1520
|
+
const elementExists = browser.executeScript(`
|
|
1521
|
+
return document.querySelector("${selector}") !== null;
|
|
1522
|
+
`);
|
|
1523
|
+
|
|
1524
|
+
if (!elementExists) {
|
|
1525
|
+
throw new Error(`Element with selector "${selector}" not found.`);
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
browser.executeScript(`
|
|
1529
|
+
const element = document.querySelector("${selector}");
|
|
1530
|
+
if (element) {
|
|
1531
|
+
element.scrollTop = element.scrollWidth;
|
|
1532
|
+
}
|
|
1533
|
+
`);
|
|
1534
|
+
|
|
1535
|
+
return browser.pause(2000);
|
|
1536
|
+
} catch (error) {
|
|
1537
|
+
throw new Error(`Failed to scroll to bottom of element "${selector}": ${error.message}`);
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const {Before, After, BeforeStep, AfterStep} = require('@cucumber/cucumber');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Safely pauses based on global config.
|
|
5
|
-
* Handles case where browser or globals may be undefined.
|
|
6
|
-
* @param {string} key
|
|
7
|
-
*/
|
|
8
|
-
function safePause(key) {
|
|
9
|
-
const time = (global.browser?.globals?.minimum_wait_time?.[key]) || 0;
|
|
10
|
-
if (time > 0 && global.browser?.pause) {
|
|
11
|
-
global.browser.pause(time);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Register hooks
|
|
16
|
-
Before(function () {
|
|
17
|
-
safePause('before_scenario');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
After(function () {
|
|
21
|
-
safePause('after_scenario');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
BeforeStep(function () {
|
|
25
|
-
safePause('before_step');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
AfterStep(function () {
|
|
29
|
-
safePause('after_step');
|
|
30
|
-
});
|