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

add test for labels and languages view #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -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<WebElement> 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<WebElement> 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();
}

}
Original file line number Diff line number Diff line change
@@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +42,12 @@
@TestExecutionListeners({ SeleniumTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class })
public class FunctionalTest {

@Autowired
protected DTLoginPage dTLoginPage;

@Autowired
protected DTDashboardPage dTDashboardPage;

@Autowired
protected WebDriver driver;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public String getText(WebElement item){
public String[] getText(List<WebElement> 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;
}
Expand All @@ -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<Boolean>) (WebDriver d) -> {
int size = element.findElements(By.xpath(childrenSelector)).size();
Expand Down