Skip to content

Commit

Permalink
fix(test): Audit administration functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djansen-redhat committed Dec 7, 2017
1 parent 79e208c commit 0800493
Show file tree
Hide file tree
Showing 22 changed files with 666 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,24 +396,55 @@ abstract class AbstractPage(val driver: WebDriver) {
}

/**
* Retrieve the text from an element
* Enter text into an element, using a locator
* @param findBy locator of element
* @param text text to enter
*/
fun enterText(findBy: By, text: String) {
enterText(readyElement(findBy), text);
}

/**
* Retrieve the text from an element, using a locator
*
* @param findBy locator of target element
*/
fun getText(findBy: By): String {
return readyElement(findBy).getText();
return getText(existingElement(findBy));
}

/**
* Retrieve an attribute value from an element
* Retrieve the text from an element
*
* @param webElement target element
*/
fun getText(webElement: WebElement): String {
scrollIntoView(webElement);
waitForElementReady(webElement);
return webElement.getText();
}

/**
* Retrieve an attribute value from an element, by locator
*
* @param findBy locator of target element
* @param attribute name of attribute to query
*/
fun getAttribute(findBy: By, attribute: String): String {
return existingElement(findBy).getAttribute(attribute);
return getAttribute(existingElement(findBy), attribute);
}

/**
* Retrieve an attribute value from an element
*
* @param webElement target element
* @param attribute name of attribute to query
*/
fun getAttribute(webElement: WebElement, attribute: String): String {
return webElement.getAttribute(attribute);
}


/**
* 'Touch' a text field to see if it's writable. For cases where fields are
* available but briefly won't accept text for some reason
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class CorePage extends AbstractPage {
private By homeLink = By.id("nav_home");
private By moreLink = By.id("nav_more");

protected static final By h3Header = By.tagName("h3");
protected static final By paragraph = By.tagName("p");

public CorePage(WebDriver driver) {
super(driver);
assertNoCriticalErrors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,40 @@
public class AddLanguagePage extends BasePage {
private static final org.slf4j.Logger log =
org.slf4j.LoggerFactory.getLogger(AddLanguagePage.class);

private By saveButton = By.id("btn-new-language-save");
private By localeId = By.className("react-autosuggest__input");
private By suggestList =
By.className("react-autosuggest__suggestions-list");
private By suggestRow = By.className("react-autosuggest__suggestion");
private By enabledByDefaultCheckbox = By.id("chk-new-language-enabled");
private By pluralsWarning = By.id("new-language-pluralforms-warning");
private By languageOption = By.name("new-language-displayName");
private By newLanguageName = By.id("new-language-name");
private By newLanguageNativeName = By.id("new-language-nativeName");

public AddLanguagePage(final WebDriver driver) {
super(driver);
}

/**
* Enter a string into the language search field
* @param language string to enter
* @return new AddLanguagePage
*/
public AddLanguagePage enterSearchLanguage(String language) {
log.info("Enter language {}", language);
enterText(readyElement(localeId), language);
enterText(localeId, language);
// Pause for a moment, as quick actions can break here
slightPause();
return new AddLanguagePage(getDriver());
}

/**
* Select a language from the search dropdown
* @param language option to select
* @return new AddLanguagePage
*/
public AddLanguagePage selectSearchLanguage(final String language) {
log.info("Select language {}", language);
waitForAMoment().withMessage("language to be clicked")
Expand All @@ -59,8 +73,8 @@ public AddLanguagePage selectSearchLanguage(final String language) {
existingElement(suggestList).findElements(suggestRow);
boolean clickedLanguage = false;
for (WebElement row : suggestions) {
if (row.findElement(By.name("new-language-displayName"))
.getText().contains(language)) {
if (existingElement(row, languageOption).getText()
.contains(language)) {
row.click();
clickedLanguage = true;
break;
Expand All @@ -71,13 +85,21 @@ public AddLanguagePage selectSearchLanguage(final String language) {
return new AddLanguagePage(getDriver());
}

/**
* Wait for the plurals warning to show
* @return new AddLanguagePage
*/
public AddLanguagePage expectPluralsWarning() {
log.info("Expect plurals warning");
waitForPageSilence();
readyElement(pluralsWarning);
return new AddLanguagePage(getDriver());
}

/**
* Click Enable by default if not already enabled
* @return new AddLanguagePage
*/
public AddLanguagePage enableLanguageByDefault() {
log.info("Click Enable by default");
if (!readyElement(enabledByDefaultCheckbox).isSelected()) {
Expand All @@ -86,6 +108,10 @@ public AddLanguagePage enableLanguageByDefault() {
return new AddLanguagePage(getDriver());
}

/**
* Click Disable by default if not already disabled
* @return new AddLanguagePage
*/
public AddLanguagePage disableLanguageByDefault() {
log.info("Click Disable by default");
if (readyElement(enabledByDefaultCheckbox).isSelected()) {
Expand All @@ -94,20 +120,34 @@ public AddLanguagePage disableLanguageByDefault() {
return new AddLanguagePage(getDriver());
}

/**
* Retrieve the name for the new language
* @return String language name
*/
public String getNewLanguageName() {
return existingElement(By.id("new-language-name"))
.getAttribute("value");
return getAttribute(newLanguageName, "value");
}

/**
* Retrieve the native name for the new language
* @return String native language name
*/
public String getNewLanguageNativeName() {
return existingElement(By.id("new-language-nativeName"))
.getAttribute("value");
return getAttribute(newLanguageNativeName, "value");
}

/**
* Retrieve the locale code for the new language
* @return String language locale code
*/
public String getNewLanguageCode() {
return existingElement(localeId).getAttribute("value");
return getAttribute(localeId, "value");
}

/**
* Press the Save button
* @return new LanguagesPage
*/
public LanguagesPage saveLanguage() {
log.info("Click Save");
clickAndCheckErrors(readyElement(saveButton));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
public class AdministrationPage extends BasePage {
private static final org.slf4j.Logger log =
org.slf4j.LoggerFactory.getLogger(AdministrationPage.class);

private final By CONFIGURE_SERVER_LINK =
By.id("Admin_Server_configuration_home");
private final By MANAGE_USER_LINK = By.id("Admin_Manage_users_home");
Expand All @@ -39,29 +40,50 @@ public AdministrationPage(WebDriver driver) {
super(driver);
}

/**
* Click the Server Configuration button
* @return new ServerConfigurationPage
*/
public ServerConfigurationPage goToServerConfigPage() {
log.info("Click Server Configuration");
clickLinkAfterAnimation(CONFIGURE_SERVER_LINK);
return new ServerConfigurationPage(getDriver());
}

/**
* Click the Manage Users button
* @return new ManageUserPage
*/
public ManageUserPage goToManageUserPage() {
log.info("Click Manage Users");
clickLinkAfterAnimation(MANAGE_USER_LINK);
return new ManageUserPage(getDriver());
}

/**
* Click the Translation Memory button
* @return new TranslationMemoryPage
*/
public TranslationMemoryPage goToTranslationMemoryPage() {
log.info("Click Translation Memory");
clickLinkAfterAnimation(MANAGE_TM_LINK);
return new TranslationMemoryPage(getDriver());
}

/**
* Click the Manage Search button
* @return new ManageSearchPage
*/
public ManageSearchPage goToManageSeachPage() {
log.info("Click Manage Search");
clickLinkAfterAnimation(MANAGE_SEARCH_LINK);
return new ManageSearchPage(getDriver());
}

/**
* Click the Manage Roles button
* @return new RoleAssignmentsPage
*/
public RoleAssignmentsPage goToManageRoleAssignments() {
log.info("Click Manage Roles");
clickLinkAfterAnimation(MANAGE_ROLES_ASSIGN_LINK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
public class CreateUserAccountPage extends BasePage {
private static final org.slf4j.Logger log =
org.slf4j.LoggerFactory.getLogger(CreateUserAccountPage.class);

private By usernameField = By.id("newUserForm:username:input:username");
private By emailField = By.id("newUserForm:email:input:email");
private By saveButton = By.id("newUserForm:newUserSave");
Expand All @@ -52,40 +53,73 @@ public CreateUserAccountPage(WebDriver driver) {
roleMap.put("user", "4");
}

/**
* Enter text into the username field
* @param username string to enter
* @return new CreateUserAccountPage
*/
public CreateUserAccountPage enterUsername(String username) {
enterText(readyElement(usernameField), username);
log.info("Enter username {}", username);
enterText(usernameField, username);
return new CreateUserAccountPage(getDriver());
}

/**
* Enter text into the email address field
* @param email string to enter
* @return new CreateUserAccountPage
*/
public CreateUserAccountPage enterEmail(String email) {
enterText(readyElement(emailField), email);
enterText(emailField, email);
return new CreateUserAccountPage(getDriver());
}

/**
* Select a role for the user
* @param role entry to select
* @return new CreateUserAccountPage
*/
public CreateUserAccountPage clickRole(String role) {
log.info("Click role {}", role);
clickElement(readyElement(By.id(roleIdPrefix.concat(roleMap.get(role)))));
clickElement(By.id(roleIdPrefix.concat(roleMap.get(role))));
return new CreateUserAccountPage(getDriver());
}

/**
* Query if a role is checked
* @param role entry to query
* @return new CreateUserAccountPage
*/
public boolean isRoleChecked(String role) {
log.info("Query is role {} checked", role);
return readyElement(By.id(roleIdPrefix.concat(roleMap.get(role))))
.isSelected();
}

/**
* Press the Save button
* @return new ManageUserPage
*/
public ManageUserPage saveUser() {
log.info("Click Save");
clickElement(saveButton);
return new ManageUserPage(getDriver());
}

/**
* Press the Save button, expecting a failure condition
* @return new CreateUserAccountPage
*/
public CreateUserAccountPage saveUserExpectFailure() {
log.info("Click Save");
log.info("Click Save, expecting faiure");
clickElement(saveButton);
return new CreateUserAccountPage(getDriver());
}

/**
* Press the Cancel button
* @return new ManageUserPage
*/
public ManageUserPage cancelEditUser() {
log.info("Click Cancel");
clickElement(cancelButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,40 @@
public class EditHomeContentPage extends BasePage {
private static final org.slf4j.Logger log =
org.slf4j.LoggerFactory.getLogger(EditHomeContentPage.class);

private By updateButton = By.id("homeContentForm:update");
private By cancelButton = By.id("homeContentForm:cancel");
private By homeContent = By.id("homeContentForm:homeContent");

public EditHomeContentPage(final WebDriver driver) {
super(driver);
}

/**
* Enter text into the content editing panel
* @param text string to enter
* @return new EditHomeContentPage
*/
public EditHomeContentPage enterText(String text) {
log.info("Enter homepage code\n{}", text);
readyElement(By.id("homeContentForm:homeContent")).sendKeys(text);
enterText(homeContent, text);
return new EditHomeContentPage(getDriver());
}

/**
* Press the Update button
* @return new HomePage
*/
public HomePage update() {
log.info("Click Update");
clickElement(updateButton);
return new HomePage(getDriver());
}

/**
* Press the Cancel button
* @return new HomePage
*/
public HomePage cancelUpdate() {
log.info("Click Cancel");
clickElement(cancelButton);
Expand Down
Loading

0 comments on commit 0800493

Please sign in to comment.