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] Adapt selenium tests from workspaces package #14716

Merged
merged 9 commits into from
Oct 3, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ public void pressKeyCombination(CharSequence... combination) {
seleniumWebDriverHelper.sendKeys(keyCombination);
}

public void waitOpenedWorkspaceIsReadyToUse() {
// switch to the IDE and wait for workspace is ready to use
switchToIdeFrame();
waitTheiaIde();
waitLoaderInvisibility();
waitTheiaIdeTopPanel();
waitAllNotificationsClosed();
}

@PreDestroy
public void close() {
seleniumWebDriver.quit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.che.selenium.pageobject.theia;

import static java.lang.String.format;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.ELEMENT_TIMEOUT_SEC;
import static org.eclipse.che.selenium.pageobject.theia.TheiaProjectTree.Locators.EXPAND_ITEM_ICON_XPATH_TEMPLATE;
import static org.eclipse.che.selenium.pageobject.theia.TheiaProjectTree.Locators.FILES_TAB_ID;
import static org.eclipse.che.selenium.pageobject.theia.TheiaProjectTree.Locators.OPEN_WORKSPACE_BUTTON_XPATH;
Expand Down Expand Up @@ -98,7 +99,7 @@ private String getExpandItemIconXpath(String itemPath) {

public void waitItem(String itemPath) {
String itemId = getProjectItemId(itemPath);
seleniumWebDriverHelper.waitVisibility(By.id(itemId));
seleniumWebDriverHelper.waitVisibility(By.id(itemId), ELEMENT_TIMEOUT_SEC);
}

public void waitItemDisappearance(String itemPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,37 @@

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED;
import static org.eclipse.che.selenium.core.TestGroup.UNDER_REPAIR;
import static org.eclipse.che.commons.lang.NameGenerator.generate;
import static org.eclipse.che.selenium.core.utils.WaitUtils.sleepQuietly;
import static org.testng.Assert.assertEquals;

import com.google.inject.Inject;
import com.google.inject.name.Named;
import java.util.Collections;
import org.eclipse.che.api.core.model.workspace.Workspace;
import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClient;
import org.eclipse.che.selenium.core.requestfactory.TestUserHttpJsonRequestFactory;
import org.eclipse.che.selenium.core.user.DefaultTestUser;
import org.eclipse.che.selenium.core.workspace.TestWorkspace;
import org.eclipse.che.selenium.pageobject.Events;
import org.eclipse.che.selenium.pageobject.Ide;
import org.eclipse.che.selenium.pageobject.ProjectExplorer;
import org.eclipse.che.selenium.pageobject.ToastLoader;
import org.eclipse.che.selenium.core.webdriver.SeleniumWebDriverHelper;
import org.eclipse.che.selenium.pageobject.dashboard.CreateWorkspaceHelper;
import org.eclipse.che.selenium.pageobject.dashboard.Dashboard;
import org.eclipse.che.selenium.pageobject.dashboard.NewWorkspace.Devfile;
import org.eclipse.che.selenium.pageobject.theia.TheiaIde;
import org.openqa.selenium.By;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/** TODO rewrite to use che7 workspace */
@Test(groups = UNDER_REPAIR)
public class CheckStoppingWsByTimeoutTest {

private static int TOASTLOADER_WIDGET_LATENCY_TIMEOUT_IN_MILLISEC = 20000;
@Inject private Ide ide;
@Inject private ProjectExplorer projectExplorer;
@Inject private ToastLoader toastLoader;
private static final String WORKSPACE_NAME =
generate(CheckStoppingWsByTimeoutTest.class.getSimpleName(), 5);

@Inject private Dashboard dashboard;
@Inject private TestWorkspaceServiceClient workspaceServiceClient;
@Inject private TestWorkspace testWorkspace;
@Inject private DefaultTestUser testUser;
@Inject private Events eventsPanel;
@Inject private DefaultTestUser defaultTestUser;
@Inject private CreateWorkspaceHelper createWorkspaceHelper;
@Inject private TheiaIde theiaIde;
@Inject private SeleniumWebDriverHelper seleniumWebDriverHelper;

@Inject
@Named("che.workspace_agent_dev_inactive_stop_timeout_ms")
Expand All @@ -52,38 +53,36 @@ public class CheckStoppingWsByTimeoutTest {
@Named("che.workspace.activity_check_scheduler_period_s")
private int cheWorkspaceActivityCheckSchedulerPeriodInSeconds;

@Inject TestUserHttpJsonRequestFactory testUserHttpJsonRequestFactory;

@BeforeClass
public void setUp() throws Exception {
ide.open(testWorkspace);
projectExplorer.waitProjectExplorer();
// We should invoke delay without any action for triggering workspace activity checker
sleepQuietly(getCommonTimeoutInMilliSec(), MILLISECONDS);
dashboard.open();
createWorkspaceHelper.createAndStartWorkspaceFromStack(
Devfile.JAVA_MAVEN, WORKSPACE_NAME, Collections.emptyList(), null);
}

@AfterClass
public void tearDown() throws Exception {
workspaceServiceClient.delete(WORKSPACE_NAME, defaultTestUser.getName());
}

@Test
public void checkStoppingByApi() throws Exception {
Workspace workspace =
workspaceServiceClient.getByName(testWorkspace.getName(), testUser.getName());
theiaIde.waitOpenedWorkspaceIsReadyToUse();
sleepQuietly(getCommonTimeoutInMilliSec(), MILLISECONDS);

Workspace workspace =
workspaceServiceClient.getByName(WORKSPACE_NAME, defaultTestUser.getName());
assertEquals(workspace.getStatus(), STOPPED);
}

@Test(priority = 1)
public void checkLoadToasterAfterStopping() {
toastLoader.waitToastLoaderButton("Start");
}

@Test(priority = 2)
public void checkStopReasonNotification() {
eventsPanel.clickEventLogBtn();
eventsPanel.waitExpectedMessage("Workspace idle timeout exceeded");
public void checkIdeStatusAfterStopping() {
seleniumWebDriverHelper.waitVisibility(
By.xpath("//div[@id='theia-statusBar']//div[@title='Cannot connect to backend.']"));
}

private int getCommonTimeoutInMilliSec() {
return cheWorkspaceAgentDevInactiveStopTimeoutMilliseconds
+ TOASTLOADER_WIDGET_LATENCY_TIMEOUT_IN_MILLISEC
+ cheWorkspaceActivityCheckSchedulerPeriodInSeconds * 1000;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,112 +11,82 @@
*/
package org.eclipse.che.selenium.workspaces;

import static org.eclipse.che.selenium.core.TestGroup.UNDER_REPAIR;
import static org.eclipse.che.selenium.core.project.ProjectTemplates.MAVEN_SPRING;
import static org.eclipse.che.commons.lang.NameGenerator.generate;
import static org.eclipse.che.selenium.pageobject.dashboard.ProjectSourcePage.Template.CONSOLE_JAVA_SIMPLE;

import com.google.inject.Inject;
import java.net.URL;
import java.nio.file.Paths;
import org.eclipse.che.commons.lang.NameGenerator;
import java.util.Collections;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.client.TestProjectServiceClient;
import org.eclipse.che.selenium.core.workspace.TestWorkspace;
import org.eclipse.che.selenium.pageobject.CodenvyEditor;
import org.eclipse.che.selenium.pageobject.Consoles;
import org.eclipse.che.selenium.pageobject.Ide;
import org.eclipse.che.selenium.pageobject.ProjectExplorer;
import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClient;
import org.eclipse.che.selenium.core.user.DefaultTestUser;
import org.eclipse.che.selenium.pageobject.dashboard.CreateWorkspaceHelper;
import org.eclipse.che.selenium.pageobject.dashboard.Dashboard;
import org.eclipse.che.selenium.pageobject.dashboard.NewWorkspace.Devfile;
import org.eclipse.che.selenium.pageobject.theia.TheiaEditor;
import org.eclipse.che.selenium.pageobject.theia.TheiaIde;
import org.eclipse.che.selenium.pageobject.theia.TheiaProjectTree;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/** @author Andrey chizhikov TODO rewrite to use che7 workspace */
@Test(groups = UNDER_REPAIR)
/** @author Andrey chizhikov */
public class ProjectStateAfterRefreshTest {
private static final String PROJECT_NAME = NameGenerator.generate("project", 5);

@Inject private TestWorkspace workspace;
@Inject private Ide ide;
@Inject private ProjectExplorer projectExplorer;
@Inject private Consoles consoles;
@Inject private CodenvyEditor editor;
@Inject private TestProjectServiceClient testProjectServiceClient;
private static final String WORKSPACE_NAME =
generate(ProjectStateAfterRefreshTest.class.getSimpleName(), 5);
private static final String PATH_TO_POM_FILE = CONSOLE_JAVA_SIMPLE + "/" + "pom.xml";
private static final String PATH_TO_README_FILE = CONSOLE_JAVA_SIMPLE + "/" + "README.md";

@Inject private Dashboard dashboard;
@Inject private TestWorkspaceServiceClient workspaceServiceClient;
@Inject private DefaultTestUser defaultTestUser;
@Inject private CreateWorkspaceHelper createWorkspaceHelper;
@Inject private TheiaIde theiaIde;
@Inject private TheiaProjectTree theiaProjectTree;
@Inject private SeleniumWebDriver seleniumWebDriver;
@Inject private TheiaEditor theiaEditor;

@BeforeClass
public void setUp() throws Exception {
URL resource =
ProjectStateAfterRefreshTest.this.getClass().getResource("/projects/guess-project");
testProjectServiceClient.importProject(
workspace.getId(), Paths.get(resource.toURI()), PROJECT_NAME, MAVEN_SPRING);
ide.open(workspace);
dashboard.open();
createWorkspaceHelper.createAndStartWorkspaceFromStack(
Devfile.JAVA_MAVEN, WORKSPACE_NAME, Collections.emptyList(), null);
}

@AfterClass
public void tearDown() throws Exception {
workspaceServiceClient.delete(WORKSPACE_NAME, defaultTestUser.getName());
}

@Test
public void checkRestoreStateOfProjectAfterRefreshTest() {
ide.waitOpenedWorkspaceIsReadyToUse();
projectExplorer.waitItem(PROJECT_NAME);
projectExplorer.quickExpandWithJavaScript();
theiaIde.waitOpenedWorkspaceIsReadyToUse();

theiaProjectTree.waitFilesTab();
theiaProjectTree.clickOnFilesTab();
theiaProjectTree.waitProjectAreaOpened();
theiaProjectTree.waitItem(CONSOLE_JAVA_SIMPLE);
theiaIde.waitAllNotificationsClosed();

openFilesInEditor();
checkFilesAreOpened();

seleniumWebDriver.navigate().refresh();
ide.waitOpenedWorkspaceIsReadyToUse();
projectExplorer.waitItem(PROJECT_NAME);
theiaIde.waitOpenedWorkspaceIsReadyToUse();

checkFilesAreOpened();

editor.closeAllTabsByContextMenu();
}

@Test
public void checkRestoreStateOfProjectIfPomXmlFileOpened() {
ide.waitOpenedWorkspaceIsReadyToUse();
projectExplorer.waitItem(PROJECT_NAME);
projectExplorer.waitAndSelectItem(PROJECT_NAME);
projectExplorer.quickExpandWithJavaScript();

projectExplorer.waitItem(PROJECT_NAME + "/pom.xml");
projectExplorer.waitItem(PROJECT_NAME + "/src/main/webapp/WEB-INF");
projectExplorer.waitItem(PROJECT_NAME + "/src/main/webapp/WEB-INF/jsp");
projectExplorer.openItemByPath(PROJECT_NAME + "/pom.xml");
editor.waitActive();

seleniumWebDriver.navigate().refresh();
ide.waitOpenedWorkspaceIsReadyToUse();
projectExplorer.waitItem(PROJECT_NAME);
editor.waitTabIsPresent("qa-spring-sample");
projectExplorer.waitItem(PROJECT_NAME + "/pom.xml");
projectExplorer.waitItem(PROJECT_NAME + "/src/main/webapp/WEB-INF");
projectExplorer.waitItem(PROJECT_NAME + "/src/main/webapp/WEB-INF/jsp");
private void openFilesInEditor() {
theiaProjectTree.expandItem(CONSOLE_JAVA_SIMPLE);
theiaProjectTree.waitItem(PATH_TO_POM_FILE);
theiaProjectTree.waitItem(PATH_TO_README_FILE);

editor.closeAllTabsByContextMenu();
theiaProjectTree.openItem(PATH_TO_POM_FILE);
theiaProjectTree.openItem(PATH_TO_README_FILE);
}

private void checkFilesAreOpened() {
projectExplorer.waitItem(PROJECT_NAME + "/src/main/webapp/WEB-INF");
projectExplorer.waitItem(PROJECT_NAME + "/src/main/webapp/WEB-INF/jsp");
projectExplorer.waitItem(PROJECT_NAME + "/src/main/webapp/index.jsp");
projectExplorer.waitItem(
PROJECT_NAME + "/src/main/java/org/eclipse/qa/examples/AppController.java");
editor.waitTabIsPresent("index.jsp");
editor.waitTabIsPresent("AppController");
editor.waitTabIsPresent("guess_num.jsp");
editor.waitTabIsPresent("web.xml");
editor.waitTabIsPresent("qa-spring-sample");
}

private void openFilesInEditor() {
projectExplorer.openItemByPath(PROJECT_NAME + "/src/main/webapp/index.jsp");
editor.waitActive();
projectExplorer.openItemByPath(
PROJECT_NAME + "/src/main/java/org/eclipse/qa/examples/AppController.java");
editor.waitActive();
projectExplorer.openItemByPath(PROJECT_NAME + "/pom.xml");
editor.waitActive();
projectExplorer.openItemByPath(
PROJECT_NAME + "/src/main/webapp/WEB-INF/jsp" + "/guess_num.jsp");
editor.waitActive();
projectExplorer.openItemByPath(PROJECT_NAME + "/src/main/webapp/WEB-INF" + "/web.xml");
editor.waitActive();
theiaEditor.waitEditorTab("pom.xml");
theiaEditor.waitEditorTab("README.md");
}
}
Loading