-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomation-framework.code-workspace
More file actions
49 lines (49 loc) · 1.13 KB
/
Automation-framework.code-workspace
File metadata and controls
49 lines (49 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.bank.tests;
import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import org.testng.Assert;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
public class AuthTests {
@Test
public void BNK_API_001_authTokenGeneration() {
RestAssured.baseURI = TestConfig.baseUrl();
String body = """
{
"username": "%s",
"password": "%s"
}
""".formatted(TestConfig.username(), TestConfig.password());
String response =
given()
.contentType("application/json")
.body(body)
.when()
.post("/auth/login")
.then()
.statusCode(200)
.extract()
.asString();
JsonPath jp = new JsonPath(response);
String token = jp.getString("token");
Assert.assertNotNull(token, "Token should not be null");
Assert.assertTrue(token.length() > 10, "Token looks too short");
}
@Test
public void BNK_API_002_authWithInvalidCredentials() {
RestAssured.baseURI = TestConfig.baseUrl();
String body = """
{
"username": "%s",
"password": "%s"
}
""".formatted(TestConfig.username(), "wrongPassword!");
given()
.contentType("application/json")
.body(body)
.when()
.post("/auth/login")
}
}
.then()
.statusCode(401); // sometimes 403 depending