-
Notifications
You must be signed in to change notification settings - Fork 16
/
TS_03_VerifyCheckoutCartTests.java
91 lines (82 loc) · 3.41 KB
/
TS_03_VerifyCheckoutCartTests.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package tests;
import java.util.ArrayList;
import java.util.List;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import base.PlaywrightFactory;
import pages.HomePage;
import pages.ShoppingCartPage;
/**
* TestNG Test class - Checkout cart
*/
public class TS_03_VerifyCheckoutCartTests extends TestBase {
private ShoppingCartPage shoppingCartPage;
private List<String> productList = new ArrayList<>();
/**
* BeforeClass Method to create ExtentTest in Extent Report
*/
@BeforeClass
public void setupBeforeClass() {
extentTest = reporter.createTest("TS_03 Verify Cart and Checkout the Cart", "Verify Add Products to Cart");
}
/**
* Test the cart checkout functionality without login
*/
@Test(priority = 1)
public void checkoutCartWithoutLoginTest() {
testNode = extentTest.createNode("TC_01 Verify Cart Checkout Without Login");
testNode.assignCategory("TS_03_Open-Cart-Checkout-Cart");
homePage = new HomePage(page, testNode);
softAssert.assertEquals(homePage.getHomePageTitle(), HOME_PAGE_TITLE);
Assert.assertTrue(homePage.searchProduct("Macbook"));
String product = homePage.addProductToCart();
Assert.assertNotNull(product);
productList.add(product);
shoppingCartPage = homePage.navigateToShoppingCartPage();
Assert.assertTrue(shoppingCartPage.checkProductInCart(productList));
Assert.assertTrue(shoppingCartPage.checkoutCart(false));
productList.remove(product);
}
/**
* Test the cart checkout functionality with login and save the session state
*/
@Test(priority = 2)
public void checkoutCartWithLoginTest() {
testNode = extentTest.createNode("TC_01 Verify Checkout with With Login");
testNode.assignCategory("TS_03_Open-Cart-Checkout-Cart");
homePage = new HomePage(page, testNode);
softAssert.assertEquals(homePage.getHomePageTitle(), HOME_PAGE_TITLE);
loginPage = homePage.navigateToLoginPage();
Assert.assertTrue(loginPage.doLogin(testProperties.getProperty("username"),
testProperties.getProperty("password")));
PlaywrightFactory.saveSessionState(page, testProperties.getProperty("sessionState"));
testProperties.setProperty("useSessionState", "true");
Assert.assertTrue(homePage.searchProduct("Macbook"));
String product = homePage.addProductToCart();
productList.add(product);
Assert.assertNotNull(product);
shoppingCartPage = homePage.navigateToShoppingCartPage();
Assert.assertTrue(shoppingCartPage.checkProductInCart(productList));
Assert.assertTrue(shoppingCartPage.checkoutCart(true));
}
/**
* Test the cart checkout functionality with adding more product and using login
* state saved in previous Test
*/
@Test(priority = 3, dependsOnMethods = { "checkoutCartWithLoginTest" })
public void addMoreProductToCartAndCheckoutTest() {
testNode = extentTest.createNode("TC_01 Verify Add More Product to cart and checkout");
testNode.assignCategory("TS_03_Open-Cart-Checkout-Cart");
homePage = new HomePage(page, testNode);
softAssert.assertEquals(homePage.getHomePageTitle(), HOME_PAGE_TITLE);
Assert.assertTrue(homePage.searchProduct("Samsung"));
String product = homePage.addProductToCart();
productList.add(product);
Assert.assertNotNull(product);
shoppingCartPage = homePage.navigateToShoppingCartPage();
Assert.assertTrue(shoppingCartPage.checkProductInCart(productList));
Assert.assertTrue(shoppingCartPage.checkoutCart(true));
testProperties.setProperty("useSessionState", "false");
}
}