Skip to content
Open
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
53 changes: 24 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
# README #

This README would normally document whatever steps are necessary to get your application up and running.

### What is this repository for? ###

* Quick summary
* Version
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)

### How do I get set up? ###

* Summary of set up
* Configuration
* Dependencies
* Database configuration
* How to run tests
* Deployment instructions

### Contribution guidelines ###

* Writing tests
* Code review
* Other guidelines

### Who do I talk to? ###

* Repo owner or admin
* Other community or team contact
# Manual-Tester-Auto-Test
## Used:
1. Java 11+
2. Maven
3. Selenium WebDriver
4. jUnit 5.x
5. Page object pattern
6. Page factory

### for page:
[Automationpractice](http://automationpractice.com )

## Added:


| to pageobjects: | to tests: | to utils: |
| --------------------- |:---------------------:|-----------:|
| BasePage | BaseTest | RandomUser |
| HomePage | CartTest | |
| ExecutionOfOrdersPage | ExecutionOfOrdersTest | |
| LoginPage | LoginTest | |
| ProductsPage | RegisterTest | |
| RegisterPage | SearchTest | |
| SearchResultPage | | |
54 changes: 50 additions & 4 deletions src/test/java/pageobjects/BasePage.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,63 @@
package pageobjects;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.List;

// here we put selectors and methods common to all subpages of our test application
// we do that we can see in automationpractice.com that footer and headers are the same on all subpages

public class BasePage {
// @FindBy to Page Factory and expands Page Object
@FindBy(id="search_query_top") // it's the same as driver.findElement(By.id("search_query_top"))
WebElement searchBox; // it's the same as driver.findElement(By.id("search_query_top"))

@FindBy(css = ".menu-content>li>a")
List<WebElement> productCategories; // List <WebElement> productCategories = driver.findElements (By.cssSelector (". Menu-content> li> a"));

@FindBy(css = ".shopping_cart .ajax_cart_quantity")
WebElement cartQuantity;

@FindBy(className = "login")
WebElement signInButton;

WebDriver driver; // because our diver is here so every other class inherits this driver
WebDriverWait wait;

WebDriver driver;
static final String BASE_URL = "http://automationpractice.com/";

public BasePage(WebDriver driverIn, WebDriverWait waitIn) { // we need create constructor to give 'static' WebDriver diver;' from tests / java / tests / BaseTests
this.driver = driverIn; // driverIn is driver with comes from our method executed
this.wait = waitIn;
// we must say in constructor that InteliJ IDEA should initialize and find elements @FindBy
PageFactory.initElements(driver, this);
}

public void searchForProduct(String productName) {
driver.findElement(By.id("search_query_top")).sendKeys("dress");
driver.findElement(By.id("search_query_top")).sendKeys(Keys.ENTER);
// write searching keyword in search box and enter
searchBox.sendKeys("dress"); // in search pool we type dress
searchBox.sendKeys(Keys.ENTER); // confirm searching phrase with enter
}

// Menu: WOMEN | DRESSES | T-SHIRTS is available in all subpages we can put method
// opening selected category in our BasePage class:
public void goToProductCategoryByIndex(int productCategoryIndex) { // depending with we choose (WOMEN, DRESSES, T-SHIRTS) method will click on this what we choose
// we created locator to three elements on menu bar in @FindBy
productCategories.get(productCategoryIndex).click(); // we click on forwarded "productCategoryIndex" in menu
}

public int getCartSize() {
String cartQuantityText = cartQuantity.getText();
return Integer.parseInt(cartQuantityText);
}

public void clickSignIn() {
signInButton.click();
}

}
40 changes: 40 additions & 0 deletions src/test/java/pageobjects/ExecutionOfOrdersPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package pageobjects;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ExecutionOfOrdersPage extends BasePage {
@FindBy(how = How.NAME, using = "processAddress")
WebElement proceedToCheckout;

@FindBy(id = "uniform-cgv")
WebElement termsOfServiceCheckBox;

@FindBy(how = How.NAME, using = "processCarrier")
WebElement proceedToCheckoutAgain;

@FindBy(className = "bankwire")
WebElement payByBankWireButton;

@FindBy(className = "cheque")
WebElement payByCheckButton;

@FindBy(xpath = "//button[@type='submit' and contains(.,'confirm ' )]")
WebElement confirmMyOrderButton;

public ExecutionOfOrdersPage(WebDriver driverIn, WebDriverWait waitIn) {
super(driverIn, waitIn);
}

public void completionOfTheOrder() {
proceedToCheckout.click();
termsOfServiceCheckBox.click();
proceedToCheckoutAgain.click();
payByBankWireButton.click();
confirmMyOrderButton.click();
}

}
17 changes: 9 additions & 8 deletions src/test/java/pageobjects/HomePage.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package pageobjects;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class HomePage extends BasePage {
public HomePage(WebDriver driverIn, WebDriverWait waitIn) {
super(driverIn, waitIn);
}

public HomePage(WebDriver driverIn) {
this.driver = driverIn;
}
// open main page
public void openPage() {
driver.get(BASE_URL + "index.php");
}

public void openPage() {
driver.get(BASE_URL + "index.php");
}

}
}
61 changes: 59 additions & 2 deletions src/test/java/pageobjects/LoginPage.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
package pageobjects;

public class LoginPage {
}
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.WebDriverWait;
import utils.RandomUser;

public class LoginPage extends BasePage {
@FindBy(id = "email")
WebElement emailAddressField;

@FindBy(id = "passwd")
WebElement passwdField;

@FindBy(id = "SubmitLogin")
WebElement signInButton;

@FindBy(className = "logout")
WebElement signOutButton;

@FindBy(id = "email_create")
WebElement createNewAccountField;

@FindBy(id = "SubmitCreate")
WebElement createNewAccountButton;

public LoginPage(WebDriver driverIn, WebDriverWait waitIn) {
super(driverIn, waitIn);
}

public void goToRegisterForm() throws InterruptedException {
RandomUser user = new RandomUser();
clickSignIn();
createNewAccountField.sendKeys(user.email);
createNewAccountButton.click();
}

public void signInToRegisteredAccount() {
emailAddressField.sendKeys("test@autotest.pl"); // registered
passwdField.sendKeys("autoTest_1234!"); // registered
signInButton.click();
Assertions.assertEquals(signOutButton.getText(), "Sign out");
}

public void signInToNotRegisteredAccount() {
RandomUser user = new RandomUser();
emailAddressField.sendKeys(user.email); // not registered
passwdField.sendKeys(user.password); // not registered
signInButton.click();
// Assertions.assertEquals
}

public void continueOrderShouldAddProductToTheBasketAndBuyThroughRegisterForm() {
RandomUser user = new RandomUser();
createNewAccountField.sendKeys(user.email);
createNewAccountButton.click();
}

}
4 changes: 0 additions & 4 deletions src/test/java/pageobjects/MyAccountPage.java

This file was deleted.

74 changes: 74 additions & 0 deletions src/test/java/pageobjects/ProductsPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package pageobjects;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.List;
import java.util.Random;

public class ProductsPage extends BasePage {
@FindBy(css = ".product_list .product-container")
List<WebElement> productsContainers;

@FindBy(css = ".ajax_add_to_cart_button")
List<WebElement> addToCartButtons;

@FindBy(className = "continue")
WebElement continueShoppingButton;

@FindBy(linkText = "Proceed to checkout")
WebElement proceedCheckoutButton;

// we need create constructor to give 'static WebDriver driver;' from src/test/java/tests/BaseTest
public ProductsPage(WebDriver driverIn, WebDriverWait waitIn) {
super(driverIn, waitIn);
}

public void moveMouseToProductContainer(int productIndex) { // List<WebElement> productsContainers = diver.findElements(By.cssSelector(".product_list .product-container"));
Actions builder = new Actions(driver);
builder.moveToElement(productsContainers.get(productIndex)).build().perform(); // we must add ".build().perform();" every invoke moveToElement
}

public void addProductToTheBasket(int productIndex) {
// wait until element: "addToCartButtons.get(productIndex)" will be clickable
wait.until(ExpectedConditions.elementToBeClickable(addToCartButtons.get(productIndex)));
// if is clickable > click
addToCartButtons.get(productIndex).click();
// wait until element: "continueShoppingButton" will be clickable
wait.until(ExpectedConditions.elementToBeClickable(continueShoppingButton));
// if is clickable > click
continueShoppingButton.click();
}

public void addProductToTheBasketAndProceedCheckout(int productIndex) {
// wait until element: "addToCartButtons.get(productIndex)" will be clickable
wait.until(ExpectedConditions.elementToBeClickable(addToCartButtons.get(productIndex)));
// if is clickable > click
addToCartButtons.get(productIndex).click();
// wait until element: "proceedCheckoutButton" will be clickable
wait.until(ExpectedConditions.elementToBeClickable(proceedCheckoutButton));
// if is clickable > click
proceedCheckoutButton.click();
// now we see summary and we must click proceedCheckoutButton again to continue shopping
proceedCheckoutButton.click();
// now we are on LoginPage and we are ask to CREATE AN ACCOUNT or login by ALREADY REGISTERED? form
}

public void addRandomProductToCart() {
Random random = new Random();
int productIndex = random.nextInt(productsContainers.size()); // set random number of product from showed product list
moveMouseToProductContainer(productIndex); // we except that sixth element from the list will be clicked // 5
addProductToTheBasket(productIndex); // we click on sixth element to add to the basket // 5
}

public void addRandomProductToCartAndProceedCheckout() {
Random random = new Random();
int productIndex = random.nextInt(productsContainers.size()); // set random number of product from showed product list
moveMouseToProductContainer(productIndex); // we except that sixth element from the list will be clicked // 5
addProductToTheBasketAndProceedCheckout(productIndex); // we click on sixth element to add to the basket // 5
}
}
Loading