Skip to content

Commit

Permalink
#1022 - Apply Automation test for Yas project
Browse files Browse the repository at this point in the history
- create category scenario init
  • Loading branch information
Phuoc Nguyen committed Sep 18, 2024
1 parent 48aba33 commit 5f12447
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public static WebElement getWebElementBy(WebDriver driver, How how, String ident
return driver.findElement(locator);
}

public static boolean isCorrectUrl(WebDriver driver, String expectedUrl) {
String currentUrl = driver.getCurrentUrl();
return expectedUrl.equals(currentUrl);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.yas.automation.ui.form;

import lombok.Getter;
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.PageFactory;

@Getter
public class CategoryForm extends BaseForm {

@FindBy(how = How.ID, using = "name")
private WebElement name;

@FindBy(how = How.ID, using = "slug")
private WebElement slug;

@FindBy(how = How.ID, using = "description")
private WebElement description;

@FindBy(how = How.ID, using = "metaKeywords")
private WebElement metaKeywords;

@FindBy(how = How.ID, using = "metaDescription")
private WebElement metaDescription;

@FindBy(xpath = "//button[@type='submit' and contains(text(),'Create')]")
WebElement createBtn;

public CategoryForm(WebDriver webDriver) {
super(webDriver);
PageFactory.initElements(webDriver, this);
}

@Override
public WebElement getSubmitBtn() {
return createBtn;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yas.automation.ui.pages;

import com.yas.automation.ui.hook.WebDriverFactory;
import com.yas.automation.ui.service.InputDelegateService;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class CategoryPage extends BasePage {
private final WebDriverFactory webDriverFactory;

private final InputDelegateService inputDelegateService;

public CategoryPage(WebDriverFactory webDriverFactory,
InputDelegateService inputDelegateService) {
super(webDriverFactory.getChromeDriver());
this.webDriverFactory = webDriverFactory;
this.inputDelegateService = inputDelegateService;
}

public void clickCreateCategoryButton() {
WebElement createCategoryButton = webDriverFactory.getChromeDriver().findElement(By.cssSelector("a[href='/catalog/categories/create'] button"));
createCategoryButton.click();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yas.automation.ui.pages;

import com.yas.automation.ui.hook.WebDriverFactory;
import com.yas.automation.ui.service.InputDelegateService;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class NewCategoryPage extends BasePage {

private final WebDriverFactory webDriverFactory;

private final InputDelegateService inputDelegateService;

public NewCategoryPage(WebDriverFactory webDriverFactory,
InputDelegateService inputDelegateService) {
super(webDriverFactory.getChromeDriver());
this.webDriverFactory = webDriverFactory;
this.inputDelegateService = inputDelegateService;
}

public void fillInAllNecessaryField() {
WebElement createCategoryButton = webDriverFactory.getChromeDriver().findElement(By.cssSelector("a[href='/catalog/categories/create'] button"));
createCategoryButton.click();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.yas.automation.ui.steps;

import static org.junit.Assert.assertTrue;

import com.yas.automation.ui.hook.WebDriverFactory;
import com.yas.automation.ui.pages.CategoryPage;
import com.yas.automation.ui.pages.HomePage;
import com.yas.automation.ui.service.AuthenticationService;
import com.yas.automation.ui.util.WebElementUtil;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class CreateCategorySteps {
private final AuthenticationService authenticationService;
private final WebDriverFactory webDriverFactory;
private final HomePage homePage;
private final CategoryPage categoryPage;

public CreateCategorySteps(AuthenticationService authenticationService, WebDriverFactory webDriverFactory,
HomePage homePage, CategoryPage categoryPage) {
this.authenticationService = authenticationService;
this.webDriverFactory = webDriverFactory;
this.homePage = homePage;
this.categoryPage = categoryPage;
}

@Given("I am logged in successfully")
public void i_am_logged_in_successfully() {
authenticationService.authorizeWithAdminUser();
}

@When("I click on the {string} option in the menu")
public void i_click_on_option_in_the_menu(String option) {
homePage.clickToCatalogItem(option);
}

@Then("I should be redirected to the category list page")
public void i_should_be_redirected_to_category_list_page() {
assertTrue(WebElementUtil.isCorrectUrl(webDriverFactory.getChromeDriver(), "http://backoffice/catalog/categories"));
}

@When("I click on the Create Category button")
public void i_click_on_button(String button) {
categoryPage.clickCreateCategoryButton();
}

@Then("I should be redirected to the create category page")
public void i_should_be_redirected_to_create_category_page() {
assertTrue(WebElementUtil.isCorrectUrl(webDriverFactory.getChromeDriver(), "http://backoffice/catalog/categories/create"));
}

@Given("I have filled in all the necessary data for the new category")
public void i_have_filled_in_all_the_necessary_data_for_new_category() {
//categoryPage.fillInAllNecessaryFields();
}

@When("I click the {string} button")
public void iClickTheButton(String arg0) {
}

@Then("I should be redirected to the category list page")
public void i_should_be_redirected_to_category_list_page_again() {
// Code to verify redirection back to the category list page after saving
}

@Then("the new category should be displayed in the category list")
public void the_new_category_should_be_displayed_in_the_category_list() {
// Code to check if the new category is visible in the category list
// Example: Find the newly created category in the list
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Create Category

Scenario: Successfully create a new category
Given I am logged in successfully
When I click on the "categories" option in the menu
Then I should be redirected to the category list page
When I click on the Create Category button
Then I should be redirected to the create category page
Given I have filled in all the necessary data for the new category
When I click the "Save" button
Then I should be redirected to the category list page
And the new category should be displayed in the category list

0 comments on commit 5f12447

Please sign in to comment.