Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium: wait that Restart button in ToastLoader is clickable #9389

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,17 @@
*/
package org.eclipse.che.selenium.pageobject;

import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.ELEMENT_TIMEOUT_SEC;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.EXPECTED_MESS_IN_CONSOLE_SEC;
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.eclipse.che.selenium.core.constant.TestTimeoutsConstants.WIDGET_TIMEOUT_SEC;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.concurrent.TimeUnit;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.utils.WaitUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.eclipse.che.selenium.core.webdriver.SeleniumWebDriverHelper;
import org.openqa.selenium.WebElement;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,19 +29,18 @@
public class NotificationsPopupPanel {
private static final Logger LOG = LoggerFactory.getLogger(NotificationsPopupPanel.class);

private final SeleniumWebDriver seleniumWebDriver;
private final SeleniumWebDriverHelper seleniumWebDriverHelper;

@Inject
public NotificationsPopupPanel(SeleniumWebDriver seleniumWebDriver) {
this.seleniumWebDriver = seleniumWebDriver;
public NotificationsPopupPanel(
SeleniumWebDriver seleniumWebDriver, SeleniumWebDriverHelper seleniumWebDriverHelper) {
this.seleniumWebDriverHelper = seleniumWebDriverHelper;
PageFactory.initElements(seleniumWebDriver, this);
}

private static final String PROGRESS_POPUP_PANEL_ID = "gwt-debug-popup-container";
private static final String CLOSE_POPUP_IMG_XPATH =
"//div[@id='gwt-debug-popup-container']/descendant::*[local-name()='svg'][2]";
private static final String RESTART_WORKSPACE_BUTTON =
"//div[@id='gwt-debug-popupLoader']//button[text()='Restart']";

@FindBy(id = PROGRESS_POPUP_PANEL_ID)
private WebElement progressPopupPanel;
Expand All @@ -58,46 +50,22 @@ public NotificationsPopupPanel(SeleniumWebDriver seleniumWebDriver) {

/** wait progress Popup panel appear */
public void waitProgressBarControl() {
new WebDriverWait(seleniumWebDriver, EXPECTED_MESS_IN_CONSOLE_SEC)
.until(ExpectedConditions.visibilityOf(progressPopupPanel));
waitProgressBarControl(EXPECTED_MESS_IN_CONSOLE_SEC);
}

/** wait progress Popup panel appear after timeout defined by user */
public void waitProgressBarControl(int userTimeout) {
new WebDriverWait(seleniumWebDriver, userTimeout)
.until(ExpectedConditions.visibilityOf(progressPopupPanel));
seleniumWebDriverHelper.waitVisibility(progressPopupPanel, userTimeout);
}

/** wait progress Popup panel disappear */
public void waitProgressPopupPanelClose() {
new WebDriverWait(seleniumWebDriver, EXPECTED_MESS_IN_CONSOLE_SEC)
.until(ExpectedConditions.invisibilityOfElementLocated(By.id(PROGRESS_POPUP_PANEL_ID)));
waitProgressPopupPanelClose(EXPECTED_MESS_IN_CONSOLE_SEC);
}

/** wait progress Popup panel disappear after timeout defined by user */
public void waitProgressPopupPanelClose(int userTimeout) {
new WebDriverWait(seleniumWebDriver, userTimeout)
.until(ExpectedConditions.invisibilityOfElementLocated(By.id(PROGRESS_POPUP_PANEL_ID)));
}

/**
* get all text from progress popup panel
*
* @return text from popup panel
*/
public String getAllMessagesFromProgressPopupPanel() {
waitProgressBarControl();
return progressPopupPanel.getText();
}

/**
* get all text from progress popup panel after appearance this with timeout defined by user
*
* @return text from popup panel
*/
public String getAllMessagesFromProgressPopupPanel(int userTimeout) {
waitProgressBarControl(userTimeout);
return progressPopupPanel.getText();
seleniumWebDriverHelper.waitInvisibility(progressPopupPanel, userTimeout);
}

/**
Expand All @@ -106,11 +74,7 @@ public String getAllMessagesFromProgressPopupPanel(int userTimeout) {
* @param message expected text
*/
public void waitExpectedMessageOnProgressPanelAndClosed(final String message) {
new WebDriverWait(seleniumWebDriver, LOADER_TIMEOUT_SEC)
.until(
(ExpectedCondition<Boolean>)
input -> getAllMessagesFromProgressPopupPanel().contains(message));
waitProgressPopupPanelClose();
waitExpectedMessageOnProgressPanelAndClosed(message, ELEMENT_TIMEOUT_SEC);
}

/**
Expand All @@ -120,35 +84,12 @@ public void waitExpectedMessageOnProgressPanelAndClosed(final String message) {
* @param timeout timeout defined by user
*/
public void waitExpectedMessageOnProgressPanelAndClosed(final String message, final int timeout) {
try {
new WebDriverWait(seleniumWebDriver, timeout)
.until(
(ExpectedCondition<Boolean>)
input -> getAllMessagesFromProgressPopupPanel(timeout).contains(message));
} catch (StaleElementReferenceException ex) {
LOG.debug(ex.getLocalizedMessage(), ex);
WaitUtils.sleepQuietly(500, TimeUnit.MILLISECONDS);
new WebDriverWait(seleniumWebDriver, timeout)
.until(ExpectedConditions.textToBePresentInElement(progressPopupPanel, message));
}
seleniumWebDriverHelper.waitTextPresence(progressPopupPanel, message, timeout);
waitProgressPopupPanelClose(timeout);
}

/** wait disappearance of notification popups */
public void waitPopupPanelsAreClosed() {
new WebDriverWait(seleniumWebDriver, WIDGET_TIMEOUT_SEC)
.until(ExpectedConditions.invisibilityOfElementLocated(By.id(PROGRESS_POPUP_PANEL_ID)));
}

public void waitWorkspaceAgentIsNotRunning() {
new WebDriverWait(seleniumWebDriver, WIDGET_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(RESTART_WORKSPACE_BUTTON)));
}

/** click on the Restart workspace button */
public void clickOnRestartWorkspaceButton() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(RESTART_WORKSPACE_BUTTON)))
.click();
seleniumWebDriverHelper.waitInvisibility(progressPopupPanel, WIDGET_TIMEOUT_SEC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.EXPECTED_MESS_IN_CONSOLE_SEC;
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 static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.UPDATING_PROJECT_TIMEOUT_SEC;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.WIDGET_TIMEOUT_SEC;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.utils.WaitUtils;
import org.eclipse.che.selenium.core.webdriver.SeleniumWebDriverHelper;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.TimeoutException;
Expand All @@ -33,37 +33,37 @@
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
* //
*
* @author Musienko Maxim
*/
/** @author Musienko Maxim */
@Singleton
public class ToastLoader {
private final SeleniumWebDriver seleniumWebDriver;
private final SeleniumWebDriverHelper seleniumWebDriverHelper;
private final Loader loader;

@Inject
public ToastLoader(SeleniumWebDriver seleniumWebDriver) {
public ToastLoader(
SeleniumWebDriver seleniumWebDriver,
SeleniumWebDriverHelper seleniumWebDriverHelper,
Loader loader) {
this.seleniumWebDriver = seleniumWebDriver;
this.seleniumWebDriverHelper = seleniumWebDriverHelper;
this.loader = loader;
PageFactory.initElements(seleniumWebDriver, this);
}

private interface Locators {
String MAIN_FORM = "gwt-debug-popupLoader";
String START_BUTTON = "//button[text()='Start']";
String MAINFORM_WITH_TEXT_CONTAINER =
String MAIN_FORM_ID = "gwt-debug-popupLoader";
String TOAST_LOADER_BUTTON_XPATH = "//div[@id='gwt-debug-popupLoader']//button[text()='%s']";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name it TOAST_LOADER_BUTTON_XPATH_PATTERN to make it obvious that it requires modification before usage.

String MAINFORM_WITH_TEXT_CONTAINER_XPATH =
"//div[@id='gwt-debug-popupLoader']/div[contains(text(),'%s')]";
}

@FindBy(id = Locators.MAIN_FORM)
@FindBy(id = Locators.MAIN_FORM_ID)
WebElement mainForm;

@FindBy(xpath = Locators.START_BUTTON)
WebElement startBtn;

/** wait appearance toast loader widget */
public void waitToastLoaderIsOpen() {
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC).until(visibilityOf(mainForm));
seleniumWebDriverHelper.waitVisibility(mainForm, UPDATING_PROJECT_TIMEOUT_SEC);
}

/**
Expand All @@ -72,10 +72,7 @@ public void waitToastLoaderIsOpen() {
* @param expText
*/
public void waitExpectedTextInToastLoader(String expText) {
new WebDriverWait(seleniumWebDriver, EXPECTED_MESS_IN_CONSOLE_SEC)
.until(
visibilityOfElementLocated(
By.xpath(format(Locators.MAINFORM_WITH_TEXT_CONTAINER, expText))));
waitExpectedTextInToastLoader(expText, EXPECTED_MESS_IN_CONSOLE_SEC);
}

/**
Expand All @@ -85,16 +82,13 @@ public void waitExpectedTextInToastLoader(String expText) {
* @param timeout timeout sets in seconds
*/
public void waitExpectedTextInToastLoader(String expText, int timeout) {
new WebDriverWait(seleniumWebDriver, timeout)
.until(
visibilityOfElementLocated(
By.xpath(format(Locators.MAINFORM_WITH_TEXT_CONTAINER, expText))));
seleniumWebDriverHelper.waitVisibility(
By.xpath(format(Locators.MAINFORM_WITH_TEXT_CONTAINER_XPATH, expText)), timeout);
}

/** wait for closing of widget */
public void waitToastLoaderIsClosed() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(invisibilityOfElementLocated(By.id(Locators.MAIN_FORM)));
waitToastLoaderIsClosed(ELEMENT_TIMEOUT_SEC);
}

/**
Expand All @@ -103,8 +97,7 @@ public void waitToastLoaderIsClosed() {
* @param userTimeout timeout defined by user
*/
public void waitToastLoaderIsClosed(int userTimeout) {
new WebDriverWait(seleniumWebDriver, userTimeout)
.until(invisibilityOfElementLocated(By.id(Locators.MAIN_FORM)));
seleniumWebDriverHelper.waitInvisibility(mainForm, userTimeout);
}

/** wait appearance the 'Toast widget' with some text, and wait disappearance this one */
Expand Down Expand Up @@ -188,20 +181,19 @@ public Boolean apply(WebDriver driver) {
}

public String getTextFromToastLoader() {
return new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(visibilityOf(mainForm))
.getText();
return seleniumWebDriverHelper.waitVisibilityAndGetText(mainForm);
}

/** wait appearance of start button in the widget */
public void waitStartButtonInToastLoader() {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
.until(visibilityOf(startBtn));
/** wait appearance of button in the widget */
public void waitToastLoaderButton(String buttonName) {
seleniumWebDriverHelper.waitVisibility(
By.xpath(format(Locators.TOAST_LOADER_BUTTON_XPATH, buttonName)), WIDGET_TIMEOUT_SEC);
}

/** wait appearance of start button in the widget and click on this one */
public void clickOnStartButton() {
waitStartButtonInToastLoader();
startBtn.click();
/** wait appearance of button in the widget and click on this one */
public void clickOnToastLoaderButton(String buttonName) {
loader.waitOnClosed();
seleniumWebDriverHelper.waitAndClick(
By.xpath(format(Locators.TOAST_LOADER_BUTTON_XPATH, buttonName)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
package org.eclipse.che.selenium.miscellaneous;

import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING;
import static org.eclipse.che.commons.lang.NameGenerator.generate;
import static org.eclipse.che.selenium.core.constant.TestCommandsConstants.CUSTOM;
import static org.eclipse.che.selenium.core.constant.TestProjectExplorerContextMenuConstants.ContextMenuCommandGoals.COMMON;
import static org.eclipse.che.selenium.core.project.ProjectTemplates.MAVEN_SPRING;

import com.google.inject.Inject;
import java.net.URL;
import java.nio.file.Paths;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.selenium.core.client.TestCommandServiceClient;
import org.eclipse.che.selenium.core.client.TestProjectServiceClient;
import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClient;
import org.eclipse.che.selenium.core.user.TestUser;
import org.eclipse.che.selenium.core.workspace.TestWorkspace;
import org.eclipse.che.selenium.pageobject.Ide;
import org.eclipse.che.selenium.pageobject.NotificationsPopupPanel;
import org.eclipse.che.selenium.pageobject.ProjectExplorer;
import org.eclipse.che.selenium.pageobject.ToastLoader;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/**
* @author Musienko Maxim
* @author Serhii Skoryk
*/
public class CheckRestoringWorkspaceAfterStoppingWsAgentProcess {
private static final String PROJECT_NAME = NameGenerator.generate("project", 4);
public class CheckRestoringWorkspaceAfterStoppingWsAgentProcessTest {
private static final String PROJECT_NAME = generate("project", 4);
private static final String nameCommandForKillWsAgent = "killWsAgent";
private static final String killPIDWSAgentCommand =
"kill -9 $(ps ax | grep java | grep ws-agent | grep conf | grep -v grep | awk '{print $1}')";
Expand All @@ -47,7 +47,7 @@ public class CheckRestoringWorkspaceAfterStoppingWsAgentProcess {
@Inject private TestCommandServiceClient testCommandServiceClient;
@Inject private TestProjectServiceClient testProjectServiceClient;
@Inject private TestWorkspaceServiceClient testWorkspaceServiceClient;
@Inject private NotificationsPopupPanel notificationsPopupPanel;
@Inject private ToastLoader toastLoader;

@BeforeClass
public void setUp() throws Exception {
Expand All @@ -66,8 +66,10 @@ public void checkRestoreWsAgentByApi() throws Exception {

projectExplorer.invokeCommandWithContextMenu(COMMON, PROJECT_NAME, nameCommandForKillWsAgent);

notificationsPopupPanel.waitWorkspaceAgentIsNotRunning();
notificationsPopupPanel.clickOnRestartWorkspaceButton();
toastLoader.waitToastLoaderIsOpen();
toastLoader.waitExpectedTextInToastLoader("Workspace agent is not running");
toastLoader.clickOnToastLoaderButton("Restart");
toastLoader.waitExpectedTextInToastLoader("Starting workspace runtime...");
testWorkspaceServiceClient.waitStatus(workspace.getName(), defaultTestUser.getName(), RUNNING);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void checkStopStartWorkspaceTest() {
menu.runCommand(WORKSPACE, STOP_WORKSPACE);
toastLoader.waitExpectedTextInToastLoader("Workspace is not running");

toastLoader.clickOnStartButton();
toastLoader.clickOnToastLoaderButton("Start");
ide.waitOpenedWorkspaceIsReadyToUse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void checkStoppingByApi() throws Exception {

@Test
public void checkLoadToasterAfterStopping() {
toastLoader.waitStartButtonInToastLoader();
toastLoader.waitToastLoaderButton("Start");
}

private int getCommonTimeoutInMilliSec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void checkProjectAfterStopStartWs() {
editor.waitTabIsNotPresent("index.jsp");
projectExplorer.waitDisappearItemByPath(PROJECT_NAME);

toastLoader.clickOnStartButton();
toastLoader.clickOnToastLoaderButton("Start");
ide.waitOpenedWorkspaceIsReadyToUse();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<class name="org.eclipse.che.selenium.mavenplugin.GenerateEffectivePomTest"/>
<class name="org.eclipse.che.selenium.miscellaneous.CheckCreatingProjectInEmptyWsTest"/>
<class name="org.eclipse.che.selenium.miscellaneous.CheckMacrosFeatureTest"/>
<class name="org.eclipse.che.selenium.miscellaneous.CheckRestoringWorkspaceAfterStoppingWsAgentProcess"/>
<class name="org.eclipse.che.selenium.miscellaneous.CheckRestoringWorkspaceAfterStoppingWsAgentProcessTest"/>
<class name="org.eclipse.che.selenium.miscellaneous.ConvertToProjectFromConfigurationTest"/>
<class name="org.eclipse.che.selenium.miscellaneous.ConvertToProjectWithPomFileTest"/>
<class name="org.eclipse.che.selenium.miscellaneous.DialogAboutTest"/>
Expand Down