Skip to content

Commit 5ec6656

Browse files
committed
feat: Add support for additional step types (change, waitForElement) to API documentation and validation
1 parent dbe2614 commit 5ec6656

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Req-Scrap is a RESTful API service that allows you to perform web scraping opera
88

99
## Features
1010

11-
- **Step-Based Scraping**: Define your scraping workflow as a series of steps (navigate, click, wait, setViewport, etc.)
11+
- **Step-Based Scraping**: Define your scraping workflow as a series of steps (navigate, click, wait, setViewport, change, waitForElement, etc.)
1212
- **Speed Control**: Multiple speed modes to control execution pace (TURBO, FAST, NORMAL, SLOW, SLOWEST, CRAWL, STEALTH)
1313
- **Proxy Support**: Configure proxies with authentication for web requests
1414
- **Security**: Built-in basic authentication, helmet protection, and CORS configuration
@@ -105,6 +105,15 @@ Main endpoint for web scraping operations.
105105
"type": "setViewport",
106106
"width": 1366,
107107
"height": 768
108+
},
109+
{
110+
"type": "change",
111+
"selectors": [".search-input"],
112+
"value": "example search"
113+
},
114+
{
115+
"type": "waitForElement",
116+
"selectors": [".search-results"]
108117
}
109118
],
110119
"proxy": {

constants.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,16 @@ export const AUTH_DEFAULTS = {
162162
* CLICK: Perform a click action
163163
* WAIT: Wait for a specified duration
164164
* SET_VIEWPORT: Set the browser viewport size
165+
* CHANGE: Change the value of an input element
166+
* WAIT_FOR_ELEMENT: Wait for a specific element to appear on the page
165167
*/
166168
export const STEP_TYPES = {
167169
NAVIGATE: 'navigate',
168170
CLICK: 'click',
169171
WAIT: 'wait',
170-
SET_VIEWPORT: 'setViewport'
172+
SET_VIEWPORT: 'setViewport',
173+
CHANGE: 'change',
174+
WAIT_FOR_ELEMENT: 'waitForElement'
171175
};
172176

173177
/**

helpers/validators.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ const scraperRequestSchema = Joi.object({
6464
// Array of steps to be executed by the scraper
6565
steps: Joi.array().items(
6666
Joi.object({
67-
// Step type - artık tüm adım türlerini destekleyen genel bir string değeri
68-
type: Joi.string(),
67+
// Step type - specific allowed types only
68+
type: Joi.string().valid(
69+
STEP_TYPES.NAVIGATE,
70+
STEP_TYPES.CLICK,
71+
STEP_TYPES.WAIT,
72+
STEP_TYPES.SET_VIEWPORT,
73+
STEP_TYPES.CHANGE,
74+
STEP_TYPES.WAIT_FOR_ELEMENT
75+
).required(),
6976

7077
// Generic value field, used differently based on step type
7178
value: Joi.string().allow(''),

routes.js

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ router.get("/health", controllerHealth);
267267
* type:
268268
* type: string
269269
* description: Type of browser action
270-
* enum: [navigate, click, wait, setViewport]
270+
* enum: [navigate, click, wait, setViewport, change, waitForElement]
271271
* example: "navigate"
272272
* url:
273273
* type: string
@@ -307,7 +307,8 @@ router.get("/health", controllerHealth);
307307
* example: "main"
308308
* value:
309309
* type: string
310-
* description: Generic value used by some step types
310+
* description: Value to set for input fields (for change action)
311+
* example: "search keyword"
311312
* offsetX:
312313
* type: number
313314
* description: X-coordinate offset for click operations
@@ -316,9 +317,66 @@ router.get("/health", controllerHealth);
316317
* type: number
317318
* description: Y-coordinate offset for click operations
318319
* example: 9
320+
* frame:
321+
* type: array
322+
* description: Frame indices for nested frames
323+
* items:
324+
* type: number
325+
* example: [0]
326+
* duration:
327+
* type: number
328+
* description: Duration of action in milliseconds
329+
* example: 50
330+
* deviceType:
331+
* type: string
332+
* description: Type of device simulated for interaction
333+
* example: "mouse"
334+
* button:
335+
* type: string
336+
* description: Mouse button used for click
337+
* example: "primary"
338+
* timeout:
339+
* type: number
340+
* description: Timeout duration for the step in milliseconds
341+
* example: 5000
342+
* operator:
343+
* type: string
344+
* description: Comparison operator for waitForElement
345+
* example: ">="
346+
* count:
347+
* type: number
348+
* description: Element count for waitForElement
349+
* example: 1
350+
* visible:
351+
* type: boolean
352+
* description: Whether element should be visible for waitForElement
353+
* example: true
354+
* attributes:
355+
* type: object
356+
* description: Attributes to check for waitForElement
357+
* example: {"attribute": "value"}
358+
* properties:
359+
* type: object
360+
* description: Properties to check for waitForElement
361+
* example: {}
319362
* assertedEvents:
320363
* type: array
321364
* description: Expected events after step execution
365+
* items:
366+
* type: object
367+
* properties:
368+
* type:
369+
* type: string
370+
* description: Type of event
371+
* example: "navigation"
372+
* url:
373+
* type: string
374+
* description: Expected URL after event
375+
* example: "https://www.amazon.com/dp/B00IJ0ALYS"
376+
* title:
377+
* type: string
378+
* description: Expected page title after event
379+
* example: "Product Page"
322380
* responses:
323381
* 200:
324382
* description: Scraping completed successfully

0 commit comments

Comments
 (0)