From e9e3cae795da55b10802042b8c54a8405501f3ca Mon Sep 17 00:00:00 2001 From: Igor Ohrimenko Date: Fri, 24 Nov 2017 15:30:49 +0200 Subject: [PATCH] Fix bug in AskForValueDialog in typeAndWaitText method (#7545) --- .../pageobject/AskForValueDialog.java | 82 ++++++++++--------- .../autocomplete/AutocompleteJSFilesTest.java | 1 + ...ConvertToProjectFromConfigurationTest.java | 1 + .../ConvertToProjectWithPomFileTest.java | 1 + .../plainjava/RunPlainJavaProjectTest.java | 1 + ...ateNewNotJavaFilesFromContextMenuTest.java | 1 + .../CreateNewNotJavaFilesTest.java | 1 + .../CreateProjectsForArtikPluginTest.java | 1 + 8 files changed, 50 insertions(+), 39 deletions(-) diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/AskForValueDialog.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/AskForValueDialog.java index a3cde125c5a..8f8d19b1a8a 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/AskForValueDialog.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/AskForValueDialog.java @@ -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; @@ -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 */ @@ -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 @@ -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) + 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) { @@ -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) - webDriver -> - seleniumWebDriver - .findElement(By.id(INPUT)) - .getAttribute("value") - .contains(expectedText)); + loadPageWait.until( + (ExpectedCondition) + webDriver -> + seleniumWebDriver + .findElement(By.id(INPUT)) + .getAttribute("value") + .contains(expectedText)); } public void createNotJavaFileByName(String name) { @@ -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() { diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/editor/autocomplete/AutocompleteJSFilesTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/editor/autocomplete/AutocompleteJSFilesTest.java index 0cb9a248883..31627032a62 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/editor/autocomplete/AutocompleteJSFilesTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/editor/autocomplete/AutocompleteJSFilesTest.java @@ -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(); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/ConvertToProjectFromConfigurationTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/ConvertToProjectFromConfigurationTest.java index 6ca748623f4..1522be40e53 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/ConvertToProjectFromConfigurationTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/ConvertToProjectFromConfigurationTest.java @@ -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(); } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/ConvertToProjectWithPomFileTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/ConvertToProjectWithPomFileTest.java index 1b30e5234e0..4621974f76c 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/ConvertToProjectWithPomFileTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/miscellaneous/ConvertToProjectWithPomFileTest.java @@ -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(); } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/plainjava/RunPlainJavaProjectTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/plainjava/RunPlainJavaProjectTest.java index 6dcaa20c0d4..830c40b87d1 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/plainjava/RunPlainJavaProjectTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/plainjava/RunPlainJavaProjectTest.java @@ -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(); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateNewNotJavaFilesFromContextMenuTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateNewNotJavaFilesFromContextMenuTest.java index 62081854451..50706aa9b4c 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateNewNotJavaFilesFromContextMenuTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateNewNotJavaFilesFromContextMenuTest.java @@ -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(); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateNewNotJavaFilesTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateNewNotJavaFilesTest.java index f9c8e660cb8..c2549443a20 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateNewNotJavaFilesTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateNewNotJavaFilesTest.java @@ -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(); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateProjectsForArtikPluginTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateProjectsForArtikPluginTest.java index 06c22c64218..764075fd186 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateProjectsForArtikPluginTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/projectexplorer/CreateProjectsForArtikPluginTest.java @@ -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();