-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1022 - Apply Automation test for Yas project
- create category scenario init
- Loading branch information
Phuoc Nguyen
committed
Sep 18, 2024
1 parent
48aba33
commit 5f12447
Showing
6 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
automation-ui/backoffice/src/test/java/com/yas/automation/ui/form/CategoryForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
automation-ui/backoffice/src/test/java/com/yas/automation/ui/pages/CategoryPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |
26 changes: 26 additions & 0 deletions
26
automation-ui/backoffice/src/test/java/com/yas/automation/ui/pages/NewCategoryPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
automation-ui/backoffice/src/test/java/com/yas/automation/ui/steps/CreateCategorySteps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
automation-ui/backoffice/src/test/resources/features/createCategory.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |