Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 15
uses: actions/setup-java@v3
with:
java-version: 15
distribution: 'adopt'
- uses: gradle/gradle-build-action@v2
with:
arguments: build --scan
- name: Archive test report
uses: actions/upload-artifact@v3
with:
name: Test report
path: build/reports/tests/test
#name: CI
#on:
# push:
# branches: [main]
# pull_request:
# branches: [main]
#jobs:
# build:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - name: Set up JDK 15
# uses: actions/setup-java@v4
# with:
# java-version: 15
# distribution: 'adopt'
# - uses: gradle/gradle-build-action@v2
# with:
# arguments: build --scan
# - name: Archive test report
# uses: actions/upload-artifact@v4
# with:
# name: Test report
# path: build/reports/tests/test
2 changes: 1 addition & 1 deletion src/test/java/pages/CartPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class CartPage extends BasePage {

public CartPage(final WebDriver driver) {
public CartPage(WebDriver driver) {
super(driver);
}

Expand Down
62 changes: 62 additions & 0 deletions src/test/java/pages/CheckoutStepOnePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import static constraints.TestConstraints.TEST_URL;

public class CheckoutStepOnePage extends BasePage {
public CheckoutStepOnePage(WebDriver driver) {
super(driver);

}

private final By firstNameInput = By.id("first-name");
private final By lastNameInput = By.id("last-name");
private final By postalCodeInput = By.id("postal-code");
private final By continueButton = By.id("continue");
private final By cancelButton = By.id("cancel");


/**
* Fill in first name, last name, and ZIP/postal code.
*/
public void fillCustomerInfo(String firstName, String lastName, String zipCode) {
driver.findElement(firstNameInput).clear();
driver.findElement(firstNameInput).sendKeys(firstName);

driver.findElement(lastNameInput).clear();
driver.findElement(lastNameInput).sendKeys(lastName);

driver.findElement(postalCodeInput).clear();
driver.findElement(postalCodeInput).sendKeys(zipCode);
}

/**
* Click “Continue” and verify navigation to step two.
*/
public void continueCheckout() {
driver.findElement(continueButton).click();
String url = driver.getCurrentUrl();
if (!url.equals(TEST_URL + "checkout-step-two.html")) {
throw new AssertionError(
"Expected to navigate to checkout-step-two.html but was: " + url
);
}
}

/**
* Click “Cancel” and verify navigation back to cart.
*/

public void cancelCheckout() {
driver.findElement(cancelButton).click();
String url = driver.getCurrentUrl();
if (!url.equals(TEST_URL + "cart.html")) {
throw new AssertionError(
"Expected to navigate to cart.html but was: " + url
);
}
}

}
2 changes: 1 addition & 1 deletion src/test/java/pages/InventoryPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public int getCartBadgeCount() {
}


public InventoryPage(final WebDriver driver) {
public InventoryPage(WebDriver driver) {
super(driver);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/pages/LoginPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class LoginPage extends BasePage {
@FindBy(id = "login-button")
private WebElement loginButton;

public LoginPage(final WebDriver driver) {
public LoginPage(WebDriver driver) {
super(driver);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/pages/MenuPopUP.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MenuPopUP extends BasePage {
@FindBy(id = "logout_sidebar_link")
private WebElement logoutLink;

public MenuPopUP(final WebDriver driver) {
public MenuPopUP(WebDriver driver) {
super(driver);
}

Expand Down
54 changes: 49 additions & 5 deletions src/test/java/steps/SauceDemoSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import io.cucumber.java.en.When;
import org.openqa.selenium.By;
import org.openqa.selenium.support.PageFactory;
import pages.CartPage;
import pages.InventoryPage;
import pages.LoginPage;
import pages.MenuPopUP;
import pages.*;

import java.util.List;
import java.util.Map;
Expand All @@ -24,12 +21,15 @@ public class SauceDemoSteps {
private final MenuPopUP menuPopUP;
private final CartPage sauceDemoCartPage;

private final CheckoutStepOnePage sauceDemoCheckoutStepOncePage;

public SauceDemoSteps() {

sauceDemoLoginPage = PageFactory.initElements(driver, LoginPage.class);
sauceDemoInventoryPage = PageFactory.initElements(driver, InventoryPage.class);
menuPopUP = PageFactory.initElements(driver, MenuPopUP.class);
sauceDemoCartPage = PageFactory.initElements(driver,CartPage.class);
sauceDemoCartPage = PageFactory.initElements(driver, CartPage.class);
sauceDemoCheckoutStepOncePage = PageFactory.initElements(driver, CheckoutStepOnePage.class);
}

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


@And("^I proceed to checkout")
public void i_proceed_checkout() {
driver.findElement(By.cssSelector("[data-test='checkout']")).click();
}


@When("I fill checkout form with first name {string}, last name {string}, zip code {string}")
public void i_fill_checkout_form(String first, String last, String zip) {
sauceDemoCheckoutStepOncePage.fillCustomerInfo(first, last, zip);
}

@And("I {string} the checkout process")
public void i_choose_action(String action) {
if (action.equalsIgnoreCase("continue")) {
sauceDemoCheckoutStepOncePage.continueCheckout();
} else if (action.equalsIgnoreCase("cancel")) {
sauceDemoCheckoutStepOncePage.cancelCheckout();
} else {
throw new IllegalArgumentException("Unknown action: " + action);
}
driver.quit();
}

@Given("I am on the checkout step one page")
public void i_am_on_checkout_step_one() {

}

@Given("I am on the checkout step two page")
public void i_am_on_checkout_step_two() {

}

@Given("I am on the inventory page")
public void i_am_on_inventory() {

}

@Given("I am on the cart page")
public void i_am_on_cart() {

}

@When("I view the cart")
public void i_view_the_Cart() {
driver.findElement(By.cssSelector("span[data-test='shopping-cart-badge']")).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ Feature: UI - SauceDemoLogin Test

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

Examples:
| username | product_item |
Expand Down
20 changes: 20 additions & 0 deletions src/test/resources/Features/3_saucedemo_cart_checkout.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@ui @sauceDemoCartCheckout
Feature: UI - SauceDemoCartCheckout Test

Scenario Outline: User can add any product for proceed to checkout step One and step Two
Given I login with "<username>"
When I add the following products to the cart:
| name | price |
| Sauce Labs Backpack | $29.99 |
| Sauce Labs Bike Light | $9.99 |
Then I view the cart
And I proceed to checkout
Then the cart badge should show 2
When I fill checkout form with first name "Jane", last name "Smith", zip code "54321"
And I "continue" the checkout process

Examples:
| username |
| standard_user |

# not stable for checking - need handle return page objects between cancel and continue