Skip to content

Commit 33a5ed7

Browse files
authored
Merge pull request #2 from volt-test/release/v0.9.2
Release/v0.9.2
2 parents 4e41d53 + 114122f commit 33a5ed7

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

docs/Examples/html_form_examples.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $scenario = $test->scenario('Login Form Test');
3232
// Get login page and extract CSRF token
3333
$scenario->step('Get Login Page')
3434
->get('https://example.com/login')
35-
->extractFromRegex('csrf_token', 'name="_token" value="(.+?)"')
35+
->extractFromHtml('csrf_token', 'input[name="_token"]', 'value')
3636
->validateStatus('page_load', 200);
3737

3838
// Submit login form
@@ -59,7 +59,7 @@ $scenario = $test->scenario('Registration Form');
5959
// Load registration page
6060
$scenario->step('Load Register Page')
6161
->get('https://example.com/register')
62-
->extractFromRegex('csrf_token', 'name="_token" value="(.+?)"')
62+
->extractFromHtml('csrf_token', 'input[name="_token"]', 'value')
6363
->validateStatus('page_load', 200);
6464

6565
// Submit registration with form data
@@ -94,13 +94,12 @@ $scenario = $test->scenario('Multi-Step Form');
9494
// Step 1: Personal Info
9595
$scenario->step('Personal Info')
9696
->get('https://example.com/form/step1')
97-
->extractFromRegex('form_token', 'name="form_token" value="(.+?)"')
97+
->extractFromHtml('form_token', 'input[name="_token"]', 'value')
9898
->validateStatus('step1_load', 200);
9999

100100
$scenario->step('Submit Step 1')
101-
->post('https://example.com/form/step1')
101+
->post('https://example.com/form/step1',''form_token=${form_token}&name=${name}&email=${email}'')
102102
->header('Content-Type', 'application/x-www-form-urlencoded')
103-
->setBody('form_token=${form_token}&name=${name}&email=${email}')
104103
->validateStatus('step1_success', 302)
105104
->extractFromCookie('session_id', 'session_id');
106105

@@ -111,9 +110,8 @@ $scenario->step('Address Info')
111110
->validateStatus('step2_load', 200);
112111

113112
$scenario->step('Submit Step 2')
114-
->post('https://example.com/form/step2')
113+
->post('https://example.com/form/step2', 'address=${address}&city=${city}&country=${country}')
115114
->header('Cookie', 'session_id=${session_id}')
116-
->setBody('address=${address}&city=${city}&country=${country}')
117115
->validateStatus('step2_success', 302);
118116

119117
// Run the test and get the result

docs/Step.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,35 @@ $scenario->get('https://api.example.com/profile')
101101
->header('Authorization', 'Bearer ${token}');
102102
```
103103

104+
### HTML Response
105+
Extract data from an HTML response:
106+
```php
107+
$scenario->get('https://example.com/login')
108+
->extractFromHtml('csrf', 'input[name="_token"]', 'value');
109+
```
110+
the above code will extract the value of the input field with the name `_token` and store it in the `csrf` variable.
111+
112+
You can also specify the form action URL to extract data from a specific form:
113+
```php
114+
$scenario->get('https://example.com/login')
115+
->extractFromHtml('csrf', 'form[action="http://localhost/login"] input[name="_token"]', 'value');
116+
```
117+
Here, the `csrf` variable will store the value of the input field with the name `_token` from the form with the action URL `http://localhost/login`.
118+
119+
```php
120+
$scenario->get('https://example.com/login')
121+
->extractFromHtml('csrf', '.login-form input[name='_csrf']', 'value');
122+
```
123+
Here, the `csrf` variable will store the value of the input field with the name `_csrf` from the form with the class `login-form`.
124+
125+
126+
```php
127+
$scenario->get('https://example.com/login')
128+
->extractFromHtml('csrf', 'div#test', 'data-test');
129+
```
130+
Here, the `csrf` variable will store the value of the data attribute `data-test` from the div with the id `test`.
131+
132+
104133
### Headers
105134
Extract data from response headers:
106135
```php

0 commit comments

Comments
 (0)