From b5ee590b20d70d6a8def74e4e3574ba96bf39a92 Mon Sep 17 00:00:00 2001 From: Sergey Skorik Date: Fri, 28 Dec 2018 14:27:36 +0200 Subject: [PATCH] Selenium: fix existed selenium tests from 'factory' package according to factory creation changes (#12297) --- .../selenium/core/factory/TestFactory.java | 1 - .../CheckFactoryWithSparseCheckoutTest.java | 4 + ...DirectUrlFactoryWithKeepDirectoryTest.java | 60 ++++----- .../DirectUrlFactoryWithRootFolderTest.java | 66 ++++------ ...irectUrlFactoryWithSpecificBranchTest.java | 118 +++++++----------- 5 files changed, 100 insertions(+), 149 deletions(-) diff --git a/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/factory/TestFactory.java b/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/factory/TestFactory.java index 76a37afa3c..bffb6179c6 100644 --- a/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/factory/TestFactory.java +++ b/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/factory/TestFactory.java @@ -60,7 +60,6 @@ public class TestFactory { seleniumWebDriver.get(dashboardUrl.get().toString()); entrance.login(owner); seleniumWebDriver.get(factoryUrl); - seleniumWebDriverHelper.switchToIdeFrameAndWaitAvailability(); } /** Opens factory url. */ diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/CheckFactoryWithSparseCheckoutTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/CheckFactoryWithSparseCheckoutTest.java index 94b49ef438..0bc2275911 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/CheckFactoryWithSparseCheckoutTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/CheckFactoryWithSparseCheckoutTest.java @@ -22,6 +22,7 @@ import org.eclipse.che.selenium.core.client.TestUserPreferencesServiceClient; import org.eclipse.che.selenium.core.factory.FactoryTemplate; import org.eclipse.che.selenium.core.factory.TestFactory; import org.eclipse.che.selenium.core.factory.TestFactoryInitializer; +import org.eclipse.che.selenium.core.webdriver.SeleniumWebDriverHelper; import org.eclipse.che.selenium.pageobject.Events; import org.eclipse.che.selenium.pageobject.ProjectExplorer; import org.eclipse.che.selenium.pageobject.PullRequestPanel; @@ -39,6 +40,7 @@ public class CheckFactoryWithSparseCheckoutTest { @Inject private PullRequestPanel pullRequestPanel; @Inject private TestGitHubRepository testRepo; @Inject private TestFactoryInitializer testFactoryInitializer; + @Inject private SeleniumWebDriverHelper seleniumWebDriverHelper; @Inject private TestUserPreferencesServiceClient testUserPreferencesServiceClient; private TestFactory testFactory; @@ -74,6 +76,8 @@ public class CheckFactoryWithSparseCheckoutTest { @Test public void acceptFactoryWithSparseCheckout() { testFactory.authenticateAndOpen(); + seleniumWebDriverHelper.switchToIdeFrameAndWaitAvailability(); + projectExplorer.waitProjectExplorer(); projectExplorer.waitItem(projectName); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithKeepDirectoryTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithKeepDirectoryTest.java index 7202de5b5a..6c0370db62 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithKeepDirectoryTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithKeepDirectoryTest.java @@ -11,41 +11,30 @@ */ package org.eclipse.che.selenium.factory; +import static org.eclipse.che.selenium.core.TestGroup.GITHUB; +import static org.eclipse.che.selenium.core.TestGroup.OPENSHIFT; import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.UPDATING_PROJECT_TIMEOUT_SEC; -import static org.testng.Assert.assertTrue; -import com.google.common.collect.ImmutableList; import com.google.inject.Inject; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; -import org.eclipse.che.selenium.core.SeleniumWebDriver; -import org.eclipse.che.selenium.core.TestGroup; import org.eclipse.che.selenium.core.client.TestGitHubRepository; -import org.eclipse.che.selenium.core.client.TestProjectServiceClient; -import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClient; import org.eclipse.che.selenium.core.factory.TestFactory; import org.eclipse.che.selenium.core.factory.TestFactoryInitializer; -import org.eclipse.che.selenium.core.user.DefaultTestUser; -import org.eclipse.che.selenium.pageobject.Events; -import org.eclipse.che.selenium.pageobject.NotificationsPopupPanel; -import org.eclipse.che.selenium.pageobject.ProjectExplorer; +import org.eclipse.che.selenium.pageobject.theia.TheiaIde; +import org.eclipse.che.selenium.pageobject.theia.TheiaProjectTree; +import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -@Test(groups = TestGroup.GITHUB) +@Test(groups = {GITHUB, OPENSHIFT}) public class DirectUrlFactoryWithKeepDirectoryTest { - @Inject private ProjectExplorer projectExplorer; @Inject private TestFactoryInitializer testFactoryInitializer; - @Inject private NotificationsPopupPanel notificationsPopupPanel; - @Inject private Events events; - @Inject private SeleniumWebDriver seleniumWebDriver; - @Inject private TestWorkspaceServiceClient workspaceServiceClient; - @Inject private TestProjectServiceClient projectServiceClient; - @Inject private DefaultTestUser testUser; @Inject private TestGitHubRepository testRepo; + @Inject private TheiaIde theiaIde; + @Inject private TheiaProjectTree theiaProjectTree; private TestFactory testFactoryWithKeepDir; @@ -65,27 +54,26 @@ public class DirectUrlFactoryWithKeepDirectoryTest { } @Test - public void factoryWithDirectUrlWithKeepDirectory() throws Exception { - String repoName = testRepo.getName(); + public void factoryWithDirectUrlWithKeepDirectory() { + String repositoryName = testRepo.getName(); testFactoryWithKeepDir.authenticateAndOpen(); - projectExplorer.waitProjectExplorer(); - notificationsPopupPanel.waitProgressPopupPanelClose(); - events.clickEventLogBtn(); - events.waitExpectedMessage("Project " + repoName + " imported", UPDATING_PROJECT_TIMEOUT_SEC); - projectExplorer.waitItem(repoName); - projectExplorer.quickExpandWithJavaScript(); - projectExplorer.waitItem(repoName + "/my-lib/pom.xml"); + theiaIde.switchToIdeFrame(); + theiaIde.waitTheiaIde(); + theiaIde.waitLoaderInvisibility(); + theiaIde.waitNotificationEqualsTo("Che Workspace: Finished cloning projects."); + theiaIde.waitNotificationDisappearance( + "Che Workspace: Finished cloning projects.", UPDATING_PROJECT_TIMEOUT_SEC); - String wsId = - workspaceServiceClient - .getByName(seleniumWebDriver.getWorkspaceNameFromBrowserUrl(), testUser.getName()) - .getId(); + theiaProjectTree.waitFilesTab(); + theiaProjectTree.clickOnFilesTab(); + theiaProjectTree.waitProjectsRootItem(); - List visibleItems = projectExplorer.getNamesOfAllOpenItems(); - assertTrue(visibleItems.containsAll(ImmutableList.of(repoName, "my-lib", "src", "pom.xml"))); + theiaProjectTree.waitItem(repositoryName); + theiaProjectTree.openItem(repositoryName + "/my-lib"); + theiaProjectTree.waitItem(repositoryName + "/my-lib/src"); - String projectType = projectServiceClient.getFirstProject(wsId).getType(); - assertTrue(projectType.equals("blank")); + Assert.assertTrue(theiaProjectTree.isItemVisible(repositoryName + "/my-lib/pom.xml")); + Assert.assertFalse(theiaProjectTree.isItemVisible(repositoryName + "/my-webapp")); } } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithRootFolderTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithRootFolderTest.java index 015757904d..4dc0f6f3d8 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithRootFolderTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithRootFolderTest.java @@ -11,43 +11,32 @@ */ package org.eclipse.che.selenium.factory; -import static org.eclipse.che.selenium.core.TestGroup.FLAKY; import static org.eclipse.che.selenium.core.TestGroup.GITHUB; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.eclipse.che.selenium.core.TestGroup.OPENSHIFT; +import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.UPDATING_PROJECT_TIMEOUT_SEC; import com.google.inject.Inject; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.List; -import org.eclipse.che.selenium.core.SeleniumWebDriver; import org.eclipse.che.selenium.core.client.TestGitHubRepository; -import org.eclipse.che.selenium.core.client.TestProjectServiceClient; -import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClient; import org.eclipse.che.selenium.core.factory.TestFactory; import org.eclipse.che.selenium.core.factory.TestFactoryInitializer; -import org.eclipse.che.selenium.core.user.DefaultTestUser; -import org.eclipse.che.selenium.pageobject.Events; -import org.eclipse.che.selenium.pageobject.NotificationsPopupPanel; -import org.eclipse.che.selenium.pageobject.ProjectExplorer; -import org.openqa.selenium.TimeoutException; +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 Musienko Maxim */ -@Test(groups = {GITHUB, FLAKY}) +@Test(groups = {GITHUB, OPENSHIFT}) public class DirectUrlFactoryWithRootFolderTest { - @Inject private ProjectExplorer projectExplorer; - @Inject private DefaultTestUser testUser; + @Inject private TestFactoryInitializer testFactoryInitializer; - @Inject private NotificationsPopupPanel notificationsPopupPanel; - @Inject private Events events; - @Inject private SeleniumWebDriver seleniumWebDriver; - @Inject private TestWorkspaceServiceClient workspaceServiceClient; - @Inject private TestProjectServiceClient projectServiceClient; @Inject private TestGitHubRepository testRepo; + @Inject private TheiaIde theiaIde; + @Inject private TheiaProjectTree theiaProjectTree; private TestFactory testFactoryWithRootFolder; @@ -67,9 +56,8 @@ public class DirectUrlFactoryWithRootFolderTest { } @Test - public void factoryWithDirectUrlWithRootFolder() throws Exception { - String projectName = testRepo.getName(); - String expectedMessInTheEventsPanel = "Project " + projectName + " imported"; + public void factoryWithDirectUrlWithRootFolder() { + String repositoryName = testRepo.getName(); List expectedItemsAfterCloning = Arrays.asList( "CHANGELOG.md", @@ -91,26 +79,22 @@ public class DirectUrlFactoryWithRootFolderTest { testFactoryWithRootFolder.authenticateAndOpen(); - projectExplorer.waitProjectExplorer(); - projectExplorer.waitItem(projectName); - notificationsPopupPanel.waitProgressPopupPanelClose(); - events.clickEventLogBtn(); + theiaIde.switchToIdeFrame(); + theiaIde.waitTheiaIde(); + theiaIde.waitLoaderInvisibility(); - try { - events.waitExpectedMessage(expectedMessInTheEventsPanel); - } catch (TimeoutException ex) { - // remove try-catch block after issue has been resolved - fail("Known random failure https://github.com/eclipse/che/issues/6440"); - } - projectExplorer.openItemByPath(projectName); + theiaProjectTree.waitFilesTab(); + theiaProjectTree.clickOnFilesTab(); + theiaProjectTree.waitProjectsRootItem(); + theiaIde.waitNotificationEqualsTo("Che Workspace: Finished cloning projects."); + theiaIde.waitNotificationDisappearance( + "Che Workspace: Finished cloning projects.", UPDATING_PROJECT_TIMEOUT_SEC); - String currentWsId = - workspaceServiceClient - .getByName(seleniumWebDriver.getWorkspaceNameFromBrowserUrl(), testUser.getName()) - .getId(); - List visibleItems = projectExplorer.getNamesOfAllOpenItems(); - assertTrue(visibleItems.containsAll(expectedItemsAfterCloning)); - String currentTypeOfProject = projectServiceClient.getFirstProject(currentWsId).getType(); - assertTrue(currentTypeOfProject.equals("blank")); + theiaProjectTree.waitItem(repositoryName); + + expectedItemsAfterCloning.forEach( + name -> { + theiaProjectTree.isItemVisible(repositoryName + "/" + name); + }); } } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithSpecificBranchTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithSpecificBranchTest.java index 30a63921ce..f17a1ba653 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithSpecificBranchTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/factory/DirectUrlFactoryWithSpecificBranchTest.java @@ -12,35 +12,29 @@ package org.eclipse.che.selenium.factory; import static org.eclipse.che.selenium.core.CheSeleniumSuiteModule.AUXILIARY; +import static org.eclipse.che.selenium.core.TestGroup.GITHUB; +import static org.eclipse.che.selenium.core.TestGroup.OPENSHIFT; import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.UPDATING_PROJECT_TIMEOUT_SEC; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; -import com.google.common.collect.ImmutableList; import com.google.inject.Inject; import com.google.inject.name.Named; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.List; -import org.eclipse.che.selenium.core.SeleniumWebDriver; -import org.eclipse.che.selenium.core.TestGroup; import org.eclipse.che.selenium.core.client.TestGitHubRepository; -import org.eclipse.che.selenium.core.client.TestProjectServiceClient; -import org.eclipse.che.selenium.core.client.TestUserPreferencesServiceClient; -import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClient; import org.eclipse.che.selenium.core.factory.TestFactory; import org.eclipse.che.selenium.core.factory.TestFactoryInitializer; -import org.eclipse.che.selenium.core.user.DefaultTestUser; -import org.eclipse.che.selenium.pageobject.Events; -import org.eclipse.che.selenium.pageobject.NotificationsPopupPanel; -import org.eclipse.che.selenium.pageobject.ProjectExplorer; -import org.eclipse.che.selenium.pageobject.PullRequestPanel; -import org.openqa.selenium.NoSuchElementException; +import org.eclipse.che.selenium.pageobject.theia.TheiaIde; +import org.eclipse.che.selenium.pageobject.theia.TheiaProjectTree; +import org.eclipse.che.selenium.pageobject.theia.TheiaProposalForm; +import org.eclipse.che.selenium.pageobject.theia.TheiaTerminal; +import org.openqa.selenium.Keys; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -@Test(groups = TestGroup.GITHUB) +@Test(groups = {GITHUB, OPENSHIFT}) public class DirectUrlFactoryWithSpecificBranchTest { private static final String SECOND_BRANCH_NAME = "contrib"; @@ -48,20 +42,11 @@ public class DirectUrlFactoryWithSpecificBranchTest { @Named(AUXILIARY) private TestGitHubRepository testAuxiliaryRepo; - @Inject - @Named("github.auxiliary.username") - private String gitHubAuxiliaryUserName; - - @Inject private ProjectExplorer projectExplorer; - @Inject private DefaultTestUser testUser; @Inject private TestFactoryInitializer testFactoryInitializer; - @Inject private NotificationsPopupPanel notificationsPopupPanel; - @Inject private Events events; - @Inject private SeleniumWebDriver seleniumWebDriver; - @Inject private TestWorkspaceServiceClient workspaceServiceClient; - @Inject private TestProjectServiceClient testProjectServiceClient; - @Inject private PullRequestPanel pullRequestPanel; - @Inject private TestUserPreferencesServiceClient testUserPreferencesServiceClient; + @Inject private TheiaIde theiaIde; + @Inject private TheiaProjectTree theiaProjectTree; + @Inject private TheiaTerminal theiaTerminal; + @Inject private TheiaProposalForm theiaProposalForm; private TestFactory testFactoryWithSpecificBranch; @@ -81,59 +66,50 @@ public class DirectUrlFactoryWithSpecificBranchTest { @AfterClass public void deleteTestBranch() throws Exception { - if (workspaceServiceClient.exists(gitHubAuxiliaryUserName, testUser.getName())) { - testFactoryWithSpecificBranch.delete(); - } - } - - @AfterClass - public void restoreContributionTabPreference() throws Exception { - testUserPreferencesServiceClient.restoreDefaultContributionTabPreference(); + testFactoryWithSpecificBranch.delete(); } @Test - public void factoryWithDirectUrlWithSpecificBranch() throws Exception { + public void factoryWithDirectUrlWithSpecificBranch() { String repositoryName = testAuxiliaryRepo.getName(); + final String wsTheiaIdeTerminalTitle = "che-workspace-pod/theia-ide terminal 0"; + List expectedItemsAfterCloning = Arrays.asList("my-lib", "my-webapp", "src", "pom.xml"); - try { - testFactoryWithSpecificBranch.authenticateAndOpen(); - } catch (NoSuchElementException ex) { - // remove try-catch block after issue has been resolved - fail("https://github.com/eclipse/che/issues/8671"); - } + testFactoryWithSpecificBranch.authenticateAndOpen(); - projectExplorer.waitProjectExplorer(); - notificationsPopupPanel.waitProgressPopupPanelClose(); - events.clickEventLogBtn(); + theiaIde.switchToIdeFrame(); + theiaIde.waitTheiaIde(); + theiaIde.waitLoaderInvisibility(); + theiaIde.waitNotificationEqualsTo("Che Workspace: Finished cloning projects."); + theiaIde.waitNotificationDisappearance( + "Che Workspace: Finished cloning projects.", UPDATING_PROJECT_TIMEOUT_SEC); - events.waitExpectedMessage( - "Project " + repositoryName + " imported", UPDATING_PROJECT_TIMEOUT_SEC); - events.waitExpectedMessage( - "Successfully configured and cloned source code of " + repositoryName, - UPDATING_PROJECT_TIMEOUT_SEC); - events.waitExpectedMessage( - String.format( - "Project: %s | cloned from: %s | remote branch: refs/remotes/origin/%s | local branch: %s", - repositoryName, repositoryName, SECOND_BRANCH_NAME, SECOND_BRANCH_NAME), - UPDATING_PROJECT_TIMEOUT_SEC); + theiaProjectTree.waitFilesTab(); + theiaProjectTree.clickOnFilesTab(); + theiaProjectTree.waitProjectsRootItem(); - projectExplorer.waitAndSelectItem(repositoryName); - pullRequestPanel.waitOpenPanel(); + theiaProjectTree.waitItem(repositoryName); + theiaProjectTree.openItem(repositoryName + "/my-lib"); + theiaProjectTree.waitItem(repositoryName + "/my-lib/src"); - projectExplorer.expandPathInProjectExplorer(repositoryName + "/my-lib"); - projectExplorer.waitItem(repositoryName + "/my-lib/pom.xml"); + expectedItemsAfterCloning.forEach( + name -> { + theiaProjectTree.isItemVisible(repositoryName + "/" + name); + }); - String wsId = - workspaceServiceClient - .getByName(seleniumWebDriver.getWorkspaceNameFromBrowserUrl(), testUser.getName()) - .getId(); + // check specific branch + openTerminalByProposal("che-workspace-pod/theia-ide"); + theiaTerminal.waitTab(wsTheiaIdeTerminalTitle); + theiaTerminal.clickOnTab(wsTheiaIdeTerminalTitle); + theiaTerminal.performCommand("cd " + repositoryName); + theiaTerminal.performCommand("git status"); + theiaTerminal.waitTerminalOutput("On branch " + SECOND_BRANCH_NAME, 0); + } - List visibleItems = projectExplorer.getNamesOfAllOpenItems(); - assertTrue( - visibleItems.containsAll( - ImmutableList.of(repositoryName, "my-lib", "my-webapp", "src", "pom.xml"))); - - String projectType = testProjectServiceClient.getFirstProject(wsId).getType(); - assertTrue(projectType.equals("blank")); + private void openTerminalByProposal(String proposalText) { + theiaIde.pressKeyCombination(Keys.LEFT_CONTROL, "`"); + theiaProposalForm.waitProposal(proposalText); + theiaProposalForm.clickOnProposal(proposalText); + theiaProposalForm.waitFormDisappearance(); } }