Skip to content

Commit

Permalink
Selenium: cover the Create New Workspace page by selenium test (#8099)
Browse files Browse the repository at this point in the history
* created CreateWorkspaceTest selenium test
  • Loading branch information
Sergey Skorik authored and dmytro-ndp committed Dec 28, 2017
1 parent c67334a commit d39c31e
Show file tree
Hide file tree
Showing 6 changed files with 460 additions and 50 deletions.
Expand Up @@ -14,6 +14,7 @@
md-on-remove="cheStackLibraryFilterCtrl.onRemove()"
md-separator-keys="cheStackLibraryFilterCtrl.keys">
<input type="text"
id="filter-stack-input"
ng-model="cheStackLibraryFilterCtrl.chip"
ng-change="cheStackLibraryFilterCtrl.querySearch(cheStackLibraryFilterCtrl.chip)"/>
<md-chip-template>
Expand All @@ -30,14 +31,16 @@
</div>
<div layout="row" flex="100" layout-align="start center" class="stack-library-filter-suggestions-row" ng-class="{'stack-library-filter-hidden': !cheStackLibraryFilterCtrl.suggestions.length}">
<label flex="25">Suggestions: </label>
<div layout="column" flex="85">
<div layout="column" flex="85" name="filterSuggestion">
<md-chips ng-model="cheStackLibraryFilterCtrl.suggestions"
class="stack-library-filter-suggestions"
readonly="true">
<md-chip-template>
<div class="stack-library-filter-suggestion-text"
name="suggestionText"
ng-dblclick="cheStackLibraryFilterCtrl.onSelectSuggestion($chip)">{{$chip | uppercase}}</div>
<div class="stack-library-filter-suggestion-btn"
name="suggestionButton"
ng-click="cheStackLibraryFilterCtrl.onSelectSuggestion($chip)">
<i class="fa fa-plus"></i>
</div>
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/components/widget/input/che-input-box.html
Expand Up @@ -15,7 +15,7 @@
ng-class="myForm[inputName] && myForm[inputName].$invalid ? 'fa-times' : 'fa-check'"></span>
</div>
<!-- display error messages for the form -->
<div ng-messages="myForm[inputName].$error" ng-transclude></div>
<div ng-messages="myForm[inputName].$error" id="new-workspace-error-message" ng-transclude></div>
</div>
</div>
<div hide-xs hide-sm flex layout="raw">
Expand Down
Expand Up @@ -25,6 +25,7 @@ public enum TestStacksConstants {
BITNAMI_SWIFT("bitnami-swift", "Bitnami Swift"),
CPP("cpp-default", "C++"),
DOTNET("dotnet-default", ".NET"),
ECLIPSE_CHE("che-in-che", "Eclipse Che"),
NODE("node-default", "Node"),
PHP("php-default", "PHP"),
PYTHON("python-default", "Python"),
Expand Down
Expand Up @@ -11,17 +11,17 @@
package org.eclipse.che.selenium.pageobject.dashboard;

import static java.lang.String.format;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.LOADER_TIMEOUT_SEC;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.REDRAW_UI_ELEMENTS_TIMEOUT_SEC;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.action.ActionsFactory;
import org.eclipse.che.selenium.core.utils.WaitUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;
Expand All @@ -31,29 +31,54 @@
public class CreateWorkspace {

private final SeleniumWebDriver seleniumWebDriver;
private final WebDriverWait redrawUiElementsTimeout;
private final ActionsFactory actionsFactory;

@Inject
public CreateWorkspace(SeleniumWebDriver seleniumWebDriver) {
public CreateWorkspace(SeleniumWebDriver seleniumWebDriver, ActionsFactory actionsFactory) {
this.seleniumWebDriver = seleniumWebDriver;
this.actionsFactory = actionsFactory;
this.redrawUiElementsTimeout =
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC);
PageFactory.initElements(seleniumWebDriver, this);
}

private interface Locators {
String TOOLBAR_TITLE_ID = "New_Workspace";
String WORKSPACE_NAME_INPUT = "workspace-name-input";
String ERROR_MESSAGE = "new-workspace-error-message";
String TOOLBAR_TITLE_ID = "New_Workspace";
String CREATE_BUTTON = "create-workspace-button";
String SELECT_ALL_STACKS_TAB = "all-stacks-button";
String SELECT_QUICK_START_STACKS_TAB = "quick-start-button";
String SELECT_SINGLE_MACHINE_STACKS_TAB = "single-machine-button";
String SELECT_MULTI_MACHINE_STACKS_TAB = "multi-machine-button";
String ADD_STACK_BUTTON = "search-stack-input";
String FILTER_STACK_BUTTON = "search-stack-input";
String SEARCH_INPUT = "search-stack-input";
String FILTERS_STACK_BUTTON = "filter-stacks-button";
String FILTER_STACK_INPUT = "filter-stack-input";
String FILTER_SUGGESTION_TEXT =
"//div[contains(@class,'stack-library-filter-suggestion-text')]";
String FILTER_SUGGESTION_BUTTON =
"//div[@name='suggestionText' and text()='%s']/../div[@name='suggestionButton']";
String FILTER_SELECTED_SUGGESTION_BUTTON = "//button[@class='md-chip-remove ng-scope']";
String SEARCH_INPUT = "//div[@id='search-stack-input']//input";
String CLEAR_INPUT = "//div[@id='search-stack-input']//div[@role='button']";
String STACK_ROW_XPATH = "//div[@data-stack-id='%s']";
String RAM_INPUT_XPATH = "//input[@name='memory']";
String MACHINE_RAM_ID = "machine-%s-ram";
String MACHINE_NAME =
"//span[contains(@class,'ram-settings-machine-item-item-name') and text()='%s']";
String MACHINE_IMAGE = "//span[@class='ram-settings-machine-item-secondary-color']";
String DECREMENT_MEMORY_BUTTON =
"//*[@id='machine-%s-ram']//button[@aria-label='Decrement memory']";
String INCREMENT_MEMORY_BUTTON =
"//*[@id='machine-%s-ram']//button[@aria-label='Increment memory']";
String MACHINE_RAM_VALUE = "//*[@id='machine-%s-ram']//input";
}

@FindBy(id = Locators.FILTERS_STACK_BUTTON)
WebElement filtersStackButton;

@FindBy(id = Locators.FILTER_STACK_INPUT)
WebElement filterStackInput;

@FindBy(id = Locators.TOOLBAR_TITLE_ID)
WebElement toolbarTitle;

Expand All @@ -63,9 +88,12 @@ private interface Locators {
@FindBy(id = Locators.CREATE_BUTTON)
WebElement createWorkspaceButton;

@FindBy(id = Locators.SEARCH_INPUT)
@FindBy(xpath = Locators.SEARCH_INPUT)
WebElement searchInput;

@FindBy(xpath = Locators.CLEAR_INPUT)
WebElement clearInput;

@FindBy(id = Locators.SELECT_ALL_STACKS_TAB)
WebElement selectAllStacksTab;

Expand All @@ -78,71 +106,148 @@ private interface Locators {
@FindBy(id = Locators.SELECT_MULTI_MACHINE_STACKS_TAB)
WebElement selectMultiMachineStacksTab;

public void waitToolbar() {
new WebDriverWait(seleniumWebDriver, LOADER_TIMEOUT_SEC)
.until(visibilityOfElementLocated(By.id(Locators.TOOLBAR_TITLE_ID)));
public void typeWorkspaceName(String name) {
redrawUiElementsTimeout.until(visibilityOf(workspaceNameInput));
workspaceNameInput.clear();
workspaceNameInput.sendKeys(name);
WaitUtils.sleepQuietly(1);
}

public void typeToSearchInput(String value) {
searchInput.sendKeys(value);
public String getWorkspaceNameValue() {
return workspaceNameInput.getAttribute("value");
}

public void selectStack(String stackId) {
WebElement stack =
seleniumWebDriver.findElement(By.xpath(format(Locators.STACK_ROW_XPATH, stackId)));
new Actions(seleniumWebDriver).moveToElement(stack).perform();
stack.click();
public boolean isWorkspaceNameErrorMessageEquals(String message) {
return redrawUiElementsTimeout
.until(visibilityOfElementLocated(By.id(Locators.ERROR_MESSAGE)))
.getText()
.equals(message);
}

public void clickOnCreateWorkspaceButton() {
createWorkspaceButton.click();
public boolean isMachineExists(String machineName) {
return seleniumWebDriver
.findElements(By.xpath(format(Locators.MACHINE_NAME, machineName)))
.size()
> 0;
}

public void typeWorkspaceName(String name) {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(visibilityOf(workspaceNameInput));
workspaceNameInput.clear();
workspaceNameInput.sendKeys(name);
public void clickOnIncrementMemoryButton(String machineName) {
redrawUiElementsTimeout
.until(
visibilityOfElementLocated(
By.xpath(format(Locators.INCREMENT_MEMORY_BUTTON, machineName))))
.click();
}

public String getWorkspaceNameValue() {
return workspaceNameInput.getAttribute("value");
public void clickOnDecrementMemoryButton(String machineName) {
redrawUiElementsTimeout
.until(
visibilityOfElementLocated(
By.xpath(format(Locators.DECREMENT_MEMORY_BUTTON, machineName))))
.click();
}

public double getRAM(String machineName) {
String s =
seleniumWebDriver
.findElement(By.xpath(format(Locators.MACHINE_RAM_VALUE, machineName)))
.getAttribute("value");
return Double.parseDouble(s);
}

public void setMachineRAM(String value) {
WebElement ramInput = seleniumWebDriver.findElement(By.xpath(Locators.RAM_INPUT_XPATH));
WebElement ramInput = seleniumWebDriver.findElement(By.xpath(Locators.MACHINE_RAM_VALUE));
ramInput.clear();
ramInput.sendKeys(value);
}

public void setMachineRAM(String machine, String value) {
public void setMachineRAM(String machineName, double value) {
WebElement ramInput =
seleniumWebDriver.findElement(By.id(format(Locators.MACHINE_RAM_ID, machine)));
seleniumWebDriver.findElement(By.xpath(format(Locators.MACHINE_RAM_VALUE, machineName)));
ramInput.clear();
ramInput.sendKeys(value);
ramInput.sendKeys(Double.toString(value));
}

public void clickOnFiltersButton() {
redrawUiElementsTimeout.until(visibilityOf(filtersStackButton)).click();
}

public void typeToFiltersInput(String value) {
redrawUiElementsTimeout.until(visibilityOf(filterStackInput)).sendKeys(value);
}

public String getTextFromFiltersInput() {
return filterStackInput.getAttribute("value");
}

public void clearSuggestions() {
WebElement webElement =
redrawUiElementsTimeout.until(
visibilityOfElementLocated(By.xpath(Locators.FILTER_SELECTED_SUGGESTION_BUTTON)));
webElement.click();
}

public void selectFilterSuggestion(String suggestion) {
WebElement webElement =
redrawUiElementsTimeout.until(
visibilityOfElementLocated(
By.xpath(format(Locators.FILTER_SUGGESTION_BUTTON, suggestion))));
webElement.click();
}

public void waitToolbar() {
redrawUiElementsTimeout.until(visibilityOfElementLocated(By.id(Locators.TOOLBAR_TITLE_ID)));
}

public String getTextFromSearchInput() {
return searchInput.getAttribute("value");
}

public void typeToSearchInput(String value) {
redrawUiElementsTimeout.until(visibilityOf(searchInput)).clear();
searchInput.sendKeys(value);
}

public void clearTextInSearchInput() {
redrawUiElementsTimeout.until(visibilityOf(clearInput)).click();
}

public boolean isStackVisible(String stackName) {
return seleniumWebDriver
.findElements(By.xpath(format(Locators.STACK_ROW_XPATH, stackName)))
.size()
> 0;
}

public void selectStack(String stackId) {
WebElement stack =
redrawUiElementsTimeout.until(
visibilityOfElementLocated(By.xpath(format(Locators.STACK_ROW_XPATH, stackId))));
actionsFactory.createAction(seleniumWebDriver).moveToElement(stack).perform();
stack.click();
}

public boolean isCreateWorkspaceButtonEnabled() {
return !Boolean.valueOf(createWorkspaceButton.getAttribute("aria-disabled"));
}

public void clickOnCreateWorkspaceButton() {
createWorkspaceButton.click();
}

public void clickOnAllStacksTab() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(visibilityOf(selectAllStacksTab))
.click();
redrawUiElementsTimeout.until(visibilityOf(selectAllStacksTab)).click();
}

public void clickOnQuickStartTab() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(visibilityOf(selectQuickStartStacksTab))
.click();
redrawUiElementsTimeout.until(visibilityOf(selectQuickStartStacksTab)).click();
}

public void clickOnSingleMachineTab() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(visibilityOf(selectSingleMachineStacksTab))
.click();
redrawUiElementsTimeout.until(visibilityOf(selectSingleMachineStacksTab)).click();
}

public void clickOnMultiMachineTab() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(visibilityOf(selectMultiMachineStacksTab))
.click();
redrawUiElementsTimeout.until(visibilityOf(selectMultiMachineStacksTab)).click();
}
}

0 comments on commit d39c31e

Please sign in to comment.