File tree Expand file tree Collapse file tree 6 files changed +110
-7
lines changed
src/test/java/io/github/mfaisalkhatri/api Expand file tree Collapse file tree 6 files changed +110
-7
lines changed Original file line number Diff line number Diff line change 12
12
13
13
<properties >
14
14
<project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
15
- <playwright-version >1.45.1 </playwright-version >
15
+ <playwright-version >1.47.0 </playwright-version >
16
16
<testng-version >7.10.2</testng-version >
17
17
<hamcrest-all-version >1.3</hamcrest-all-version >
18
18
<json-simple-version >1.1.1</json-simple-version >
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ public final class BookingDataBuilder {
14
14
private static final Faker FAKER = new Faker ();
15
15
16
16
public static BookingData getBookingData () {
17
- final SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd" );
18
17
return BookingData .builder ()
19
18
.firstname (FAKER .name ()
20
19
.firstName ())
@@ -24,11 +23,10 @@ public static BookingData getBookingData() {
24
23
.numberBetween (1 , 2000 ))
25
24
.depositpaid (true )
26
25
.bookingdates (BookingDates .builder ()
27
- .checkin (formatter .format (FAKER .date ()
28
- .past (20 , TimeUnit .DAYS )))
29
- .checkout (formatter .format (FAKER .date ()
30
- .future (5 , TimeUnit .DAYS )))
31
- .build ())
26
+ .checkin (FAKER .timeAndDate ()
27
+ .past (20 , TimeUnit .DAYS ,"yyyy-MM-dd" ))
28
+ .checkout (FAKER .timeAndDate ()
29
+ .future (5 , TimeUnit .DAYS , "yyyy-MM-dd" )).build ())
32
30
.additionalneeds ("Breakfast" )
33
31
.build ();
34
32
Original file line number Diff line number Diff line change
1
+ package io .github .mfaisalkhatri .api .restfulecommerce ;
2
+
3
+
4
+ import org .testng .annotations .Test ;
5
+
6
+ public class APITests extends BaseTest {
7
+
8
+ @ Test
9
+ public void testShouldCreateNewOrders () {
10
+ //request.post("/addOrder").body()
11
+ }
12
+
13
+
14
+ }
Original file line number Diff line number Diff line change
1
+ package io .github .mfaisalkhatri .api .restfulecommerce ;
2
+
3
+ import com .microsoft .playwright .APIRequest ;
4
+ import com .microsoft .playwright .APIRequestContext ;
5
+ import com .microsoft .playwright .Playwright ;
6
+ import org .testng .annotations .AfterClass ;
7
+ import org .testng .annotations .BeforeClass ;
8
+
9
+ import java .util .HashMap ;
10
+ import java .util .Map ;
11
+
12
+ public class BaseTest {
13
+
14
+ protected Playwright playwright ;
15
+ protected APIRequestContext request ;
16
+ private static final String BASE_URL = "http://localhost:3004" ;
17
+
18
+ @ BeforeClass
19
+ public void setup () {
20
+ createPlaywright ();
21
+ createAPIRequestContext ();
22
+ }
23
+
24
+ @ AfterClass
25
+ public void tearDown () {
26
+ disposeAPIRequestContext ();
27
+ closePlaywright ();
28
+
29
+ }
30
+
31
+ private void createPlaywright () {
32
+ playwright = Playwright .create ();
33
+ }
34
+
35
+ private void createAPIRequestContext () {
36
+ Map <String , String > headers = new HashMap <>();
37
+ headers .put ("Content-Type" , "application/json" );
38
+
39
+ request = playwright .request ().newContext (new APIRequest .NewContextOptions ()
40
+ .setBaseURL (BASE_URL )
41
+ .setExtraHTTPHeaders (headers ));
42
+ }
43
+
44
+
45
+ private void closePlaywright () {
46
+ if (playwright != null ) {
47
+ playwright .close ();
48
+ playwright = null ;
49
+ }
50
+ }
51
+
52
+ private void disposeAPIRequestContext () {
53
+ if (request != null ) {
54
+ request .dispose ();
55
+ request = null ;
56
+ }
57
+ }
58
+
59
+
60
+ }
Original file line number Diff line number Diff line change
1
+ package io .github .mfaisalkhatri .api .restfulecommerce .testdata ;
2
+
3
+
4
+ import com .google .gson .annotations .SerializedName ;
5
+ import lombok .Builder ;
6
+ import lombok .Getter ;
7
+
8
+ @ Getter
9
+ @ Builder
10
+ public class OrderData {
11
+ @ SerializedName ("user_id" )
12
+ private String userId ;
13
+ @ SerializedName ("product_id" )
14
+ private String productId ;
15
+ @ SerializedName ("product_name" )
16
+ private String productName ;
17
+ @ SerializedName ("product_amount" )
18
+ private int productAmount ;
19
+ private int qty ;
20
+ @ SerializedName ("tax_amt" )
21
+ private int taxAmt ;
22
+ @ SerializedName ("total_amt" )
23
+ private int totalAmt ;
24
+
25
+ }
Original file line number Diff line number Diff line change
1
+ package io .github .mfaisalkhatri .api .restfulecommerce .testdata ;
2
+
3
+ public class OrderDataBuilder {
4
+
5
+
6
+ }
You can’t perform that action at this time.
0 commit comments