Skip to content

Commit

Permalink
Adapt the CSharpFileEditingTest after latest changes in Csharp langua…
Browse files Browse the repository at this point in the history
…ge server (#10166)

* Adapt the test after latest changes for C sharp language server
  • Loading branch information
Maxim Musienko committed Jun 26, 2018
1 parent d4e2d0f commit ef444f9
Showing 1 changed file with 54 additions and 46 deletions.
Expand Up @@ -10,14 +10,15 @@
*/
package org.eclipse.che.selenium.languageserver;

import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.MINIMUM_SEC;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.MarkerLocator.ERROR;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.MarkerLocator.INFO;
import static org.testng.Assert.fail;

import com.google.inject.Inject;
import java.util.List;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.client.TestCommandServiceClient;
import org.eclipse.che.selenium.core.client.TestWorkspaceServiceClient;
import org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants;
import org.eclipse.che.selenium.core.workspace.InjectTestWorkspace;
import org.eclipse.che.selenium.core.workspace.TestWorkspace;
Expand All @@ -30,11 +31,9 @@
import org.eclipse.che.selenium.pageobject.ProjectExplorer;
import org.eclipse.che.selenium.pageobject.Wizard;
import org.eclipse.che.selenium.pageobject.intelligent.CommandsPalette;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.TimeoutException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

Expand All @@ -56,69 +55,78 @@ public class CSharpFileEditingTest {
@Inject private SeleniumWebDriver seleniumWebDriver;
@Inject private TestCommandServiceClient testCommandServiceClient;
@Inject private CommandsPalette commandsPalette;

@Inject TestWorkspaceServiceClient testWorkspaceServiceClient;
@Inject private Consoles consoles;

@BeforeClass
public void setUp() throws Exception {
ide.open(workspace);
createDotNetAppFromWizard();
restoreDependenciesForLanguageServerByCommand();
projectExplorer.quickRevealToItemWithJavaScript(PROJECT_NAME + "/Program.cs");
}

@AfterMethod
public void restartWorkspace() throws Exception {
editor.closeAllTabs();
testWorkspaceServiceClient.stop(workspace.getName(), workspace.getOwner().getName());
ide.open(workspace);
ide.waitOpenedWorkspaceIsReadyToUse();
restoreDependenciesForLanguageServerByCommand();
projectExplorer.quickRevealToItemWithJavaScript(PROJECT_NAME + "/Program.cs");
}

@Test
public void checkLaunchingCodeserver() {
projectExplorer.waitProjectExplorer();
menu.runCommand(
TestMenuCommandsConstants.Workspace.WORKSPACE,
TestMenuCommandsConstants.Workspace.CREATE_PROJECT);
wizard.selectSample(Wizard.SamplesName.ASP_DOT_NET_WEB_SIMPLE);
wizard.typeProjectNameOnWizard(PROJECT_NAME);
wizard.clickCreateButton();
wizard.waitCloseProjectConfigForm();
projectExplorer.openItemByPath(PROJECT_NAME);
projectExplorer.waitItem(PROJECT_NAME + "/Program.cs", 240);
public void checkCodeEditing() {
projectExplorer.openItemByPath(PROJECT_NAME + "/Program.cs");
loader.waitOnClosed();
checkLanguageServerInitStateAndLaunch();
checkCodeValidation();
}

@Test(priority = 1)
public void checkInitializingAfterFirstStarting() {
projectExplorer.openItemByPath(PROJECT_NAME + "/Program.cs");
try {
editor.waitMarkerInPosition(INFO, 1);
editor.waitMarkerInPosition(INFO, 2);
} catch (TimeoutException ex) {
// remove try-catch block after issue has been resolved
fail("Known issue: https://github.com/eclipse/che/issues/10151", ex);
}
}

public void checkCodeValidation() {
editor.goToCursorPositionVisible(24, 12);
for (int i = 0; i < 9; i++) {
editor.typeTextIntoEditor(Keys.BACK_SPACE.toString());
}
editor.waitMarkerInPosition(ERROR, 23);
editor.waitMarkerInPosition(INFO, 23);
editor.waitMarkerInPosition(ERROR, 21);
checkAutocompletion();
}

private void checkAutocompletion() {
editor.goToCursorPositionVisible(23, 49);
editor.typeTextIntoEditor(".");
editor.launchAutocomplete();
editor.enterAutocompleteProposal("Build() ");
editor.typeTextIntoEditor(";");
editor.waitAllMarkersInvisibility(ERROR);
editor.enterAutocompleteProposal("Build ");
editor.typeTextIntoEditor("();");
editor.waitAllMarkersInvisibility(INFO);
}

private void checkLanguageServerInitStateAndLaunch() {
if (isLanguageServerInitFailed()) {
reInitLanguageServer();
}
private void createDotNetAppFromWizard() {
projectExplorer.waitProjectExplorer();
menu.runCommand(
TestMenuCommandsConstants.Workspace.WORKSPACE,
TestMenuCommandsConstants.Workspace.CREATE_PROJECT);
wizard.selectSample(Wizard.SamplesName.ASP_DOT_NET_WEB_SIMPLE);
wizard.typeProjectNameOnWizard(PROJECT_NAME);
wizard.clickCreateButton();
wizard.waitCloseProjectConfigForm();
}

private void reInitLanguageServer() {
private void restoreDependenciesForLanguageServerByCommand() {
commandsPalette.openCommandPalette();
commandsPalette.startCommandByDoubleClick(COMMAND_NAME_FOR_RESTORE_LS);
consoles.waitExpectedTextIntoConsole("Restore completed");
editor.closeAllTabs();
projectExplorer.openItemByPath(PROJECT_NAME + "/Program.cs");
loader.waitOnClosed();
}

private boolean isLanguageServerInitFailed() {
String xpathLocatorForEventMessages =
"//div[contains(@id,'gwt-debug-notification-wrappergwt-uid')]";
List<WebElement> textMessages =
new WebDriverWait(seleniumWebDriver, MINIMUM_SEC)
.until(
ExpectedConditions.presenceOfAllElementsLocatedBy(
By.xpath(xpathLocatorForEventMessages)));
return textMessages
.stream()
.anyMatch(
message -> message.getAttribute("textContent").contains("Timeout initializing error"));
}
}

0 comments on commit ef444f9

Please sign in to comment.