Skip to content
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

Change type to var #6

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bc0b98d
isExpectedPage() changed
Apr 9, 2021
eb3934e
javadoc removed
Apr 12, 2021
e85219c
type changed to var
Apr 12, 2021
82964a0
step annotations changed
ufjena Apr 28, 2021
410e80c
pageobjects changed
ufjena Apr 28, 2021
11190ad
dataobjects changed
ufjena Apr 29, 2021
f02720e
project reworked
ufjena May 3, 2021
54cd243
isExpectedPage() - double use removed
ufjena May 4, 2021
db6ae4a
order changed for easier debugging
ufjena May 4, 2021
ca7a5f9
project reworked
ufjena May 7, 2021
ebe2311
project reworked
ufjena May 7, 2021
832d1ed
step annotations removed - test case added
ufjena May 7, 2021
a6363ec
RegisterPage changed
ufjena May 7, 2021
f6701fe
remove address form validation from AbstractBrowsingPage
oomelianchuk May 11, 2021
844c366
improve usage of AddressForm
oomelianchuk May 11, 2021
3588390
call isExpectedPage before returning page object
oomelianchuk May 19, 2021
04fcb79
remove return types from support flows
oomelianchuk May 19, 2021
6810e52
remove duplicated functionality and use updateCountOfProduct instead
oomelianchuk May 19, 2021
28c9a88
use forms to avoid code duplication
oomelianchuk May 19, 2021
9be2a4e
rename ~AddressForm to ~AddressContainer
oomelianchuk May 19, 2021
f35bbeb
improve toString method of Product
oomelianchuk May 19, 2021
79f2e79
improve naming of openProductdetailsPage
oomelianchuk May 19, 2021
4d84e10
return Product in updateCountOfProduct avoid product fetch
oomelianchuk May 20, 2021
6eb407c
remove ; from open page methods
oomelianchuk May 20, 2021
04ee4c9
remove TODO, method call in OrderSupport.openProductPageAndAddItoTheCart
oomelianchuk May 20, 2021
362ce7d
remove unneeded isExpectedPage call
oomelianchuk May 20, 2021
fa23796
remove unused method
oomelianchuk May 20, 2021
446951c
improve isComponentAvailable method of AddressForm
oomelianchuk May 20, 2021
4050880
add isPage method to check if the expected page is loaded without errors
oomelianchuk May 26, 2021
d02ffb4
check if account page is open while cleanup and don't open it again
oomelianchuk May 26, 2021
4c1865d
remove unneeded new line
oomelianchuk Jun 4, 2021
3dde365
improve removeProduct method
oomelianchuk Oct 1, 2021
bbaf053
fix toString method for Product
oomelianchuk Oct 1, 2021
4a07108
open mini cart before going to cart page
oomelianchuk Oct 1, 2021
e6c496d
remove isPage method
oomelianchuk Oct 1, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.cucumber.java.en.When;
import posters.pageobjects.pages.browsing.CategoryPage;
import posters.pageobjects.pages.browsing.HomePage;
import posters.pageobjects.pages.browsing.ProductdetailPage;
import posters.pageobjects.pages.browsing.ProductDetailPage;

public class BrowseRandomVisualAssertSupport
{
Expand All @@ -21,8 +21,8 @@ public class BrowseRandomVisualAssertSupport
@Given("^homepage is open")
public void openHomePageAndValidate()
{
HomePage homepage = OpenPageFlows.homepage();
homepage.validateAndVisualAssert();
var homePage = OpenPageFlows.homePage();
homePage.validateAndVisualAssert();
}

@When("^I choose random sub category with seed \"([^\"]*)\"$")
Expand All @@ -37,8 +37,7 @@ public void openRandomSubCategoryAndValidate(String seed)
random = new Random(Long.valueOf(seed));
}
String categoryName = new HomePage().topNav.getRandomSubcategoryName(random);
CategoryPage categoryPage = new HomePage().topNav.clickSubcategoryByName(categoryName);
categoryPage.isExpectedPage();
var categoryPage = new HomePage().topNav.clickSubcategoryByName(categoryName);
categoryPage.validateAndVisualAssert(categoryName);
}

Expand All @@ -52,7 +51,7 @@ public void openRandomProduct()
@Then("^I see correct product")
public void validateProduct()
{
new ProductdetailPage().validateAndVisualAssert(productName);
new ProductDetailPage().validateAndVisualAssert(productName);
}

}
30 changes: 13 additions & 17 deletions src/test/java/posters/cucumber/support/CartSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import posters.dataobjects.Product;
import posters.pageobjects.pages.browsing.ProductdetailPage;
import posters.pageobjects.pages.browsing.ProductDetailPage;
import posters.pageobjects.pages.checkout.CartPage;
import posters.pageobjects.utility.PriceHelper;

Expand All @@ -20,15 +20,14 @@ public CartSupport(GlobalStorage storage)
@When("^I open the cart$")
public void openCart()
{
CartPage cartPage = new ProductdetailPage().miniCart.openCartPage();
cartPage.isExpectedPage();
new ProductDetailPage().miniCart.openCartPage();
}

@Then("^I see all the added products in the cart and their properties are correct$")
public void validateProductsInTheCart()
{
double subtotal = 0.0;
CartPage cartPage = new CartPage();
var cartPage = new CartPage();

for (Product product : storage.products)
{
Expand All @@ -39,25 +38,22 @@ public void validateProductsInTheCart()
}

@Then("^I can change amount of the \"([^\"]*)\" with \"([^\"]*)\" and \"([^\"]*)\" to (\\d+)$")
public void updateCountOfProduct(String productName, String size, String style, int amount)
public void updateCountOfProduct(String name, String size, String style, int amount)
{
CartPage cartPage = new CartPage();
cartPage.updateProductCountByName(productName, style, size, amount);
for (Product product : storage.products)
{
if (product.getName().equals(productName) && product.getSize().equals(size)
&& product.getStyle().equals(style))
{
product.setAmount(amount);
}
cartPage.validateContainsProduct(product);
}
var cartPage = new CartPage();
cartPage.updateProductCountByName(name, style, size, amount);

var updateProduct = storage.getProductFromArrayList(name, size, style);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oomelianchuk I think we can use storage.updateCountOfProduct() to shorten the code at this place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, done

storage.products.remove(updateProduct);
String unitPrice = updateProduct.getUnitPrice();
updateProduct = new Product(name, unitPrice, style, size, amount);
storage.products.add(updateProduct);
}

@Then("^I can remove \"([^\"]*)\" with \"([^\"]*)\" and \"([^\"]*)\"$")
public void removeProduct(String productName, String size, String style)
{
CartPage cartPage = new CartPage();
var cartPage = new CartPage();
cartPage.removeProductByName(productName, style, size);

storage.removeProduct(productName, style, size);
Expand Down
39 changes: 30 additions & 9 deletions src/test/java/posters/cucumber/support/GlobalStorage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package posters.cucumber.support;

import java.util.ArrayList;
Expand Down Expand Up @@ -38,8 +35,15 @@ public Product addProduct(Product product)
// increase amount of product if already there or add the whole product
if (products.contains(product))
{
Product updatedProduct = products.get(products.indexOf(product));
updatedProduct.setAmount(updatedProduct.getAmount() + 1);
var updatedProduct = products.get(products.indexOf(product));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oomelianchuk Please reuse updateCountOfProduct if possible. We should not implement the same functions again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

String name = updatedProduct.getName();
String unitPrice = updatedProduct.getUnitPrice();
String style = updatedProduct.getStyle();
String size = updatedProduct.getSize();
int amount = updatedProduct.getAmount();
products.remove(updatedProduct);
updatedProduct = new Product(name, unitPrice, style, size, amount + 1);
products.add(updatedProduct);
return updatedProduct;
}
else
Expand All @@ -48,16 +52,33 @@ public Product addProduct(Product product)
return product;
}
}

public void removeProduct(String productName, String style, String size)
public Product getProductFromArrayList(String name, String size, String style)
{
int i = 0;
for (Product product : products)
{
if (product.getName().equals(productName) && product.getSize().equals(size)
if (product.getName().equals(name) && product.getSize().equals(size)
&& product.getStyle().equals(style))
{
products.remove(product);
i = products.indexOf(product);
}
}
return products.get(i);
}

public void updateCountOfProduct(String name, String size, String style, int amount)
{
var updateProducht = getProductFromArrayList(name, size, style);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename updateProducht to product.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

String unitPrice = updateProducht.getUnitPrice();
products.remove(products.indexOf(updateProducht));
updateProducht = new Product(name, unitPrice, style, size, amount);
products.add(updateProducht);
}

public void removeProduct(String name, String style, String size)
{
var updateProducht = getProductFromArrayList(name, size, style);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename updateProducht to product.
Maybe you can also delete the local variable and call it directly within the next line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

products.remove(products.indexOf(updateProducht));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is products.indexOf needed?

products.remove(updateProducht); should work as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
}
3 changes: 1 addition & 2 deletions src/test/java/posters/cucumber/support/HomePageSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class HomePageSupport
@Step("validate homepage")
public void validateHomePage(String title)
{
HomePage homePage = new HomePage();
homePage.isExpectedPage();
var homePage = new HomePage();
homePage.title.validateTitle(title);
homePage.validateStructure();
homePage.footer.validate();
Expand Down
25 changes: 10 additions & 15 deletions src/test/java/posters/cucumber/support/OpenPageFlows.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,53 @@
import io.cucumber.java.en.Given;
import io.qameta.allure.Step;
import posters.pageobjects.pages.browsing.HomePage;
import posters.pageobjects.pages.browsing.ProductdetailPage;
import posters.pageobjects.pages.browsing.ProductDetailPage;
import posters.pageobjects.pages.user.LoginPage;
import posters.pageobjects.pages.user.RegisterPage;

public class OpenPageFlows
{
@Given("^homepage is loaded$")
@Step("open home page")
public static HomePage homepage()
public static HomePage homePage()
{
// clear cookies to ensure a new session
clearBrowserCookies();
// open home page
open(Neodymium.configuration().url());
HomePage homePage = new HomePage();
homePage.isExpectedPage();
return homePage;
return new HomePage().isExpectedPage();
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oomelianchuk Please remove the ; after functions. They are not needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


@Given("^login page is loaded$")
@Step("open login page")
public static LoginPage loginPage()
{
// open login page and check for expected page
LoginPage loginPage = homepage().userMenu.openLogin();
loginPage.isExpectedPage();
return loginPage;
return homePage().userMenu.openLogin();
};

@Given("^register page is loaded$")
@Step("open register page")
public static RegisterPage registerPage()
{
// open login page and check for expected page
RegisterPage registerPage = homepage().userMenu.openRegister();
registerPage.isExpectedPage();
return registerPage;
return homePage().userMenu.openRegister();
};

@Given("^product page \"([^\"]*)\" is open$")
@Step("open product page with cleared cookes")
public static ProductdetailPage openProductdetailsPageWithClearedCookes(String url)
public static ProductDetailPage openProductdetailsPageWithClearedCookes(String url)
{
clearBrowserCookies();
open(Neodymium.configuration().url() + url);
return new ProductdetailPage();
return new ProductDetailPage();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please call isExpectedPage() to validate the result

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

// TODO check if needed - else delete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oomelianchuk Please take care of the TODO

Copy link
Contributor

@oomelianchuk oomelianchuk May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is called in OrderSupport.openProductPageAndAddItoTheCart, so I just removed TODO

@Step("open product page without cleared cookes")
public static ProductdetailPage openProductdetailsPage(String url)
public static ProductDetailPage openProductdetailsPage(String url)
{
open(Neodymium.configuration().url() + url);
return new ProductdetailPage();
return new ProductDetailPage();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please call isExpectedPage() to validate the result

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
}
94 changes: 42 additions & 52 deletions src/test/java/posters/cucumber/support/OrderSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@
import posters.dataobjects.Product;
import posters.dataobjects.User;
import posters.pageobjects.pages.browsing.HomePage;
import posters.pageobjects.pages.browsing.ProductdetailPage;
import posters.pageobjects.pages.checkout.CartPage;
import posters.pageobjects.pages.browsing.ProductDetailPage;
import posters.pageobjects.pages.checkout.PaymentPage;
import posters.pageobjects.pages.checkout.PlaceOrderPage;
import posters.pageobjects.pages.checkout.ShippingAddressPage;
import posters.pageobjects.pages.user.AccountOverviewPage;
import posters.pageobjects.pages.user.LoginPage;
import posters.pageobjects.pages.user.OrderHistoryPage;
import posters.pageobjects.pages.user.RegisterPage;
import posters.pageobjects.utility.PriceHelper;

public class OrderSupport
Expand All @@ -33,97 +27,93 @@ public OrderSupport(GlobalStorage storage)
@Given("^new user with \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\" is registered and logged in$")
public void registerAndLogIn(String firstName, String lastName, String email, String password)
{
RegisterPage registerPage = OpenPageFlows.registerPage();
var registerPage = OpenPageFlows.registerPage();
registerPage.isExpectedPage();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check all "Support" classes. We should have added the isExpectedPage already in the open function for the page. so a second call should not be needed.

storage.user = new User(firstName, lastName, email, password);
registerPage.sendRegisterForm(firstName, lastName, email, password, password);
LoginPage loginPage = registerPage.userMenu.openLogin();
loginPage.isExpectedPage();
var loginPage = registerPage.userMenu.openLogin();;
loginPage.sendLoginform(email, password);
}

@Then("^all the products are to find in order history$")
public void validateOrderInOrderHistory()
@When("I add this product with size \"([^\"]*)\" and style \"([^\"]*)\" to the cart$")
public void addProductToCart(String size, String style)
{
AccountOverviewPage accountOverview = new HomePage().userMenu.openAccountOverview();
accountOverview.isExpectedPage();
OrderHistoryPage orderHistory = accountOverview.openOrderHistory();
for (Product product : storage.products)
{
orderHistory.validateContainsProduct(product);
}
}
var productDetailPage = new ProductDetailPage();
productDetailPage.setSize(size);
productDetailPage.setStyle(style);

var product = storage.addProduct(productDetailPage.getProduct());

productDetailPage.addToCart();
productDetailPage.miniCart.openMiniCart();
productDetailPage.miniCart.validateMiniCartByProduct(product);
}

@When("^I add product \"([^\"]*)\" in size \"([^\"]*)\" and style \"([^\"]*)\"$")
@Step("open product page and add product to the cart")
public void openProductPageAndAddItoTheCart(String productUrl, String size, String style)
{
OpenPageFlows.openProductdetailsPage(productUrl);
addProductToCart(size, style);
}

@When("I add this product with size \"([^\"]*)\" and style \"([^\"]*)\" to the cart$")
public void addProductToCart(String size, String style)
{
ProductdetailPage productPage = new ProductdetailPage();
productPage.setSize(size);
productPage.setStyle(style);

Product product = storage.addProduct(productPage.getProduct());

productPage.addToCart();
productPage.miniCart.openMiniCart();
productPage.miniCart.validateMiniCartByProduct(product);
}


@When("^I specify the shipping address \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\" and use it for billing$")
public void openFillAndSendShippingFormUseForBilling(String name, String company, String address, String city, String state, String zip, String country)
public void openFillAndSendShippingFormUseForBilling(String name, String company, String street, String city, String state, String zip, String country)
{
CartPage cartPage = new ProductdetailPage().miniCart.openCartPage();
cartPage.isExpectedPage();
ShippingAddressPage shippingPage = cartPage.openShippingPage();
shippingPage.isExpectedPage();
shippingPage.sendShippingAddressForm(name, company, address, city, state, zip, country, true);
storage.shippingAddress = new Address(name, company, address, city, state, zip, country);
storage.billingAddress = new Address(name, company, address, city, state, zip, country);
var cartPage = new ProductDetailPage().miniCart.openCartPage();
var shippingAddressPage = cartPage.openShippingPage();
shippingAddressPage.sendShippingAddressForm(name, company, street, city, state, zip, country, true);

storage.shippingAddress = new Address(storage.user.getFirstName(), storage.user.getLastName(), company, street, city, state, zip, country);
storage.billingAddress = new Address(storage.user.getFirstName(), storage.user.getLastName(), company, street, city, state, zip, country);
new PaymentPage().isExpectedPage();
}

@When("^I enter payment data \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\", \"([^\"]*)\"$")
public void fillAndSendPaymentForm(String name, String cardNumber, String month, String year)
{
PaymentPage paymentPage = new PaymentPage();
var paymentPage = new PaymentPage();
paymentPage.isExpectedPage();
PlaceOrderPage placeOrder = paymentPage.sendPaymentForm(cardNumber, name, month, year);
paymentPage.sendPaymentForm(cardNumber, name, month, year);

storage.creditcard = new CreditCard(name, cardNumber, "xxxx xxxx xxxx " + cardNumber.substring(12, 16), month, year);
placeOrder.isExpectedPage();
}

@Then("^I see all the products in order overview$")
public void validateContainsAllProductsWithCorrectPricesAndAmount()
{
double subtotal = 0.0;
PlaceOrderPage placeOrder = new PlaceOrderPage();
var placeOrderPage = new PlaceOrderPage();
for (Product product : storage.products)
{
placeOrder.validateContainsProduct(product);
placeOrderPage.validateContainsProduct(product);
subtotal += product.getTotalPrice();
}
placeOrder.validateSubtotal(PriceHelper.format(subtotal));
placeOrderPage.validateSubtotal(PriceHelper.format(subtotal));
}

@Then("^my shipping and billing addresses as well as payment data are displayed correctly")
public void validateAddressesAndPaymentData()
{
PlaceOrderPage placeOrder = new PlaceOrderPage();
placeOrder.validateAddressesAndPayment(storage.shippingAddress, storage.billingAddress, storage.creditcard);
var placeOrderPage = new PlaceOrderPage();
placeOrderPage.validateAddressesAndPayment(storage.shippingAddress, storage.billingAddress, storage.creditcard);
}

@Then("^my order is successfully placed$")
public void placeOrder()
{
HomePage succssefulOrder = new PlaceOrderPage().placeOrder();
succssefulOrder.isExpectedPage();
succssefulOrder.validateSuccessfulOrder();
}

@Then("^all the products are to find in order history$")
public void validateOrderInOrderHistory()
{
var accountOverviewPage = new HomePage().userMenu.openAccountOverview();
var orderHistoryPage = accountOverviewPage.openOrderHistory();
for (Product product : storage.products)
{
orderHistoryPage.validateContainsProduct(product);
}
}
}
Loading