Skip to content

Commit cc43f9b

Browse files
Update : [Implement Dependency Injection] (#3)
1 parent 1985ad4 commit cc43f9b

File tree

10 files changed

+235
-197
lines changed

10 files changed

+235
-197
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ JDK : 20
1414
| 4 | io.cucumber | cucumber-java | 7.14.0 |
1515
| 5 | io.cucumber | cucumber-junit | 7.14.0 |
1616
| 6 | org.junit.platform | junit-platform-console | 1.10.0 |
17+
| 7 | io.cucumber | cucumber-picocontainer | 7.14.0 |
1718

1819
### Test Information
1920

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656
<artifactId>junit-platform-console</artifactId>
5757
<version>1.10.0</version>
5858
</dependency>
59+
60+
<dependency>
61+
<groupId>io.cucumber</groupId>
62+
<artifactId>cucumber-picocontainer</artifactId>
63+
<version>7.14.0</version>
64+
<scope>test</scope>
65+
</dependency>
5966
</dependencies>
6067
<build>
6168
<plugins>

src/test/java/config/SetupDriver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import org.openqa.selenium.chrome.ChromeDriver;
66

77
public class SetupDriver {
8-
private final Config config;
8+
private Config config;
99
private WebDriver webDriver;
1010

11-
public SetupDriver() {
11+
public void startDriver() {
1212
config = new Config();
1313

1414
setChromeDriver();
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import org.junit.jupiter.api.Assertions;
66
import org.openqa.selenium.WebElement;
77

8-
public class AddToProductCart {
8+
public class AddProductToCart {
99
private final SetupDriver setupDriver;
1010

1111
private final ElementInventory elementInventory;
1212

13-
public AddToProductCart(SetupDriver setupDriver) {
13+
public AddProductToCart(SetupDriver setupDriver) {
1414
this.setupDriver = setupDriver;
1515

1616
this.elementInventory = new ElementInventory(this.setupDriver.getWebDriver());
@@ -45,8 +45,4 @@ public void cartNumberWillBePlusTwo() {
4545
WebElement shoppingCart = this.elementInventory.shoppingCart();
4646
Assertions.assertEquals("2", shoppingCart.getText());
4747
}
48-
49-
public void verifyFirstProductButton() {
50-
System.out.println("RUN ME TOO");
51-
}
5248
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package stepDef;
2+
3+
import io.cucumber.java.en.Then;
4+
import io.cucumber.java.en.When;
5+
import main.AddProductToCart;
6+
7+
public class AddProductToCartStepDef {
8+
private final Hook hook;
9+
private AddProductToCart addProductToCart;
10+
11+
public AddProductToCartStepDef(Hook hook) {
12+
this.hook = hook;
13+
this.addProductToCart = new AddProductToCart(this.hook.getSetUpDriver());
14+
}
15+
16+
@When("The user clicks the add to cart button")
17+
public void addToCartFirstProduct() {
18+
this.addProductToCart.addToCartFirstProduct();
19+
}
20+
21+
@Then("The text on the add to cart button should change to remove")
22+
public void verifyFirstProductButton() {
23+
this.addProductToCart.addToCartTextWillBeChangeToRemove();
24+
}
25+
26+
@Then("The number of items in the cart icon should be 1")
27+
public void cartNumberWillBePlusOne() {
28+
this.addProductToCart.cartNumberWillBePlusOne();
29+
}
30+
31+
@When("The user clicks the add to cart button for another product")
32+
public void userClickAddToCartOtherProductButton() {
33+
this.addProductToCart.userClickAddToCartOtherProductButton();
34+
}
35+
36+
@Then("The text on the add to cart button other product should change to remove")
37+
public void addToCartTextForOtherProductWillBeChangeToRemove() {
38+
this.addProductToCart.addToCartTextForOtherProductWillBeChangeToRemove();
39+
}
40+
41+
@Then("The number of items in the cart icon should be 2")
42+
public void cartNumberWillBePlusTwo() {
43+
this.addProductToCart.cartNumberWillBePlusTwo();
44+
}
45+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package stepDef;
2+
3+
import io.cucumber.java.en.Then;
4+
import io.cucumber.java.en.When;
5+
import main.Cart;
6+
7+
public class CartStepDef {
8+
private final Hook hook;
9+
private Cart cart;
10+
11+
public CartStepDef(Hook hook) {
12+
this.hook = hook;
13+
this.cart = new Cart(this.hook.getSetUpDriver());
14+
}
15+
16+
@Then("The user is on the cart page")
17+
public void userNavigateToCartPage() {
18+
this.cart.userNavigateToCartPage();
19+
}
20+
21+
@Then("The user should see at least {int} products in their cart")
22+
public void assertAtLeastXProductsInShoppingCart(int number) {
23+
this.cart.assertAtLeastXProductsInShoppingCart(number);
24+
}
25+
26+
@When("The user clicks the remove button for the first item")
27+
public void clickRemoveButtonForFirstItem() {
28+
this.cart.clickRemoveButtonForFirstItem();
29+
}
30+
31+
@Then("The shopping cart should be empty")
32+
public void assertShoppingCartIsEmpty() {
33+
this.cart.assertShoppingCartIsEmpty();
34+
}
35+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package stepDef;
2+
3+
import io.cucumber.java.en.Then;
4+
import main.Checkout;
5+
6+
public class CheckoutStepDef {
7+
private Hook hook;
8+
private Checkout checkout;
9+
10+
public CheckoutStepDef(Hook hook) {
11+
this.hook = hook;
12+
this.checkout = new Checkout(this.hook.getSetUpDriver());
13+
}
14+
15+
@Then("The user clicks the checkout button")
16+
public void clickCheckOutButton() {
17+
this.checkout.clickCheckOutButton();
18+
}
19+
20+
@Then("The user should be on the checkout page")
21+
public void userShouldBeOnCheckoutPage() {
22+
this.checkout.userShouldBeOnCheckoutPage();
23+
}
24+
25+
@Then("The user enters (.*) as the first name$")
26+
public void userEntersExampleAsFirstName(String firstName) {
27+
this.checkout.userEntersExampleAsFirstName(firstName);
28+
}
29+
30+
@Then("The user enters (.*) as the last name$")
31+
public void userEntersExampleLastNameAsLastName(String lastName) {
32+
this.checkout.userEntersExampleLastNameAsLastName(lastName);
33+
}
34+
35+
@Then("The user enters (.*) as the postal code$")
36+
public void userEntersPostalCode(int postalCode) {
37+
this.checkout.userEntersPostalCode(postalCode);
38+
}
39+
40+
@Then("The user clicks the continue button")
41+
public void userClicksContinueButton() {
42+
this.checkout.userClicksContinueButton();
43+
}
44+
45+
@Then("The user should be redirected to the checkout page step {string}")
46+
public void userShouldBeRedirectedToCheckoutPageStep(String stepNumber) {
47+
this.checkout.userShouldBeRedirectedToCheckoutPageStep(stepNumber);
48+
}
49+
50+
@Then("The user clicks the finish button")
51+
public void userClicksFinishButton() {
52+
this.checkout.userClicksFinishButton();
53+
}
54+
55+
@Then("The user should be redirected to the checkout complete page")
56+
public void userShouldBeRedirectedToCheckoutCompletePage() {
57+
this.checkout.userShouldBeRedirectedToCheckoutCompletePage();
58+
}
59+
60+
@Then("The user clicks the back home button")
61+
public void userClicksBackHomeButton() {
62+
this.checkout.userClicksBackHomeButton();
63+
}
64+
65+
@Then("The number of items in the cart icon should be empty")
66+
public void numberOfItemsInCartIconShouldBeEmpty() {
67+
this.checkout.numberOfItemsInCartIconShouldBeEmpty();
68+
}
69+
}

src/test/java/stepDef/Hook.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package stepDef;
2+
3+
import config.SetupDriver;
4+
import io.cucumber.java.After;
5+
import io.cucumber.java.Before;
6+
7+
public class Hook extends SetupDriver {
8+
@Before
9+
public void startHook() {
10+
startDriver();
11+
}
12+
13+
@After(order = 0)
14+
public void closeBrowser() {
15+
this.getWebDriver().close();
16+
}
17+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package stepDef;
2+
3+
import io.cucumber.java.en.And;
4+
import io.cucumber.java.en.Given;
5+
import io.cucumber.java.en.Then;
6+
import io.cucumber.java.en.When;
7+
import main.Login;
8+
9+
public class LoginStepDef {
10+
private final Hook hook;
11+
private Login login;
12+
13+
public LoginStepDef(Hook hook) {
14+
this.hook = hook;
15+
this.login = new Login(this.hook.getSetUpDriver());
16+
}
17+
18+
@Given("The user opens the web page or app")
19+
public void openApp() {
20+
this.hook.openDefaultApp();
21+
}
22+
23+
@When("The user enters a valid username")
24+
public void enterValidUserName() {
25+
this.login.enterValidUserName();
26+
}
27+
28+
@When("The user enters a invalid username")
29+
public void enterInValidUserName() {
30+
this.login.enterInValidUserName();
31+
}
32+
33+
@And("The user enters a valid password")
34+
public void enterValidPassword() {
35+
this.login.enterValidPassword();
36+
}
37+
38+
@And("The user enters a invalid password")
39+
public void enterInValidPassword() {
40+
this.login.enterInValidPassword();
41+
}
42+
43+
@And("The user clicks the login button")
44+
public void clickLoginButton() {
45+
this.login.clickLoginButton();
46+
}
47+
48+
@Then("The user should be logged in successfully")
49+
public void verifyUserLoggedIn() {
50+
this.login.verifyUserLoggedIn();
51+
}
52+
53+
@Then("The user should be see error message")
54+
public void verifyAlert() {
55+
this.login.verifyAlert();
56+
}
57+
}

0 commit comments

Comments
 (0)