Skip to content

Commit

Permalink
Fix bug in AskForValueDialog in typeAndWaitText method (#7545)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohrimenko1988 committed Nov 24, 2017
1 parent ba9ff8b commit e9e3cae
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 39 deletions.
Expand Up @@ -10,7 +10,10 @@
*/
package org.eclipse.che.selenium.pageobject;

import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.LOAD_PAGE_TIMEOUT_SEC;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.REDRAW_UI_ELEMENTS_TIMEOUT_SEC;
import static org.openqa.selenium.support.ui.ExpectedConditions.invisibilityOfElementLocated;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;

import com.google.inject.Inject;
import com.google.inject.Singleton;
Expand All @@ -23,7 +26,6 @@
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

/** @author Vitaliy Gulyy */
Expand Down Expand Up @@ -96,6 +98,8 @@ public enum JavaFiles {
WebElement errorLabelJava;

private final SeleniumWebDriver seleniumWebDriver;
private final WebDriverWait loadPageWait;
private final WebDriverWait redrawElementWait;
private final Loader loader;

@Inject
Expand All @@ -104,82 +108,83 @@ public AskForValueDialog(
this.seleniumWebDriver = seleniumWebDriver;
this.loader = loader;
this.actionsFactory = actionsFactory;
this.loadPageWait = new WebDriverWait(seleniumWebDriver, LOAD_PAGE_TIMEOUT_SEC);
this.redrawElementWait = new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC);
PageFactory.initElements(seleniumWebDriver, this);
}

public void waitFormToOpen() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOf(form));
redrawElementWait.until(visibilityOf(form));
}

public void waitFormToClose() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.invisibilityOfElementLocated(By.id(ASK_FOR_VALUE_FORM)));
redrawElementWait.until(invisibilityOfElementLocated(By.id(ASK_FOR_VALUE_FORM)));
loader.waitOnClosed();
}

/** click ok button */
public void clickOkBtn() {
okBtn.click();
loadPageWait.until(visibilityOf(okBtn)).click();
waitFormToClose();
}

/** click cancel button */
public void clickCancelBtn() {
cancelBtn.click();
loadPageWait.until(visibilityOf(cancelBtn)).click();
waitFormToClose();
}

public void clickCancelButtonJava() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOf(cancelButtonJava))
.click();
redrawElementWait.until(visibilityOf(cancelButtonJava)).click();
}

public void typeAndWaitText(String text) {
input.sendKeys(text);
loadPageWait.until(visibilityOf(input)).sendKeys(text);
waitInputNameContains(text);
}

public void waitNewJavaClassOpen() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOf(newJavaClass));
redrawElementWait.until(visibilityOf(newJavaClass));
}

public void waitNewJavaClassClose() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.invisibilityOfElementLocated(By.id(NEW_JAVA_CLASS_FORM)));
redrawElementWait.until(invisibilityOfElementLocated(By.id(NEW_JAVA_CLASS_FORM)));
}

public void clickOkBtnNewJavaClass() {
okBtnnewJavaClass.click();
loadPageWait.until(visibilityOf(okBtnnewJavaClass)).click();
loader.waitOnClosed();
}

public void typeTextInFieldName(String text) {
inputNameJavaClass.sendKeys(text);
loadPageWait.until(visibilityOf(inputNameJavaClass)).sendKeys(text);
waitTextInFieldName(text);
}

public void waitTextInFieldName(String expectedText) {
loadPageWait.until(
(ExpectedCondition<Boolean>)
driver ->
loadPageWait
.until(visibilityOf(inputNameJavaClass))
.getAttribute("value")
.contains(expectedText));
}

public void deleteNameFromDialog() {
input.clear();
loadPageWait.until(visibilityOf(input)).clear();
}

/** select interface item from dropdown */
public void selectInterfaceItemFromDropDown() {
new WebDriverWait(seleniumWebDriver, 7).until(ExpectedConditions.visibilityOf(type));
type.click();
new WebDriverWait(seleniumWebDriver, 7)
.until(ExpectedConditions.elementToBeClickable(By.xpath(INTERFACE_ITEM)));
interfaceItem.click();
loadPageWait.until(visibilityOf(type)).click();
loadPageWait.until(visibilityOf(interfaceItem)).click();
}

/** select enum item from dropdown */
public void selectEnumItemFromDropDown() {
new WebDriverWait(seleniumWebDriver, 7).until(ExpectedConditions.visibilityOf(type));
type.click();
new WebDriverWait(seleniumWebDriver, 7)
.until(ExpectedConditions.elementToBeClickable(By.xpath(ENUM_ITEM)));
enumItem.click();
loadPageWait.until(visibilityOf(type)).click();
loadPageWait.until(visibilityOf(enumItem)).click();
}

public void createJavaFileByNameAndType(String name, JavaFiles javaFileType) {
Expand All @@ -199,14 +204,13 @@ public void createJavaFileByNameAndType(String name, JavaFiles javaFileType) {

/** wait expected text */
public void waitInputNameContains(final String expectedText) {
new WebDriverWait(seleniumWebDriver, 3)
.until(
(ExpectedCondition<Boolean>)
webDriver ->
seleniumWebDriver
.findElement(By.id(INPUT))
.getAttribute("value")
.contains(expectedText));
loadPageWait.until(
(ExpectedCondition<Boolean>)
webDriver ->
seleniumWebDriver
.findElement(By.id(INPUT))
.getAttribute("value")
.contains(expectedText));
}

public void createNotJavaFileByName(String name) {
Expand All @@ -217,17 +221,17 @@ public void createNotJavaFileByName(String name) {
/** clear the input box */
public void clearInput() {
waitFormToOpen();
input.clear();
loadPageWait.until(visibilityOf(input)).clear();
}

/** Wait for error message */
public boolean waitErrorMessage() {
new WebDriverWait(seleniumWebDriver, 5).until(ExpectedConditions.visibilityOf(errorLabel));
loadPageWait.until(visibilityOf(errorLabel));
return "Name is invalid".equals(errorLabel.getText());
}

public void waitErrorMessageInJavaClass() {
new WebDriverWait(seleniumWebDriver, 5).until(ExpectedConditions.visibilityOf(errorLabelJava));
loadPageWait.until(visibilityOf(errorLabelJava));
}

public boolean isWidgetNewJavaClassIsOpened() {
Expand Down
Expand Up @@ -79,6 +79,7 @@ public void checkAutocompleteJSFilesTest() {
TestMenuCommandsConstants.Project.PROJECT,
TestMenuCommandsConstants.Project.New.NEW,
TestMenuCommandsConstants.Project.New.JAVASCRIPT_FILE);
askForValueDialog.waitFormToOpen();
askForValueDialog.typeAndWaitText("newJsFile");
askForValueDialog.clickOkBtn();
loader.waitOnClosed();
Expand Down
Expand Up @@ -175,6 +175,7 @@ public void createNewFile(String name, String pathToFile, String type) throws Ex
projectExplorer.openContextMenuByPathSelectedItem(pathToFile);
projectExplorer.clickOnItemInContextMenu(TestProjectExplorerContextMenuConstants.NEW);
projectExplorer.clickOnItemInContextMenu(type);
askForValueDialog.waitFormToOpen();
askForValueDialog.typeAndWaitText(name);
askForValueDialog.clickOkBtn();
}
Expand Down
Expand Up @@ -131,6 +131,7 @@ private void createNewFile(String name, String pathToFile, String type) throws E
projectExplorer.openContextMenuByPathSelectedItem(pathToFile);
projectExplorer.clickOnItemInContextMenu(TestProjectExplorerContextMenuConstants.NEW);
projectExplorer.clickOnItemInContextMenu(type);
askForValueDialog.waitFormToOpen();
askForValueDialog.typeAndWaitText(name);
askForValueDialog.clickOkBtn();
}
Expand Down
Expand Up @@ -172,6 +172,7 @@ public void checkRunPlainJavaProject() {
projectExplorer.clickOnItemInContextMenu(TestProjectExplorerContextMenuConstants.NEW);
projectExplorer.clickOnNewContextMenuItem(
TestProjectExplorerContextMenuConstants.SubMenuNew.FOLDER);
askForValueDialog.waitFormToOpen();
askForValueDialog.typeAndWaitText("bin");
askForValueDialog.clickOkBtn();
loader.waitOnClosed();
Expand Down
Expand Up @@ -130,6 +130,7 @@ public void createNewFile(String name, String type, String fileExt) throws Excep
projectExplorer.openContextMenuByPathSelectedItem(PATH_TO_FILES);
projectExplorer.clickOnItemInContextMenu(TestProjectExplorerContextMenuConstants.NEW);
projectExplorer.clickOnItemInContextMenu(type);
askForValueDialog.waitFormToOpen();
askForValueDialog.typeAndWaitText(name);
askForValueDialog.clickOkBtn();
loader.waitOnClosed();
Expand Down
Expand Up @@ -144,6 +144,7 @@ private void createNewFile(String pathFromItem, String name, String type, String
projectExplorer.selectItem(pathFromItem);
menu.runCommand(
TestMenuCommandsConstants.Project.PROJECT, TestMenuCommandsConstants.Project.New.NEW, type);
askForValueDialog.waitFormToOpen();
askForValueDialog.typeAndWaitText(name);
askForValueDialog.clickOkBtn();
loader.waitOnClosed();
Expand Down
Expand Up @@ -148,6 +148,7 @@ private void createAndCheckNewFile(
projectExplorer.openContextMenuByPathSelectedItem(projectName);
projectExplorer.clickOnItemInContextMenu(TestProjectExplorerContextMenuConstants.NEW);
projectExplorer.clickOnItemInContextMenu(type);
askForValueDialog.waitFormToOpen();
askForValueDialog.typeAndWaitText(fileName);
askForValueDialog.clickOkBtn();
loader.waitOnClosed();
Expand Down

0 comments on commit e9e3cae

Please sign in to comment.