[Selenium] Fix unexpected fail of "AutocompleteFeaturesInEditorTest" selenium test (#11565)

6.19.x
Igor Ohrimenko 2018-10-11 10:31:15 +03:00 committed by GitHub
parent 534a961e84
commit 915e9ffbf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 6 deletions

View File

@ -12,6 +12,8 @@
package org.eclipse.che.selenium.pageobject;
import static java.lang.String.format;
import static org.eclipse.che.selenium.pageobject.FileStructure.Locators.FILE_STRUCTURE_ITEM;
import static org.eclipse.che.selenium.pageobject.FileStructure.Locators.SELECTED_FILE_STRUCTURE_ITEM_XPATH_TEMPLATE;
import static org.openqa.selenium.Keys.CONTROL;
import static org.openqa.selenium.Keys.ENTER;
import static org.openqa.selenium.Keys.ESCAPE;
@ -46,7 +48,7 @@ public class FileStructure {
PageFactory.initElements(seleniumWebDriver, this);
}
private interface Locators {
public interface Locators {
String FILE_STRUCTURE_FORM = "//table[@title='%s.java']";
String FILE_STRUCTURE_CLOSE_ICON = "gwt-debug-file-structure-windowFrameCloseButton";
String FILE_STRUCTURE_CONTENT = "gwt-debug-file-structure-mainPanel";
@ -54,6 +56,8 @@ public class FileStructure {
"(//div[text()='%s']/preceding::*[local-name()='svg'][2])[last()]";
String FILE_STRUCTURE_ITEM =
"//div[@id='gwt-debug-file-structure-mainPanel']//div[text()='%s']";
String SELECTED_FILE_STRUCTURE_ITEM_XPATH_TEMPLATE =
"//div[@id='gwt-debug-file-structure-mainPanel']//div[contains(@class, 'selected')]//div[text()='%s']";
}
@FindBy(id = Locators.FILE_STRUCTURE_CONTENT)
@ -140,11 +144,13 @@ public class FileStructure {
* @param item is the name of the item
*/
public void selectItemInFileStructureByDoubleClick(String item) {
final String itemXpath = getItemXpath(item);
// we need to wait a little to avoid node closing after quick clicking
WaitUtils.sleepQuietly(1);
seleniumWebDriverHelper.waitNoExceptions(
() -> seleniumWebDriverHelper.moveCursorToAndDoubleClick(getFileStructureItem(item)),
() -> seleniumWebDriverHelper.moveCursorToAndDoubleClick(By.xpath(itemXpath)),
StaleElementReferenceException.class);
}
@ -163,12 +169,29 @@ public class FileStructure {
* @param item is the name of the item
*/
public void selectItemInFileStructure(String item) {
seleniumWebDriverHelper.waitAndClick(getFileStructureItem(item));
seleniumWebDriverHelper.waitNoExceptions(
() -> selectItem(item), StaleElementReferenceException.class);
}
private WebElement getFileStructureItem(String item) {
return seleniumWebDriverHelper.waitVisibility(
By.xpath(format(Locators.FILE_STRUCTURE_ITEM, item)));
private void selectItem(String visibleItemText) {
final String itemXpath = getItemXpath(visibleItemText);
seleniumWebDriverHelper.waitAndClick(By.xpath(itemXpath));
waitItemSelected(visibleItemText);
}
private String getItemXpath(String item) {
return format(FILE_STRUCTURE_ITEM, item);
}
private String getSelectedItemXpath(String itemText) {
return format(SELECTED_FILE_STRUCTURE_ITEM_XPATH_TEMPLATE, itemText);
}
public void waitItemSelected(String itemText) {
final String selectedItemXpath = getSelectedItemXpath(itemText);
seleniumWebDriverHelper.waitVisibility(By.xpath(selectedItemXpath));
}
/**

View File

@ -28,6 +28,7 @@ import static org.eclipse.che.selenium.pageobject.ProjectExplorer.Locators.COLOU
import static org.eclipse.che.selenium.pageobject.ProjectExplorer.Locators.EXPLORER_RIGHT_TAB_ID;
import static org.eclipse.che.selenium.pageobject.ProjectExplorer.Locators.PROJECT_EXPLORER_ITEM_TEMPLATE;
import static org.eclipse.che.selenium.pageobject.ProjectExplorer.Locators.PROJECT_EXPLORER_TREE_ITEMS;
import static org.eclipse.che.selenium.pageobject.ProjectExplorer.Locators.SELECTED_ITEM_BY_NAME_XPATH_TEMPLATE;
import static org.eclipse.che.selenium.pageobject.ProjectExplorer.ProjectExplorerItemColors.BLUE;
import static org.eclipse.che.selenium.pageobject.ProjectExplorer.ProjectExplorerItemColors.DEFAULT;
import static org.eclipse.che.selenium.pageobject.ProjectExplorer.ProjectExplorerItemColors.GREEN;
@ -182,6 +183,9 @@ public class ProjectExplorer {
String COLOURED_ITEM_TEMPLATE =
"//div[@id='gwt-debug-projectTree']//div[@path='/%s']/descendant::div[@style='%s']";
String MAXIMIZE_BUTTON_XPATH = "(//div[@id='gwt-debug-maximizeButton'])[position()=1]";
String SELECTED_ITEM_BY_NAME_XPATH_TEMPLATE =
"//div[contains(@class, 'selected')]//div[text()='%s']";
// "//div[@name='%s' or @name='%s.class']//div[contains(@class, 'selected')] ";
}
/**
@ -571,7 +575,14 @@ public class ProjectExplorer {
* @param name item's visible name
*/
public void openItemByVisibleNameInExplorer(String name) {
seleniumWebDriverHelper.waitNoExceptions(
() -> openItemByVisibleName(name), StaleElementReferenceException.class);
}
private void openItemByVisibleName(String name) {
waitVisibilityByName(name).click();
waitItemSelectedByName(name);
actionsFactory
.createAction(seleniumWebDriver)
.moveToElement(waitVisibilityByName(name))
@ -1095,6 +1106,12 @@ public class ProjectExplorer {
ELEMENT_TIMEOUT_SEC);
}
public void waitItemSelectedByName(String visibleName) {
final String itemXpath = format(SELECTED_ITEM_BY_NAME_XPATH_TEMPLATE, visibleName);
seleniumWebDriverHelper.waitVisibility(By.xpath(itemXpath));
}
/**
* Waits until all items with specified {@code paths} be selected
*