Skip to content

Commit 89d7a58

Browse files
authored
docs: refresh the complete SHAFT user guide (#915)
Refresh guide content, property references, examples, and documentation quality checks.
1 parent 19308ae commit 89d7a58

31 files changed

Lines changed: 301 additions & 377 deletions

docs/features/test-automation-pillars.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,13 @@ attachFullLog=true
108108
Use explicit waits for application states that the browser cannot infer:
109109

110110
```java title="ReliableStateWait.java"
111+
import org.openqa.selenium.By;
112+
import org.openqa.selenium.support.ui.ExpectedConditions;
113+
111114
driver.browser().navigateToURL("https://example.test/orders");
112115
driver.element().click("Refresh orders");
113-
driver.element().waitUntilElementTextToBe(By.id("sync-status"), "Complete");
116+
driver.element().waitUntil(ExpectedConditions.textToBePresentInElementLocated(
117+
By.id("sync-status"), "Complete"));
114118
driver.assertThat(By.id("order-count")).text().isEqualTo("25");
115119
```
116120

docs/integrations/visual.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,24 @@ and image-file operations continue to work.
130130
| `STRICT_EYES` | High-sensitivity comparison with minor tolerance | UI components |
131131
| `CONTENT_EYES` | Compares content while ignoring minor rendering differences | Text-heavy pages |
132132
| `LAYOUT_EYES` | Compares layout structure, ignores content changes | Page layout regression |
133-
| `OPENCV` | Uses OpenCV for flexible image matching | Complex scenarios, partial matching |
133+
| `EXACT_OPENCV` | Uses OpenCV for image comparison | OpenCV-based visual checks |
134134

135135
```java title="VisualTesting.java"
136-
import com.shaft.enums.internal.VisualValidationEngine;
136+
import com.shaft.validation.ValidationEnums;
137137

138138
// Assert element matches a reference image (stores baseline on first run)
139139
driver.element().assertThat(By.id("logo")).matchesReferenceImage();
140140

141141
// Layout comparison — ignores content, checks structure
142142
driver.element().assertThat(By.id("productCard"))
143-
.matchesReferenceImage(VisualValidationEngine.LAYOUT_EYES);
143+
.matchesReferenceImage(ValidationEnums.VisualValidationEngine.LAYOUT_EYES);
144144
```
145145

146146
When an intentional UI change is made, delete the relevant baseline image from `src/test/resources/DynamicObjectRepository/` and run the test once to regenerate it. Run visual tests in a consistent environment (same OS, browser version, screen resolution) to avoid false positives, and avoid mixing headless and headed baselines.
147147

148148
## matchesScreenshot()
149149

150-
`matchesScreenshot()` is a lighter-weight, OpenCV-only pixel-diff assertion built into `shaft-engine` (no `shaft-visual` dependency required). Like every other SHAFT assertion it runs immediately — no `perform()` is needed. Pass a `VisualComparisonOptions` object to tune the diff budget and masks, mirroring Playwright's `toHaveScreenshot()` options:
150+
`matchesScreenshot()` is an OpenCV-only pixel-diff assertion built into `shaft-engine`, so it does not require `shaft-visual`. It runs when you call it. Pass a `VisualComparisonOptions` object to tune the diff budget and masks, mirroring Playwright's `toHaveScreenshot()` options:
151151

152152
```java title="ScreenshotBaseline.java"
153153
driver.element().assertThat(By.id("logo"))

docs/reference/actions/API/API_Authentication.md

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
id: API_Authentication
33
title: API Authentication
44
sidebar_label: API Authentication
5-
description: "Configure BASIC, DIGEST, OAuth2, API Key, cookie, and session authentication for API tests in SHAFT Engine using setAuthentication and addHeader."
6-
keywords: [SHAFT, API authentication, basic auth, digest auth, OAuth2, bearer token, API key, cookie auth, REST API]
5+
description: "Configure BASIC, FORM, OAuth2, API Key, cookie, and session authentication for API tests in SHAFT Engine using setAuthentication and addHeader."
6+
keywords: [SHAFT, API authentication, basic auth, form auth, OAuth2, bearer token, API key, cookie auth, REST API]
77
tags: [api, authentication, security, rest-assured]
88
---
99

10-
SHAFT Engine supports multiple API authentication strategies through `setAuthentication()` and the fluent request builder. All authentication methods work with the existing `SHAFT.API` request-building API.
10+
Use `setAuthentication()` for BASIC or FORM authentication. For bearer tokens, API keys, and cookies, add the relevant header before sending the request.
1111

1212
---
1313

@@ -17,25 +17,14 @@ Pass a username and password using `AuthenticationType.BASIC`:
1717

1818
```java title="APIAuthentication.java"
1919
import com.shaft.driver.SHAFT;
20-
import com.shaft.api.RestActions.AuthenticationType;
20+
import com.shaft.api.RequestBuilder.AuthenticationType;
2121

2222
SHAFT.API api = new SHAFT.API("https://api.example.com");
2323

2424
api.get("/secure/data")
2525
.setAuthentication("username", "password", AuthenticationType.BASIC)
26-
.setTargetStatusCode(200);
27-
```
28-
29-
---
30-
31-
## DIGEST Authentication
32-
33-
Use `AuthenticationType.DIGEST` for digest-challenge protected endpoints:
34-
35-
```java title="APIAuthentication.java"
36-
api.get("/digest-auth/data")
37-
.setAuthentication("user", "pass", AuthenticationType.DIGEST)
38-
.setTargetStatusCode(200);
26+
.setTargetStatusCode(200)
27+
;
3928
```
4029

4130
---
@@ -47,7 +36,8 @@ Submit credentials as form parameters using `AuthenticationType.FORM`:
4736
```java title="APIAuthentication.java"
4837
api.post("/login")
4938
.setAuthentication("user@example.com", "password123", AuthenticationType.FORM)
50-
.setTargetStatusCode(200);
39+
.setTargetStatusCode(200)
40+
;
5141
```
5242

5343
---
@@ -59,7 +49,8 @@ Add the `Authorization` header with a `Bearer` token prefix:
5949
```java title="APIAuthentication.java"
6050
api.get("/oauth/resource")
6151
.addHeader("Authorization", "Bearer your-oauth-token")
62-
.setTargetStatusCode(200);
52+
.setTargetStatusCode(200)
53+
;
6354
```
6455

6556
---
@@ -71,15 +62,17 @@ api.get("/oauth/resource")
7162
```java title="APIAuthentication.java"
7263
api.get("/data")
7364
.addHeader("X-API-Key", "your-api-key")
74-
.setTargetStatusCode(200);
65+
.setTargetStatusCode(200)
66+
;
7567
```
7668

7769
### API Key in Query Parameter
7870

7971
```java title="APIAuthentication.java"
8072
api.get("/data")
81-
.addUrlParameter("api_key", "your-api-key")
82-
.setTargetStatusCode(200);
73+
.setUrlArguments("api_key=your-api-key")
74+
.setTargetStatusCode(200)
75+
;
8376
```
8477

8578
---
@@ -91,26 +84,22 @@ Pass a session cookie using `addHeader`:
9184
```java title="APIAuthentication.java"
9285
api.get("/profile")
9386
.addHeader("Cookie", "session_id=abc123xyz; token=your-session-token")
94-
.setTargetStatusCode(200);
87+
.setTargetStatusCode(200)
88+
;
9589
```
9690

9791
---
9892

99-
## Persistent Session Authentication
93+
## Persistent headers and cookies
10094

101-
When `setAuthentication()` is called, the credentials are saved for all subsequent requests in the same `SHAFT.API` session:
95+
Use `addHeader()` or `addCookie()` on `SHAFT.API` when a token or cookie should be sent with later requests:
10296

10397
```java title="APIAuthentication.java"
10498
SHAFT.API api = new SHAFT.API("https://api.example.com");
10599

106-
// Authenticate once — credentials reused for all subsequent requests
107-
api.get("/login")
108-
.setAuthentication("user", "password", AuthenticationType.BASIC);
109-
110-
// These requests automatically include the authentication credentials
100+
api.addHeader("Authorization", "Bearer your-oauth-token");
101+
api.addCookie("session_id", "your-session-id");
111102
api.get("/users").setTargetStatusCode(200);
112-
api.get("/orders").setTargetStatusCode(200);
113-
api.get("/profile").setTargetStatusCode(200);
114103
```
115104

116105
---
@@ -119,7 +108,7 @@ api.get("/profile").setTargetStatusCode(200);
119108

120109
```java title="APIAuthTest.java"
121110
import com.shaft.driver.SHAFT;
122-
import com.shaft.api.RestActions.AuthenticationType;
111+
import com.shaft.api.RequestBuilder.AuthenticationType;
123112
import org.testng.annotations.Test;
124113

125114
public class APIAuthTest {
@@ -129,10 +118,11 @@ public class APIAuthTest {
129118
SHAFT.API api = new SHAFT.API("https://httpbin.org");
130119
api.get("/basic-auth/user/pass")
131120
.setAuthentication("user", "pass", AuthenticationType.BASIC)
132-
.setTargetStatusCode(200);
121+
.setTargetStatusCode(200)
122+
;
133123

134124
api.assertThatResponse()
135-
.extractedJsonValue("authenticated")
125+
.extractedJsonValue("$.authenticated")
136126
.isEqualTo("true");
137127
}
138128

@@ -141,7 +131,8 @@ public class APIAuthTest {
141131
SHAFT.API api = new SHAFT.API("https://api.example.com");
142132
api.get("/protected")
143133
.addHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
144-
.setTargetStatusCode(200);
134+
.setTargetStatusCode(200)
135+
;
145136
}
146137
}
147138
```

docs/reference/actions/API/GraphQL_Testing.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords: [SHAFT, GraphQL, API testing, GraphQL query, variables, fragments, mut
77
tags: [api, graphql, rest-assured]
88
---
99

10-
SHAFT Engine provides first-class GraphQL support through `SHAFT.API.sendGraphQlRequest()`. It returns the normal request builder, so **queries**, **mutations**, variables, fragments, authentication headers, status checks, and response assertions all use the same fluent API as REST requests.
10+
Use `SHAFT.API.sendGraphQlRequest()` for GraphQL queries and mutations. It returns the normal request builder, so variables, fragments, headers, status checks, and response assertions use the same fluent API as REST requests.
1111

1212
---
1313

@@ -26,7 +26,7 @@ api.sendGraphQlRequest(
2626
);
2727

2828
// Assert response content
29-
api.assertThatResponse().extractedJsonValue("data.users").isNotNull();
29+
api.assertThatResponse().extractedJsonValue("$.data.users").isNotNull();
3030
```
3131

3232
---
@@ -104,7 +104,7 @@ public class GraphQLTest {
104104

105105
api.sendGraphQlRequest("/graphql", "{ users { id name email } }");
106106

107-
api.assertThatResponse().extractedJsonValue("data.users").isNotNull();
107+
api.assertThatResponse().extractedJsonValue("$.data.users").isNotNull();
108108
}
109109

110110
@Test
@@ -115,7 +115,7 @@ public class GraphQLTest {
115115

116116
api.sendGraphQlRequest("/graphql", query, variables);
117117

118-
api.assertThatResponse().extractedJsonValue("data.user.email").isNotNull();
118+
api.assertThatResponse().extractedJsonValue("$.data.user.email").isNotNull();
119119
}
120120

121121
@Test
@@ -127,7 +127,7 @@ public class GraphQLTest {
127127

128128
api.sendGraphQlRequest("/graphql", mutation, variables);
129129

130-
api.assertThatResponse().extractedJsonValue("data.createUser.id").isNotNull();
130+
api.assertThatResponse().extractedJsonValue("$.data.createUser.id").isNotNull();
131131
}
132132
}
133133
```
@@ -146,10 +146,11 @@ SHAFT.API api = new SHAFT.API("https://api.example.com");
146146
api.post("/graphql")
147147
.setRequestBody("{\"query\": \"{ users { id name } }\"}")
148148
.addHeader("Content-Type", "application/json")
149-
.setTargetStatusCode(200);
149+
.setTargetStatusCode(200)
150+
;
150151

151152
api.assertThatResponse()
152-
.extractedJsonValue("data.users[0].name")
153+
.extractedJsonValue("$.data.users[0].name")
153154
.isEqualTo("John Doe");
154155
```
155156

0 commit comments

Comments
 (0)