-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: add scenarios to check cart badge and content #2
base: action-classes-exercise
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||
package serenityswag.inventory; | ||||||
|
||||||
import net.serenitybdd.core.pages.WebElementFacade; | ||||||
import net.serenitybdd.core.steps.UIInteractionSteps; | ||||||
import net.thucydides.core.annotations.Step; | ||||||
|
||||||
import java.util.List; | ||||||
|
||||||
public class AddProductsActions extends UIInteractionSteps { | ||||||
|
||||||
ProductList productList; | ||||||
@Step("Add Products'") | ||||||
public Integer forAllAvailableItems() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. returning the number of items added feels not good...
Suggested change
and later assert "visibleItems.size equals cartBadgeNumber" |
||||||
List<WebElementFacade> itemsAdded = productList.availableItems(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
name could be better i think. You are not returning the items you can buy but the button to click |
||||||
itemsAdded.forEach(WebElementFacade::click); | ||||||
return itemsAdded.size(); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package serenityswag.inventory; | ||
|
||
import net.serenitybdd.core.pages.PageObject; | ||
import net.serenitybdd.core.pages.WebElementFacade; | ||
import net.serenitybdd.core.pages.WebElementState; | ||
import net.serenitybdd.core.pages.WithLocator; | ||
|
||
public class CartDetails extends PageObject { | ||
public String productName() { | ||
return $(".inventory_details_name").getText(); | ||
} | ||
|
||
public WebElementFacade cartLink() { | ||
return $(".shopping_cart_link"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,4 +6,8 @@ public class InventoryPage extends PageObject { | |||||
public String getHeading() { | ||||||
return $(".title").getText(); | ||||||
} | ||||||
|
||||||
public String getShoppingCartBadge() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
i find the name not great, you are returning text, not a shoppingCartBadge |
||||||
return $(".shopping_cart_badge").getText(); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package serenityswag.inventory; | ||
|
||
import net.serenitybdd.core.steps.UIInteractionSteps; | ||
import net.thucydides.core.annotations.Step; | ||
|
||
public class ViewCartDetailsActions extends UIInteractionSteps { | ||
|
||
CartDetails cartDetails; | ||
|
||
@Step("View cart details for added products'") | ||
public void openCart() { | ||
$(cartDetails.cartLink()).click(); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,15 +1,57 @@ | ||||||
package serenityswag.inventory; | ||||||
|
||||||
import net.serenitybdd.core.Serenity; | ||||||
import net.serenitybdd.junit.runners.SerenityRunner; | ||||||
import net.thucydides.core.annotations.Managed; | ||||||
import net.thucydides.core.annotations.Steps; | ||||||
import org.junit.Assert; | ||||||
import org.junit.Before; | ||||||
import org.junit.Test; | ||||||
import org.junit.runner.RunWith; | ||||||
import org.openqa.selenium.WebDriver; | ||||||
import serenityswag.authentication.LoginActions; | ||||||
|
||||||
import java.util.List; | ||||||
|
||||||
import static org.assertj.core.api.Assertions.assertThat; | ||||||
import static serenityswag.authentication.User.STANDARD_USER; | ||||||
|
||||||
@RunWith(SerenityRunner.class) | ||||||
public class WhenAddingAnItemToTheCart { | ||||||
|
||||||
@Managed(driver = "firefox") | ||||||
WebDriver driver; | ||||||
|
||||||
@Steps | ||||||
LoginActions login; | ||||||
@Steps | ||||||
AddProductsActions addProducts; | ||||||
@Steps | ||||||
ProductList productList; | ||||||
@Steps | ||||||
ViewCartDetailsActions cartDetailsActions; | ||||||
List<String> productsAdded; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
InventoryPage inventoryPage; | ||||||
|
||||||
@Before | ||||||
public void login() { | ||||||
login.as(STANDARD_USER); | ||||||
|
||||||
} | ||||||
@Test | ||||||
public void theCorrectItemCountShouldBeShown() { | ||||||
Integer numberOfItemsAdded = addProducts.forAllAvailableItems(); | ||||||
Serenity.reportThat("The badge in shopping cart logo increases correctly according with items added", | ||||||
() -> assertThat(inventoryPage.getShoppingCartBadge()).isEqualTo(numberOfItemsAdded.toString())); | ||||||
} | ||||||
|
||||||
@Test | ||||||
public void allTheItemsShouldAppearInTheCart() { | ||||||
|
||||||
productsAdded = productList.titles(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
addProducts.forAllAvailableItems(); | ||||||
cartDetailsActions.openCart(); | ||||||
List<String> productsCart = productList.titles(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
Serenity.reportThat("The products added are displayed in the cart", | ||||||
() -> Assert.assertEquals(productsCart, productsAdded)); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you usually use the primitive version