diff --git a/Selenium_TESTS/src/test/java/org/entando/selenium/pages/DTLabelsAndLanguagesPage.java b/Selenium_TESTS/src/test/java/org/entando/selenium/pages/DTLabelsAndLanguagesPage.java new file mode 100644 index 0000000..24f30a6 --- /dev/null +++ b/Selenium_TESTS/src/test/java/org/entando/selenium/pages/DTLabelsAndLanguagesPage.java @@ -0,0 +1,114 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.entando.selenium.pages; + +import java.util.List; +import org.entando.selenium.utils.PageObject; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.Select; + +/** + * + * @author leobel + */ +public class DTLabelsAndLanguagesPage extends PageObject { + + @FindBy(css = "h1 > span:nth-child(1)") + private WebElement pageTitle; + + @FindBy(xpath = "//ul[contains(@class, 'LabelsAndLanguagesPage__header-container')]/li") + private List tabs; + + @FindBy(xpath = "//select[contains(@class, 'LanguageForm__language-field')]") + private WebElement selectLanguage; + + @FindBy(xpath = "//button[@type='submit']/span[text()='Add']/parent::button") + private WebElement addBUtton; + + @FindBy(xpath = "//table[contains(@class, 'ActiveLangTable__table')]") + private WebElement languageTable; + + @FindBy(xpath = "//form[contains(@class, 'LabelSearchForm')]") + private WebElement searchForm; + + @FindBy(xpath = "//input[contains(@class, 'LabelSearchForm__text-field')]") + private WebElement searchInput; + + @FindBy(xpath = "//button[@type='submit']/span[text()='Search']/parent::button") + private WebElement searchButton; + + @FindBy (xpath = "//table[contains(@class, 'LabelsTable')]") + private WebElement labelsTable; + + @FindBy(xpath = "//*[contains(@class, 'spinner')]") + private WebElement searchSpinner; + + public WebElement getLabelsTable() { + return labelsTable; + } + + public WebElement getSearchSpinner() { + return searchSpinner; + } + + public WebElement getSearchForm() { + return searchForm; + } + + public WebElement getSearchInput() { + return searchInput; + } + + public WebElement getSearchButton() { + return searchButton; + } + + public WebElement getPageTitle() { + return pageTitle; + } + + public List getTabs() { + return tabs; + } + + public WebElement getSelectLanguage() { + return selectLanguage; + } + + public WebElement getAddBUtton() { + return addBUtton; + } + + public WebElement getLanguageTable() { + return languageTable; + } + + public WebElement getLabelsTab(){ + return tabs.get(1); + } + + + public DTLabelsAndLanguagesPage(WebDriver driver) { + super(driver); + } + + public void setLanguage(String code) { + Select language = getLanguageSelect(); + language.selectByValue(code); + } + + private Select getLanguageSelect() { + return new Select(selectLanguage); + } + + public void search(String text) { + getSearchInput().sendKeys(text); + getSearchButton().click(); + } + +} diff --git a/Selenium_TESTS/src/test/java/org/entando/selenium/tests/DTLabelsAndLanguagesTest.java b/Selenium_TESTS/src/test/java/org/entando/selenium/tests/DTLabelsAndLanguagesTest.java new file mode 100644 index 0000000..9e302f2 --- /dev/null +++ b/Selenium_TESTS/src/test/java/org/entando/selenium/tests/DTLabelsAndLanguagesTest.java @@ -0,0 +1,50 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.entando.selenium.tests; + +import org.entando.selenium.pages.DTLabelsAndLanguagesPage; +import org.entando.selenium.utils.FunctionalTest; +import org.entando.selenium.utils.Utils; +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * + * @author leobel + */ +public class DTLabelsAndLanguagesTest extends FunctionalTest { + + @Autowired + DTLabelsAndLanguagesPage dTLabelsAndLanguagesPage; + + @Autowired + Utils util; + + @Test + public void test(){ + login(); + goTo("Configuration", "Labels and Languages"); + + String pageTitle = "Labels and Languages"; + String[] tabs = new String[]{"Languages", "System labels"}; + + Assert.assertEquals(pageTitle, dTLabelsAndLanguagesPage.getPageTitle().getText()); + + String[] pageTabs = util.getText(dTLabelsAndLanguagesPage.getTabs()); + Assert.assertArrayEquals(tabs, pageTabs); + Assert.assertTrue(dTLabelsAndLanguagesPage.getLanguageTable().isDisplayed()); + + dTLabelsAndLanguagesPage.getLabelsTab().click(); + + util.waitUntilIsVisible(driver, dTLabelsAndLanguagesPage.getLabelsTable()); + Assert.assertTrue(dTLabelsAndLanguagesPage.getSearchForm().isDisplayed()); + dTLabelsAndLanguagesPage.search("all"); + util.waitUntilIsVisible(driver, dTLabelsAndLanguagesPage.getSearchSpinner()); + Assert.assertTrue(dTLabelsAndLanguagesPage.getLabelsTable().isDisplayed()); + } + +} diff --git a/Selenium_TESTS/src/test/java/org/entando/selenium/utils/AppConfig.java b/Selenium_TESTS/src/test/java/org/entando/selenium/utils/AppConfig.java index d18c701..28bdb68 100644 --- a/Selenium_TESTS/src/test/java/org/entando/selenium/utils/AppConfig.java +++ b/Selenium_TESTS/src/test/java/org/entando/selenium/utils/AppConfig.java @@ -16,6 +16,7 @@ import org.entando.selenium.pages.DTGroupDetailsPage; import org.entando.selenium.pages.DTGroupEditPage; import org.entando.selenium.pages.DTGroupsPage; +import org.entando.selenium.pages.DTLabelsAndLanguagesPage; import org.entando.selenium.pages.DTLoginPage; import org.entando.selenium.pages.DTPageEditPage; import org.entando.selenium.pages.DTPageTreePage; @@ -160,6 +161,12 @@ public DTWidgetPage dTWidgetPage(WebDriver driver){ return new DTWidgetPage(driver); } + @Bean + @Scope("prototype") + public DTLabelsAndLanguagesPage dTLabelsAndLanguagesPage(WebDriver driver){ + return new DTLabelsAndLanguagesPage(driver); + } + @Bean @Scope("prototype") public Utils utils(){ diff --git a/Selenium_TESTS/src/test/java/org/entando/selenium/utils/FunctionalTest.java b/Selenium_TESTS/src/test/java/org/entando/selenium/utils/FunctionalTest.java index 1fce71f..25ded0e 100644 --- a/Selenium_TESTS/src/test/java/org/entando/selenium/utils/FunctionalTest.java +++ b/Selenium_TESTS/src/test/java/org/entando/selenium/utils/FunctionalTest.java @@ -13,6 +13,9 @@ package org.entando.selenium.utils; import java.util.concurrent.TimeUnit; +import org.entando.selenium.pages.DTDashboardPage; +import org.entando.selenium.pages.DTLoginPage; +import static org.junit.Assert.assertTrue; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; @@ -39,6 +42,12 @@ @TestExecutionListeners({ SeleniumTestExecutionListener.class, DependencyInjectionTestExecutionListener.class }) public class FunctionalTest { + + @Autowired + protected DTLoginPage dTLoginPage; + + @Autowired + protected DTDashboardPage dTDashboardPage; @Autowired protected WebDriver driver; @@ -58,4 +67,15 @@ public void tearDown() { driver.close(); driver.quit(); } + + protected void login(){ + dTLoginPage.logIn("admin", "adminadmin"); + + ReceiptDTLoginPage receiptDtPage = dTLoginPage.submit(); + assertTrue(receiptDtPage.isInitialized()); + } + + protected void goTo(String menu, String submenu){ + dTDashboardPage.SelectSecondOrderLink(menu, submenu); + } } diff --git a/Selenium_TESTS/src/test/java/org/entando/selenium/utils/Utils.java b/Selenium_TESTS/src/test/java/org/entando/selenium/utils/Utils.java index 0c36abc..eebf9b4 100644 --- a/Selenium_TESTS/src/test/java/org/entando/selenium/utils/Utils.java +++ b/Selenium_TESTS/src/test/java/org/entando/selenium/utils/Utils.java @@ -289,7 +289,7 @@ public String getText(WebElement item){ public String[] getText(List items) { String[] result = new String[items.size()]; for(int i = 0; i < items.size(); i++){ - result[i] = items.get(i).getAttribute(innerText); + result[i] = items.get(i).getAttribute(innerText).trim(); } return result; } @@ -304,6 +304,16 @@ public void waitUntilIsVisible(WebDriver driver, WebElement element) { wait.until(ExpectedConditions.visibilityOf(element)); } + public int getTableCount(WebElement table){ + return table.findElements(By.xpath("/tbody/tr")).size(); + } + + public void waitUntilTableSizeChange(WebDriver driver, WebElement table){ + int size = getTableCount(table); + WebDriverWait wait = new WebDriverWait(driver, 5); + waitUntilSizeChange(wait, table, "/tbody/tr", size); + } + private void waitUntilSizeChange(WebDriverWait wait, WebElement element, String childrenSelector, int currentSize){ wait.until((ExpectedCondition) (WebDriver d) -> { int size = element.findElements(By.xpath(childrenSelector)).size();