[Selenium] Stabilize selenium tests (#16023)

7.20.x
Sergey Skorik 2020-02-14 17:35:37 +02:00 committed by GitHub
parent cac70f2712
commit f01869fdd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 361 deletions

View File

@ -51,7 +51,7 @@ seleniumTestsSetup
createIndentityProvider
bash /root/payload/tests/legacy-e2e/che-selenium-test/selenium-tests.sh \
--threads=3 \
--threads=4 \
--host=${CHE_ROUTE} \
--port=80 \
--multiuser \
@ -64,4 +64,4 @@ saveSeleniumTestResult
getOpenshiftLogs
archiveArtifacts "che-pullrequests-test-temporary"
if [[ "$IS_TESTS_FAILED" == "true" ]]; then exit 1; fi
if [[ "$IS_TESTS_FAILED" == "true" ]]; then exit 1; fi

View File

@ -292,7 +292,7 @@ public class OrganizationListPage {
}
public void waitOrganizationInList(String name) {
new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC)
.until(visibilityOfElementLocated(By.xpath(format(Locators.ORGANIZATION_XPATH, name))));
}

View File

@ -28,24 +28,32 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
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.eclipse.che.selenium.pageobject.TestWebElementRenderChecker;
import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriverException;
@Singleton
public class TheiaProjectTree {
private final SeleniumWebDriverHelper seleniumWebDriverHelper;
private final SeleniumWebDriver seleniumWebDriver;
private final TheiaIde theiaIde;
private final TestWebElementRenderChecker renderChecker;
private final TheiaEditor theiaEditor;
@Inject
private TheiaProjectTree(
SeleniumWebDriverHelper seleniumWebDriverHelper,
SeleniumWebDriver seleniumWebDriver,
TheiaIde theiaIde,
TestWebElementRenderChecker renderChecker,
TheiaEditor theiaEditor) {
this.seleniumWebDriverHelper = seleniumWebDriverHelper;
this.seleniumWebDriver = seleniumWebDriver;
this.theiaIde = theiaIde;
this.renderChecker = renderChecker;
this.theiaEditor = theiaEditor;
}
@ -99,7 +107,15 @@ public class TheiaProjectTree {
public void waitItem(String itemPath) {
String itemId = getProjectItemId(itemPath);
seleniumWebDriverHelper.waitVisibility(By.id(itemId), ELEMENT_TIMEOUT_SEC);
try {
seleniumWebDriverHelper.waitVisibility(By.id(itemId), ELEMENT_TIMEOUT_SEC);
} catch (TimeoutException ex) {
seleniumWebDriver.navigate().refresh();
theiaIde.waitOpenedWorkspaceIsReadyToUse();
seleniumWebDriverHelper.waitVisibility(By.id(itemId), ELEMENT_TIMEOUT_SEC);
}
}
public void waitItemDisappearance(String itemPath) {
@ -137,7 +153,6 @@ public class TheiaProjectTree {
public void expandItem(String itemName) {
if (!isItemExpanded(itemName)) {
clickOnItem(itemName);
waitItemExpanded(itemName);
}
}

View File

@ -127,8 +127,8 @@ public class RenameOrganizationTest {
organizationPage.clickBackButton();
organizationListPage.waitForOrganizationsList();
assertTrue(organizationListPage.getValues(NAME).contains(newChildOrgQualifiedName));
assertTrue(organizationListPage.getValues(NAME).contains(NEW_PARENT_ORG_NAME));
organizationListPage.waitOrganizationInList(newChildOrgQualifiedName);
organizationListPage.waitOrganizationInList(NEW_PARENT_ORG_NAME);
}
private void renameOrganizationWithInvalidName(String organizationName) {

View File

@ -89,6 +89,7 @@ public class ShareWorkspaceMemberTest {
@Test
public void checkSharingByWorkspaceOwner() {
createWorkspace(WORKSPACE_NAME);
dashboard.open(adminTestUser.getName(), adminTestUser.getPassword());
dashboard.waitDashboardToolbarTitle();
dashboard.selectWorkspacesItemOnDashboard();
@ -162,17 +163,18 @@ public class ShareWorkspaceMemberTest {
dashboard.selectWorkspacesItemOnDashboard();
workspaces.waitWorkspaceIsPresent(WORKSPACE_NAME);
workspaces.waitWorkspaceStatus(WORKSPACE_NAME, STOPPED);
workspaces.selectWorkspaceByCheckbox(WORKSPACE_NAME);
workspaces.clickOnDeleteWorkspacesBtn();
workspaces.clickOnDeleteButtonInDialogWindow();
workspaces.waitWorkspaceIsNotPresent(WORKSPACE_NAME);
}
private void createWorkspace(String workspaceName) {
createWorkspaceHelper.createAndStartWorkspaceFromStack(
Devfile.JAVA_MAVEN, workspaceName, Collections.emptyList(), null);
theiaIde.switchToIdeFrame();
theiaIde.waitTheiaIde();
theiaIde.waitLoaderInvisibility();
theiaIde.waitTheiaIdeTopPanel();
theiaIde.waitAllNotificationsClosed();
theiaIde.waitOpenedWorkspaceIsReadyToUse();
theiaProjectTree.waitFilesTab();
theiaProjectTree.clickOnFilesTab();
@ -180,6 +182,7 @@ public class ShareWorkspaceMemberTest {
theiaIde.waitNotificationDisappearance(
"Che Workspace: Finished importing projects.", UPDATING_PROJECT_TIMEOUT_SEC);
theiaIde.waitAllNotificationsClosed();
theiaProjectTree.expandItem(CONSOLE_JAVA_SIMPLE);
theiaProjectTree.openItem(CONSOLE_JAVA_SIMPLE + "/README.md");
theiaEditor.waitEditorTab("README.md");

View File

@ -1,55 +0,0 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.selenium.theia;
import static org.eclipse.che.selenium.core.TestGroup.OPENSHIFT;
import com.google.inject.Inject;
import org.eclipse.che.commons.lang.NameGenerator;
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.TheiaIde;
import org.eclipse.che.selenium.pageobject.theia.TheiaProjectTree;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
public class Che7PreviewDevfileStartTest {
private static final String WORKSPACE_NAME = NameGenerator.generate("wksp-", 5);
@Inject private Dashboard dashboard;
@Inject private TheiaIde theiaIde;
@Inject private DefaultTestUser defaultTestUser;
@Inject private CreateWorkspaceHelper createWorkspaceHelper;
@Inject private TestWorkspaceServiceClient workspaceServiceClient;
@Inject private TheiaProjectTree theiaProjectTree;
@AfterClass
public void tearDown() throws Exception {
workspaceServiceClient.delete(WORKSPACE_NAME, defaultTestUser.getName());
}
@Test(groups = {OPENSHIFT})
public void workspaceShouldBeStarted() {
dashboard.open();
createWorkspaceHelper.createWorkspaceFromDevfileWithoutProject(Devfile.GO, WORKSPACE_NAME);
theiaIde.switchToIdeFrame();
theiaIde.waitTheiaIde();
theiaIde.waitLoaderInvisibility();
theiaIde.waitTheiaIde();
theiaIde.waitTheiaIdeTopPanel();
theiaProjectTree.waitFilesTab();
}
}

View File

@ -1,293 +0,0 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.selenium.theia;
import static org.eclipse.che.selenium.core.TestGroup.OPENSHIFT;
import static org.eclipse.che.selenium.core.TestGroup.UNDER_REPAIR;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.LOADER_TIMEOUT_SEC;
import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.UPDATING_PROJECT_TIMEOUT_SEC;
import static org.testng.Assert.fail;
import com.google.inject.Inject;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClient;
import org.eclipse.che.selenium.core.user.DefaultTestUser;
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;
import org.eclipse.che.selenium.pageobject.dashboard.NewWorkspace.Devfile;
import org.eclipse.che.selenium.pageobject.dashboard.workspaces.Workspaces;
import org.eclipse.che.selenium.pageobject.theia.TheiaEditor;
import org.eclipse.che.selenium.pageobject.theia.TheiaHostedPluginSelectPathForm;
import org.eclipse.che.selenium.pageobject.theia.TheiaIde;
import org.eclipse.che.selenium.pageobject.theia.TheiaNewFileDialog;
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.openqa.selenium.TimeoutException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@Test(groups = {OPENSHIFT, UNDER_REPAIR})
/** TODO the test looks outdated */
public class TheiaBuildPluginTest {
private static final String WORKSPACE_NAME = NameGenerator.generate("wksp-", 5);
private static final String EXPECTED_DEVELOPMENT_HOST_TITLE = "Development Host";
@Inject private Dashboard dashboard;
@Inject private NewWorkspace newWorkspace;
@Inject private Workspaces workspaces;
@Inject private TheiaIde theiaIde;
@Inject private DefaultTestUser defaultTestUser;
@Inject private CreateWorkspaceHelper createWorkspaceHelper;
@Inject private SeleniumWebDriverHelper seleniumWebDriverHelper;
@Inject private SeleniumWebDriver seleniumWebDriver;
@Inject private TestWorkspaceServiceClient workspaceServiceClient;
@Inject private TheiaTerminal theiaTerminal;
@Inject private TheiaProjectTree theiaProjectTree;
@Inject private TheiaEditor theiaEditor;
@Inject private TheiaNewFileDialog theiaNewFileDialog;
@Inject private TheiaHostedPluginSelectPathForm hostedPluginSelectPathForm;
@Inject private TheiaProposalForm theiaProposalForm;
@BeforeClass
public void prepare() {
dashboard.open();
createWorkspaceHelper.createWorkspaceFromDevfileWithoutProject(Devfile.GO, WORKSPACE_NAME);
theiaIde.switchToIdeFrame();
theiaIde.waitTheiaIde();
theiaIde.waitLoaderInvisibility();
}
@AfterClass
public void tearDown() throws Exception {
workspaceServiceClient.delete(WORKSPACE_NAME, defaultTestUser.getName());
}
@Test
public void pluginShouldBeBuilt() {
final String pluginNameSearchSequence = "hello-world";
final String yeomanWizardSearchSequence = ">yeom";
final String helloWorldPluginProposal = "Hello World plug-in";
final String goToDirectoryCommand = "cd hello-world";
final String wsTheiaIdeTerminalTitle = "ws/theia-ide terminal 0";
final String expectedYaomanMessage = "Yeoman generator successfully ended";
final String expectedTerminalSuccessOutput =
"Packaging of plugin\n"
+ "\uD83D\uDD0D Validating...✔️\n"
+ "\uD83D\uDDC2 Getting dependencies...✔️\n"
+ "\uD83D\uDDC3 Resolving files...✔️\n"
+ "✂️ Excluding files...✔️\n"
+ "✍️ Generating Assembly...✔️\n"
+ "\uD83C\uDF89 Generated plugin: hello_world.theia";
final String backendPluginDescription = "Backend plug-in, it will run on the server side.";
// prepare project tree
theiaProjectTree.waitFilesTab();
theiaProjectTree.clickOnFilesTab();
theiaIde.waitNotificationDisappearance(
"Che Workspace: Finished cloning projects.", UPDATING_PROJECT_TIMEOUT_SEC);
// create project by "Yeoman Wizard"
theiaIde.pressKeyCombination(Keys.LEFT_CONTROL, Keys.LEFT_SHIFT, "p");
theiaProposalForm.waitForm();
theiaProposalForm.enterTextToSearchField(yeomanWizardSearchSequence);
theiaProposalForm.waitProposal("Yeoman Wizard");
theiaProposalForm.clickOnProposal("Yeoman Wizard");
try {
theiaProposalForm.waitForm();
} catch (TimeoutException ex) {
// remove try-catch block after issue has been resolved
fail("Known permanent failure https://github.com/eclipse/che/issues/12315");
}
theiaProposalForm.enterTextToSearchField(pluginNameSearchSequence);
seleniumWebDriverHelper.pressEnter();
theiaProposalForm.clickOnProposal(backendPluginDescription);
theiaProposalForm.clickOnProposal(helloWorldPluginProposal);
theiaIde.waitNotificationMessageContains(expectedYaomanMessage, UPDATING_PROJECT_TIMEOUT_SEC);
theiaIde.waitNotificationDisappearance(expectedYaomanMessage, UPDATING_PROJECT_TIMEOUT_SEC);
// build plugin
openTerminalByProposal("ws/theia-ide");
theiaTerminal.waitTab(wsTheiaIdeTerminalTitle);
theiaTerminal.clickOnTab(wsTheiaIdeTerminalTitle);
theiaTerminal.performCommand(goToDirectoryCommand);
theiaTerminal.waitTerminalOutput(goToDirectoryCommand, 0);
theiaTerminal.clickOnTab(wsTheiaIdeTerminalTitle);
theiaTerminal.waitTabSelected(wsTheiaIdeTerminalTitle);
theiaTerminal.performCommand("yarn");
try {
theiaTerminal.waitTerminalOutput(expectedTerminalSuccessOutput, 0);
} catch (TimeoutException ex) {
// remove try-catch block after issue has been resolved
fail("Known permanent failure https://github.com/eclipse/che/issues/11624", ex);
}
}
@Test(priority = 1)
public void hostedModeShouldWork() {
final String projectName = "hello-world";
final String hostedSearchSequence = ">hosted";
final String editedSourceFile = "hello-world-backend.ts";
final String expectedHelloWorldNotification = "Hello World!";
final String expectedAlohaWorldNotification = "Aloha World!";
final String suggestionForSelection = "Hosted Plugin: Start Instance";
final String helloWorldProposal = "Hello World";
final String helloWorldSearchSequence = ">Hello";
final String expectedInstanceRunningMessage = "Hosted instance is running at:";
final String parentWindow = seleniumWebDriver.getWindowHandle();
final String expectedPluginFolderMessage =
"Plugin folder is set to: file:///projects/hello-world";
final String expectedStartingServerMessage = "Starting hosted instance server ...";
final String editedSourceLine = "theia.window.showInformationMessage('Aloha World!');";
final String expectedTextAfterDeleting =
"context.subscriptions.push(theia.commands.registerCommand(informationMessageTestCommand, (...args: any[]) => {\n"
+ " \n"
+ " }));";
// run hosted mode
theiaProjectTree.waitItem(projectName);
theiaProjectTree.clickOnItem(projectName);
theiaProjectTree.waitItemSelected(projectName);
theiaIde.pressKeyCombination(Keys.LEFT_CONTROL, Keys.LEFT_SHIFT, "p");
theiaProposalForm.waitForm();
theiaProposalForm.enterTextToSearchField(hostedSearchSequence);
theiaProposalForm.clickOnProposal(suggestionForSelection);
hostedPluginSelectPathForm.waitForm();
hostedPluginSelectPathForm.clickOnProjectItem(projectName);
hostedPluginSelectPathForm.waitProjectItemSelected(projectName);
hostedPluginSelectPathForm.clickOnOpenButton();
hostedPluginSelectPathForm.waitFormClosed();
waitNotificationEqualsTo(expectedPluginFolderMessage, parentWindow);
waitNotificationEqualsTo(expectedStartingServerMessage, parentWindow);
waitNotificationContains(expectedInstanceRunningMessage, parentWindow);
// check hosted mode availability
switchToNonParentWindow(parentWindow);
waitHostedPageReady();
theiaProjectTree.clickOnFilesTab();
theiaProjectTree.waitProjectAreaOpened();
theiaProjectTree.waitItem(projectName);
// check plugin output
theiaIde.pressKeyCombination(Keys.LEFT_CONTROL, Keys.LEFT_SHIFT, "p");
theiaProposalForm.waitSearchField();
theiaProposalForm.enterTextToSearchField(helloWorldSearchSequence);
theiaProposalForm.clickOnProposal(helloWorldProposal);
theiaIde.waitNotificationEqualsTo(expectedHelloWorldNotification);
theiaIde.waitNotificationDisappearance(expectedHelloWorldNotification);
// check editing of the source code
switchToParentWindow(parentWindow);
theiaProjectTree.waitProjectAreaOpened();
theiaProjectTree.waitItem(projectName);
theiaProjectTree.expandPathAndOpenFile(projectName + "/src", editedSourceFile);
theiaEditor.waitEditorTab(editedSourceFile);
theiaEditor.waitTabSelecting(editedSourceFile);
theiaEditor.waitActiveEditor();
theiaEditor.selectLineText(14);
seleniumWebDriverHelper.pressDelete();
theiaEditor.waitEditorText(expectedTextAfterDeleting);
theiaEditor.enterTextByTypingEachChar(editedSourceLine);
theiaEditor.waitEditorText(editedSourceLine);
theiaEditor.waitTabSavedStatus(editedSourceFile);
// check applying of the changes in hosted mode window
switchToNonParentWindow(parentWindow);
waitHostedPageReady();
seleniumWebDriver.navigate().refresh();
waitHostedPageReady();
theiaProjectTree.waitProjectAreaOpened();
theiaProjectTree.waitItem(projectName);
theiaIde.pressKeyCombination(Keys.LEFT_CONTROL, Keys.LEFT_SHIFT, "p");
theiaProposalForm.waitSearchField();
theiaProposalForm.enterTextToSearchField(helloWorldSearchSequence);
theiaProposalForm.clickOnProposal(helloWorldProposal);
theiaIde.waitNotificationEqualsTo(expectedAlohaWorldNotification);
theiaIde.waitNotificationDisappearance(expectedAlohaWorldNotification);
}
private void switchToNonParentWindow(String parentWindowHandle) {
seleniumWebDriver.switchToNoneCurrentWindow(parentWindowHandle);
}
private void switchToParentWindow(String parentWindowHandle) {
seleniumWebDriver.switchTo().window(parentWindowHandle);
theiaIde.switchToIdeFrame();
}
private void waitHostedPageReady() {
seleniumWebDriverHelper.waitSuccessCondition(
driver -> {
try {
theiaIde.waitTheiaIdeTopPanel();
theiaProjectTree.waitFilesTab();
} catch (TimeoutException ex) {
// page should be refreshed for checking of the deploying
seleniumWebDriver.navigate().refresh();
return false;
}
return true;
},
LOADER_TIMEOUT_SEC);
}
private void openTerminal(String topMenuCommand, String commandName, String proposalText) {
theiaIde.runMenuCommand(topMenuCommand, commandName);
theiaProposalForm.waitSearchField();
theiaProposalForm.waitProposal(proposalText);
theiaProposalForm.clickOnProposal(proposalText);
theiaProposalForm.waitFormDisappearance();
}
private void openTerminalByProposal(String proposalText) {
theiaIde.pressKeyCombination(Keys.LEFT_CONTROL, "`");
theiaProposalForm.waitProposal(proposalText);
theiaProposalForm.clickOnProposal(proposalText);
theiaProposalForm.waitFormDisappearance();
}
private void waitNotificationEqualsTo(String notificationMessage, String parentWindowHandle) {
seleniumWebDriverHelper.waitSuccessCondition(
driver -> {
if (seleniumWebDriverHelper.isTwoOrMoreWindowsOpened()) {
driver.switchTo().window(parentWindowHandle);
theiaIde.switchToIdeFrame();
}
return theiaIde.isNotificationEqualsTo(notificationMessage);
},
LOADER_TIMEOUT_SEC);
}
private void waitNotificationContains(String notificationMessage, String parentWindowHandle) {
seleniumWebDriverHelper.waitSuccessCondition(
driver -> {
if (seleniumWebDriverHelper.isTwoOrMoreWindowsOpened()) {
driver.switchTo().window(parentWindowHandle);
theiaIde.switchToIdeFrame();
}
return theiaIde.isNotificationContains(notificationMessage);
},
LOADER_TIMEOUT_SEC);
}
}

View File

@ -33,7 +33,6 @@
<class name="org.eclipse.che.selenium.factory.DirectUrlFactoryWithSpecificBranchTest"/>
<class name="org.eclipse.che.selenium.factory.DirectUrlFactoryWithKeepDirectoryTest"/>
<class name="org.eclipse.che.selenium.factory.CreateFactoryFromDevfileUrl"/>
<class name="org.eclipse.che.selenium.theia.TheiaBuildPluginTest"/>
<class name="org.eclipse.che.selenium.swagger.SwaggerTest"/>
<class name="org.eclipse.che.selenium.workspaces.ProjectStateAfterRefreshTest"/>
<class name="org.eclipse.che.selenium.workspaces.ProjectStateAfterRenameWorkspaceTest"/>