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

Adapt the CSharpFileEditingTest after latest changes in Csharp language server #10166

Merged
merged 5 commits into from Jun 26, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -10,14 +10,16 @@
*/
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.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grouping of imports is not good practice.

import static org.eclipse.che.selenium.pageobject.CodenvyEditor.MarkerLocator.ERROR;
import static org.testng.Assert.fail;

import com.google.inject.Inject;
import java.util.List;
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
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 +32,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 +56,80 @@ 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();
restoreLanguageServer();
projectExplorer.quickRevealToItemWithJavaScript(PROJECT_NAME + "/Program.cs");
}

@AfterMethod
public void restartWorkspace() throws Exception {
if (testWorkspaceServiceClient.getStatus(workspace.getId()).equals(WorkspaceStatus.RUNNING)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if workspace is not running at the moment? It doesn't mean that workspace is restarting at the moment, or language server will be restarted as well, do it?

editor.closeAllTabs();
testWorkspaceServiceClient.stop(workspace.getName(), workspace.getOwner().getName());
ide.open(workspace);
ide.waitOpenedWorkspaceIsReadyToUse();
restoreLanguageServer();
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("https://github.com/eclipse/che/issues/10151");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message is unclear.

}
}

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(ERROR, 21);
checkAutocompletion();
}

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

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 restoreLanguageServer() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not restoring language server directly here, aren't we?
We are doing something which lead to restoring language server. It's kind of magic which have to be commented clearly, and method name should reflect the magic explicitely.

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"));
}
}