Skip to content

Commit

Permalink
Fix selenium tests in projectexplorer package (#10452)
Browse files Browse the repository at this point in the history
* Fix selenium tests in projectexplorer package

Signed-off-by: Anatoliy Bazko <[email protected]>

* Fixup

Signed-off-by: Anatoliy Bazko <[email protected]>
  • Loading branch information
tolusha authored and tsmaeder committed Aug 22, 2018
1 parent 444a08b commit ae4de22
Show file tree
Hide file tree
Showing 22 changed files with 116 additions and 331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,11 @@ public void apply(java.util.Optional<VirtualFile> optionalFile)
callback.onSuccess(null);
}
}
})
.catchError(
error -> {
removeFromOpeningFilesList(path, editorPartStack);
callback.onSuccess(null);
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants;
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.Loader;
import org.eclipse.che.selenium.pageobject.Menu;
Expand All @@ -26,8 +27,8 @@
/** @author Andrey Chizhikov */
public class CheckShowHideHiddenFilesTest {
private static final String PROJECT_NAME = "RefreshProject";
private static final String PATH_TO_CODENVY_FOLDER = PROJECT_NAME + "/.che";
private static final String PATH_TO_CLASSPATH_FILE = PROJECT_NAME + "/.che/classpath";
private static final String PATH_TO_CLASSPATH_FILE = PROJECT_NAME + "/.classpath";
private static final String PATH_TO_PROJECT_FILE = PROJECT_NAME + "/.project";
public static final String CLASSPATH_CONTENT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

@Inject private TestWorkspace testWorkspace;
Expand All @@ -37,6 +38,7 @@ public class CheckShowHideHiddenFilesTest {
@Inject private CodenvyEditor editor;
@Inject private Menu menu;
@Inject private Wizard projectWizard;
@Inject private Consoles consoles;

@BeforeClass
public void setUp() throws Exception {
Expand All @@ -46,6 +48,7 @@ public void setUp() throws Exception {
@Test
public void checkShowHideHiddenFilesTest() {
createProject(PROJECT_NAME);
consoles.waitJDTLSProjectResolveFinishedMessage(PROJECT_NAME);
projectExplorer.waitProjectExplorer();
projectExplorer.waitItem(PROJECT_NAME);
projectExplorer.openItemByPath(PROJECT_NAME);
Expand All @@ -54,10 +57,8 @@ public void checkShowHideHiddenFilesTest() {
TestMenuCommandsConstants.Project.PROJECT,
TestMenuCommandsConstants.Project.SHOW_HIDE_HIDDEN_FILES);
loader.waitOnClosed();
projectExplorer.waitItem(PATH_TO_CODENVY_FOLDER);
projectExplorer.openItemByPath(PATH_TO_CODENVY_FOLDER);
loader.waitOnClosed();
projectExplorer.waitItem(PATH_TO_CLASSPATH_FILE);
projectExplorer.waitItem(PATH_TO_PROJECT_FILE);
projectExplorer.openItemByPath(PATH_TO_CLASSPATH_FILE);
loader.waitOnClosed();
editor.waitActive();
Expand All @@ -67,8 +68,9 @@ public void checkShowHideHiddenFilesTest() {
TestMenuCommandsConstants.Project.PROJECT,
TestMenuCommandsConstants.Project.SHOW_HIDE_HIDDEN_FILES);
loader.waitOnClosed();
editor.waitTabIsPresent("classpath");
projectExplorer.waitItemInvisibility(PATH_TO_CODENVY_FOLDER);
editor.waitTabIsPresent(".classpath");
projectExplorer.waitItemInvisibility(PATH_TO_CLASSPATH_FILE);
projectExplorer.waitItemInvisibility(PATH_TO_PROJECT_FILE);
}

private void createProject(String projectName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package org.eclipse.che.selenium.projectexplorer;

import static org.eclipse.che.selenium.core.constant.TestProjectExplorerContextMenuConstants.ContextMenuFirstLevelItems.DELETE;
import static org.testng.Assert.fail;

import com.google.inject.Inject;
import java.net.URL;
Expand All @@ -30,7 +29,6 @@
import org.eclipse.che.selenium.pageobject.Loader;
import org.eclipse.che.selenium.pageobject.Menu;
import org.eclipse.che.selenium.pageobject.ProjectExplorer;
import org.openqa.selenium.TimeoutException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -92,7 +90,6 @@ public void shouldDeleteProjectByContextMenu() {
projectExplorer.openContextMenuByPathSelectedItem(PROJECT_NAMES.get(0));
projectExplorer.clickOnItemInContextMenu(DELETE);
acceptDeletion(PROJECT_NAMES.get(0));
checkErrorMessageNotPresentInConsole();
}

@Test
Expand All @@ -101,7 +98,6 @@ public void shouldDeleteProjectByMenuFile() {
projectExplorer.waitAndSelectItem(PROJECT_NAMES.get(1));
menu.runCommand(TestMenuCommandsConstants.Edit.EDIT, TestMenuCommandsConstants.Edit.DELETE);
acceptDeletion(PROJECT_NAMES.get(1));
checkErrorMessageNotPresentInConsole();
}

@Test
Expand All @@ -114,7 +110,6 @@ public void shouldDeleteOpenedProjectByMenuFile() {
menu.runCommand(TestMenuCommandsConstants.Edit.EDIT, TestMenuCommandsConstants.Edit.DELETE);
acceptDeletion(PROJECT_NAMES.get(3));
projectExplorer.waitDisappearItemByPath(PROJECT_NAMES.get(3));
checkErrorMessageNotPresentInConsole();
}

@Test
Expand All @@ -128,7 +123,6 @@ public void shouldDeleteOpenedProjectFromContextMenu() {
projectExplorer.clickOnItemInContextMenu(DELETE);
acceptDeletion(PROJECT_NAMES.get(4));
projectExplorer.waitDisappearItemByPath(PROJECT_NAMES.get(4));
checkErrorMessageNotPresentInConsole();
}

private void deleteFromDeleteIcon(String pathToProject) {
Expand All @@ -146,14 +140,6 @@ private void acceptDeletion(String projectName) {
projectExplorer.waitDisappearItemByPath(projectName);
}

private void checkErrorMessageNotPresentInConsole() {
try {
consoles.waitExpectedTextIntoConsole("[ERROR]", 7);
fail("Error message is present in console");
} catch (TimeoutException ex) {
}
}

private void waitAllProjectsInProjectExplorer() {
PROJECT_NAMES.forEach((String projectName) -> projectExplorer.waitItem(projectName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import static org.eclipse.che.selenium.core.utils.WaitUtils.sleepQuietly;
import static org.testng.Assert.assertEquals;

import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.client.TestProjectServiceClient;
import org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants;
Expand All @@ -32,6 +32,7 @@
import org.eclipse.che.selenium.core.user.DefaultTestUser;
import org.eclipse.che.selenium.core.webdriver.DownloadedFileUtil;
import org.eclipse.che.selenium.core.workspace.TestWorkspace;
import org.eclipse.che.selenium.pageobject.Consoles;
import org.eclipse.che.selenium.pageobject.Ide;
import org.eclipse.che.selenium.pageobject.Loader;
import org.eclipse.che.selenium.pageobject.Menu;
Expand All @@ -44,16 +45,15 @@
public class DownloadProjectTest {
private static final String TEST_PROJECT_1 = "TestProject1";
private static final String TEST_PROJECT_2 = "TestProject2";
private static final ImmutableList<String> PROJECT_NAMES =
ImmutableList.of(TEST_PROJECT_1, TEST_PROJECT_2);

private static final String TEST_FILE_NAME = "README.md";
private static final String TEST_DIRECTORY_NAME = "src";

private static final int MAX_ATTEMPTS = 5;

private static final URL PROJECT_SOURCES =
private static final URL PROJECT_1_SOURCES =
DownloadProjectTest.class.getResource("/projects/ProjectWithDifferentTypeOfFiles");
private static final URL PROJECT_2_SOURCES =
DownloadProjectTest.class.getResource("/projects/ProjectWithDifferentTypeOfFiles2");

private static final String DOWNLOADED_PROJECTS_PACKAGE_NAME = "download.zip";
private static final String DOWNLOADED_TEST_PROJECT_1_PACKAGE_NAME = TEST_PROJECT_1 + ".zip";
Expand All @@ -68,23 +68,24 @@ public class DownloadProjectTest {
@Inject private DownloadedFileUtil downloadedFileUtil;
@Inject private SeleniumWebDriver seleniumWebDriver;
@Inject private DefaultTestUser user;
@Inject private Consoles consoles;

@BeforeClass
public void setUp() throws Exception {
PROJECT_NAMES.forEach(
testProject -> {
try {
testProjectServiceClient.importProject(
workspace.getId(),
Paths.get(PROJECT_SOURCES.toURI()),
testProject,
ProjectTemplates.MAVEN_SPRING);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
testProjectServiceClient.importProject(
workspace.getId(),
Paths.get(PROJECT_1_SOURCES.toURI()),
TEST_PROJECT_1,
ProjectTemplates.MAVEN_SPRING);
testProjectServiceClient.importProject(
workspace.getId(),
Paths.get(PROJECT_2_SOURCES.toURI()),
TEST_PROJECT_2,
ProjectTemplates.MAVEN_SPRING);

ide.open(workspace);
consoles.waitJDTLSProjectResolveFinishedMessage(TEST_PROJECT_1);
consoles.waitJDTLSProjectResolveFinishedMessage(TEST_PROJECT_2);
projectExplorer.waitProjectExplorer();
loader.waitOnClosed();
}
Expand All @@ -104,19 +105,26 @@ public void downloadAllProjectsTest() throws IOException {
// given
List<String> expectedPackageFileList =
asList(
"TestProject1/.che/classpath",
"TestProject1/.classpath",
"TestProject1/.project",
"TestProject1/.settings/org.eclipse.jdt.apt.core.prefs",
"TestProject1/.settings/org.eclipse.jdt.core.prefs",
"TestProject1/.settings/org.eclipse.m2e.core.prefs",
"TestProject1/README.md",
"TestProject1/pom.xml",
"TestProject1/src/main/java/org/eclipse/qa/examples/AppController.java",
"TestProject1/src/main/webapp/WEB-INF/jsp/guess_num.jsp",
"TestProject1/src/main/webapp/WEB-INF/spring-servlet.xml",
"TestProject1/src/main/webapp/WEB-INF/web.xml",
"TestProject1/src/main/webapp/index.jsp",
"TestProject2/.che/classpath",
"TestProject2/README.md",
"TestProject2/.classpath",
"TestProject2/.project",
"TestProject2/.settings/org.eclipse.jdt.apt.core.prefs",
"TestProject2/.settings/org.eclipse.jdt.core.prefs",
"TestProject2/.settings/org.eclipse.m2e.core.prefs",
"TestProject2/pom.xml",
"TestProject2/src/main/java/org/eclipse/qa/examples/AppController.java",
"TestProject2/src/main/webapp/WEB-INF/jsp/guess_num.jsp",
"TestProject2/src/main/webapp/WEB-INF/jsp/hello_view.jsp",
"TestProject2/src/main/webapp/WEB-INF/spring-servlet.xml",
"TestProject2/src/main/webapp/WEB-INF/web.xml",
"TestProject2/src/main/webapp/index.jsp");
Expand All @@ -125,16 +133,19 @@ public void downloadAllProjectsTest() throws IOException {
menu.runCommand(WORKSPACE, DOWNLOAD_AS_ZIP);

// then
assertEquals(
getPackageFileList(DOWNLOADED_PROJECTS_PACKAGE_NAME), expectedPackageFileList.toString());
assertEquals(getPackageFileList(DOWNLOADED_PROJECTS_PACKAGE_NAME), expectedPackageFileList);
}

@Test
public void downloadSingleProjectTest() throws IOException {
// given
List<String> expectedPackageFileList =
asList(
".che/classpath",
".classpath",
".project",
".settings/org.eclipse.jdt.apt.core.prefs",
".settings/org.eclipse.jdt.core.prefs",
".settings/org.eclipse.m2e.core.prefs",
"README.md",
"pom.xml",
"src/main/java/org/eclipse/qa/examples/AppController.java",
Expand All @@ -151,8 +162,7 @@ public void downloadSingleProjectTest() throws IOException {

// then
assertEquals(
getPackageFileList(DOWNLOADED_TEST_PROJECT_1_PACKAGE_NAME),
expectedPackageFileList.toString());
getPackageFileList(DOWNLOADED_TEST_PROJECT_1_PACKAGE_NAME), expectedPackageFileList);

// when
downloadedFileUtil.removeDownloadedFiles(
Expand All @@ -164,8 +174,7 @@ public void downloadSingleProjectTest() throws IOException {

// then
assertEquals(
getPackageFileList(DOWNLOADED_TEST_PROJECT_1_PACKAGE_NAME),
expectedPackageFileList.toString());
getPackageFileList(DOWNLOADED_TEST_PROJECT_1_PACKAGE_NAME), expectedPackageFileList);
}

@Test
Expand All @@ -188,8 +197,8 @@ public void downloadDirectoryTest() throws IOException {
projectExplorer.clickOnItemInContextMenu(ContextMenuFirstLevelItems.DOWNLOAD);

// then
String packageFileList = getPackageFileList(DOWNLOADED_TEST_DIRECTORY_PACKAGE_NAME);
assertEquals(packageFileList, expectedPackageFileList.toString());
assertEquals(
getPackageFileList(DOWNLOADED_TEST_DIRECTORY_PACKAGE_NAME), expectedPackageFileList);
}

@Test
Expand Down Expand Up @@ -224,13 +233,17 @@ private String getDownloadedFileContent(String testFileName) throws IOException
throw lastException;
}

private String getPackageFileList(String downloadedTestProject1PackageName) throws IOException {
private List<String> getPackageFileList(String downloadedTestProject1PackageName)
throws IOException {
IOException lastException = null;
for (int i = 0; i < MAX_ATTEMPTS; i++) {
try {
return downloadedFileUtil
.getPackageFileList(seleniumWebDriver, downloadedTestProject1PackageName)
.toString();
.stream()
// target && .che directories appears asynchronously and leads to failed tests
.filter(s -> !s.contains("target/") && !s.startsWith(".che"))
.collect(Collectors.toList());
} catch (IOException e) {
lastException = e;
sleepQuietly(TestTimeoutsConstants.MINIMUM_SEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void setUp() throws Exception {
projectExplorer.waitProjectExplorer();
projectExplorer.waitItem(PROJECT_NAME);
notificationsPopupPanel.waitProgressPopupPanelClose();
consoles.waitJDTLSProjectResolveFinishedMessage(PROJECT_NAME);
consoles.closeProcessesArea();
}

Expand Down Expand Up @@ -148,8 +149,8 @@ public void navigationByKeyboard() throws Exception {

projectExplorer.sendToItemRightArrowKey();
checkLibrariesIsVisible();
projectExplorer.waitAndSelectItemByName("servlet-api-2.5.jar");

projectExplorer.sendToItemDownArrowKey();
projectExplorer.sendToItemEnterKey();
projectExplorer.waitVisibilityByName("META-INF");
projectExplorer.waitVisibilityByName("javax.servlet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.che.selenium.core.project.ProjectTemplates;
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.Events;
import org.eclipse.che.selenium.pageobject.Ide;
import org.eclipse.che.selenium.pageobject.Menu;
Expand Down Expand Up @@ -61,17 +62,19 @@ public class UploadIntoProjectTest {
@Inject private UploadDirectoryDialogPage uploadDirectoryDialogPage;
@Inject private NotificationsPopupPanel notificationPopup;
@Inject private CodenvyEditor editor;
@Inject private Consoles consoles;

@BeforeClass
public void setup() throws Exception {
testProjectServiceClient.importProject(
testWorkspace.getId(),
get(PROJECT_SOURCES.toURI()),
PROJECT_NAME,
ProjectTemplates.MAVEN_SPRING);
ProjectTemplates.PLAIN_JAVA);

ide.open(testWorkspace);
projectExplorer.waitProjectInitialization(PROJECT_NAME);
consoles.waitJDTLSProjectResolveFinishedMessage(PROJECT_NAME);
projectExplorer.waitVisibleItem(PROJECT_NAME);
}

@BeforeMethod
Expand Down
Loading

0 comments on commit ae4de22

Please sign in to comment.