Skip to content

Commit 41bf625

Browse files
authored
Merge pull request #2 from patrickduong/myda_13May_2025_Add_more_test_cases
Myda 13 may 2025 add more test cases
2 parents 8f512f2 + 5f3c9e6 commit 41bf625

File tree

10 files changed

+161
-34
lines changed

10 files changed

+161
-34
lines changed

.github/workflows/workflow.yml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
name: CI
2-
on:
3-
push:
4-
branches: [main]
5-
pull_request:
6-
branches: [main]
7-
jobs:
8-
build:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v3
12-
- name: Set up JDK 15
13-
uses: actions/setup-java@v3
14-
with:
15-
java-version: 15
16-
distribution: 'adopt'
17-
- uses: gradle/gradle-build-action@v2
18-
with:
19-
arguments: build --scan
20-
- name: Archive test report
21-
uses: actions/upload-artifact@v3
22-
with:
23-
name: Test report
24-
path: build/reports/tests/test
1+
#name: CI
2+
#on:
3+
# push:
4+
# branches: [main]
5+
# pull_request:
6+
# branches: [main]
7+
#jobs:
8+
# build:
9+
# runs-on: ubuntu-latest
10+
# steps:
11+
# - uses: actions/checkout@v4
12+
# - name: Set up JDK 15
13+
# uses: actions/setup-java@v4
14+
# with:
15+
# java-version: 15
16+
# distribution: 'adopt'
17+
# - uses: gradle/gradle-build-action@v2
18+
# with:
19+
# arguments: build --scan
20+
# - name: Archive test report
21+
# uses: actions/upload-artifact@v4
22+
# with:
23+
# name: Test report
24+
# path: build/reports/tests/test

src/test/java/pages/CartPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public class CartPage extends BasePage {
1111

12-
public CartPage(final WebDriver driver) {
12+
public CartPage(WebDriver driver) {
1313
super(driver);
1414
}
1515

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package pages;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebDriver;
5+
6+
import static constraints.TestConstraints.TEST_URL;
7+
8+
public class CheckoutStepOnePage extends BasePage {
9+
public CheckoutStepOnePage(WebDriver driver) {
10+
super(driver);
11+
12+
}
13+
14+
private final By firstNameInput = By.id("first-name");
15+
private final By lastNameInput = By.id("last-name");
16+
private final By postalCodeInput = By.id("postal-code");
17+
private final By continueButton = By.id("continue");
18+
private final By cancelButton = By.id("cancel");
19+
20+
21+
/**
22+
* Fill in first name, last name, and ZIP/postal code.
23+
*/
24+
public void fillCustomerInfo(String firstName, String lastName, String zipCode) {
25+
driver.findElement(firstNameInput).clear();
26+
driver.findElement(firstNameInput).sendKeys(firstName);
27+
28+
driver.findElement(lastNameInput).clear();
29+
driver.findElement(lastNameInput).sendKeys(lastName);
30+
31+
driver.findElement(postalCodeInput).clear();
32+
driver.findElement(postalCodeInput).sendKeys(zipCode);
33+
}
34+
35+
/**
36+
* Click “Continue” and verify navigation to step two.
37+
*/
38+
public void continueCheckout() {
39+
driver.findElement(continueButton).click();
40+
String url = driver.getCurrentUrl();
41+
if (!url.equals(TEST_URL + "checkout-step-two.html")) {
42+
throw new AssertionError(
43+
"Expected to navigate to checkout-step-two.html but was: " + url
44+
);
45+
}
46+
}
47+
48+
/**
49+
* Click “Cancel” and verify navigation back to cart.
50+
*/
51+
52+
public void cancelCheckout() {
53+
driver.findElement(cancelButton).click();
54+
String url = driver.getCurrentUrl();
55+
if (!url.equals(TEST_URL + "cart.html")) {
56+
throw new AssertionError(
57+
"Expected to navigate to cart.html but was: " + url
58+
);
59+
}
60+
}
61+
62+
}

src/test/java/pages/InventoryPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public int getCartBadgeCount() {
5757
}
5858

5959

60-
public InventoryPage(final WebDriver driver) {
60+
public InventoryPage(WebDriver driver) {
6161
super(driver);
6262
}
6363

src/test/java/pages/LoginPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class LoginPage extends BasePage {
1515
@FindBy(id = "login-button")
1616
private WebElement loginButton;
1717

18-
public LoginPage(final WebDriver driver) {
18+
public LoginPage(WebDriver driver) {
1919
super(driver);
2020
}
2121

src/test/java/pages/MenuPopUP.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class MenuPopUP extends BasePage {
1616
@FindBy(id = "logout_sidebar_link")
1717
private WebElement logoutLink;
1818

19-
public MenuPopUP(final WebDriver driver) {
19+
public MenuPopUP(WebDriver driver) {
2020
super(driver);
2121
}
2222

src/test/java/steps/SauceDemoSteps.java

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import io.cucumber.java.en.When;
99
import org.openqa.selenium.By;
1010
import org.openqa.selenium.support.PageFactory;
11-
import pages.CartPage;
12-
import pages.InventoryPage;
13-
import pages.LoginPage;
14-
import pages.MenuPopUP;
11+
import pages.*;
1512

1613
import java.util.List;
1714
import java.util.Map;
@@ -24,12 +21,15 @@ public class SauceDemoSteps {
2421
private final MenuPopUP menuPopUP;
2522
private final CartPage sauceDemoCartPage;
2623

24+
private final CheckoutStepOnePage sauceDemoCheckoutStepOncePage;
25+
2726
public SauceDemoSteps() {
2827

2928
sauceDemoLoginPage = PageFactory.initElements(driver, LoginPage.class);
3029
sauceDemoInventoryPage = PageFactory.initElements(driver, InventoryPage.class);
3130
menuPopUP = PageFactory.initElements(driver, MenuPopUP.class);
32-
sauceDemoCartPage = PageFactory.initElements(driver,CartPage.class);
31+
sauceDemoCartPage = PageFactory.initElements(driver, CartPage.class);
32+
sauceDemoCheckoutStepOncePage = PageFactory.initElements(driver, CheckoutStepOnePage.class);
3333
}
3434

3535
@Given("^I login with \"([^\"]*)\"$")
@@ -77,6 +77,50 @@ public void i_logout_the_web() {
7777
menuPopUP.logout();
7878
}
7979

80+
81+
@And("^I proceed to checkout")
82+
public void i_proceed_checkout() {
83+
driver.findElement(By.cssSelector("[data-test='checkout']")).click();
84+
}
85+
86+
87+
@When("I fill checkout form with first name {string}, last name {string}, zip code {string}")
88+
public void i_fill_checkout_form(String first, String last, String zip) {
89+
sauceDemoCheckoutStepOncePage.fillCustomerInfo(first, last, zip);
90+
}
91+
92+
@And("I {string} the checkout process")
93+
public void i_choose_action(String action) {
94+
if (action.equalsIgnoreCase("continue")) {
95+
sauceDemoCheckoutStepOncePage.continueCheckout();
96+
} else if (action.equalsIgnoreCase("cancel")) {
97+
sauceDemoCheckoutStepOncePage.cancelCheckout();
98+
} else {
99+
throw new IllegalArgumentException("Unknown action: " + action);
100+
}
101+
driver.quit();
102+
}
103+
104+
@Given("I am on the checkout step one page")
105+
public void i_am_on_checkout_step_one() {
106+
107+
}
108+
109+
@Given("I am on the checkout step two page")
110+
public void i_am_on_checkout_step_two() {
111+
112+
}
113+
114+
@Given("I am on the inventory page")
115+
public void i_am_on_inventory() {
116+
117+
}
118+
119+
@Given("I am on the cart page")
120+
public void i_am_on_cart() {
121+
122+
}
123+
80124
@When("I view the cart")
81125
public void i_view_the_Cart() {
82126
driver.findElement(By.cssSelector("span[data-test='shopping-cart-badge']")).click();

src/test/resources/Features/saucedemo_login.feature renamed to src/test/resources/Features/1_saucedemo_login.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ Feature: UI - SauceDemoLogin Test
33

44
Scenario Outline: User can login successfully with an account to see the PRODUCTS page then logout successfully to see the Login page
55
Given I login with "<username>"
6+
Then I am on the inventory page
67
Then The Product page display success with <product_item>
7-
When I logout the web
8+
And I logout the web
89

910
Examples:
1011
| username | product_item |
File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@ui @sauceDemoCartCheckout
2+
Feature: UI - SauceDemoCartCheckout Test
3+
4+
Scenario Outline: User can add any product for proceed to checkout step One and step Two
5+
Given I login with "<username>"
6+
When I add the following products to the cart:
7+
| name | price |
8+
| Sauce Labs Backpack | $29.99 |
9+
| Sauce Labs Bike Light | $9.99 |
10+
Then I view the cart
11+
And I proceed to checkout
12+
Then the cart badge should show 2
13+
When I fill checkout form with first name "Jane", last name "Smith", zip code "54321"
14+
And I "continue" the checkout process
15+
16+
Examples:
17+
| username |
18+
| standard_user |
19+
20+
# not stable for checking - need handle return page objects between cancel and continue

0 commit comments

Comments
 (0)