Skip to content

Commit

Permalink
Adapt tests to correct observed behaviour (#10824)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder authored Aug 21, 2018
1 parent b92c471 commit b8f2a20
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import com.google.inject.Singleton;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
import org.eclipse.che.commons.lang.Pair;
import org.eclipse.che.selenium.core.SeleniumWebDriver;
import org.eclipse.che.selenium.core.action.ActionsFactory;
Expand Down Expand Up @@ -190,10 +191,10 @@ public interface Locators {
String JAVA_DOC_POPUP = "//div[contains(@class, 'textviewTooltip')]";
String AUTOCOMPLETE_PROPOSAL_JAVA_DOC_POPUP =
"//div[@id='gwt-debug-content-assist-doc-popup']//div[@class='gwt-HTML']";
String HIGHLIGHT_ITEM_PATTERN = "//li[@selected='true']//span[text()='%s']";
String HIGHLIGHT_ITEM_PATTERN = "//li[@selected='true']//span[contains(.,'%s')]";
String TOOLTIP_TITLE_CSS = "span.tooltipTitle";
String TEXT_TO_MOVE_CURSOR_XPATH =
ORION_ACTIVE_EDITOR_CONTAINER_XPATH + "//span[contains(text(),'%s')]";
ORION_ACTIVE_EDITOR_CONTAINER_XPATH + "//span[contains(.,'%s')]";
String HOVER_POPUP_XPATH = "//div[@class='textviewTooltip'][last()]";
String AUTOCOMPLETE_PROPOSAL_DOC_ID = "gwt-debug-content-assistant-doc-popup";
}
Expand Down Expand Up @@ -373,25 +374,35 @@ public String getTextFromSplitEditor(int indexOfEditor) {
return getTextFromOrionLines(inner);
}

/**
* Waits during {@code timeout} until specified {@code expectedText} is present in editor.
*
* @param expectedText text which should be present in the editor
* @param timeout waiting time in seconds
*/
public void waitTextIntoEditor(final String expectedText, final int timeout) {
private void waitForText(String expectedText, int timeout, Supplier<String> textProvider) {
String[] result = new String[1];
webDriverWaitFactory
.get(timeout)
.withMessage(() -> "Timeout waiting for txt, actual='" + result[0] + "'")
.withMessage(
() ->
"Timeout waiting for txt, expected= '"
+ expectedText
+ "', actual='"
+ result[0]
+ "'")
.until(
(ExpectedCondition<Boolean>)
driver -> {
result[0] = getVisibleTextFromEditor();
result[0] = textProvider.get();
return result[0].contains(expectedText);
});
}

/**
* Waits during {@code timeout} until specified {@code expectedText} is present in editor.
*
* @param expectedText text which should be present in the editor
* @param timeout waiting time in seconds
*/
public void waitTextIntoEditor(final String expectedText, final int timeout) {
waitForText(expectedText, timeout, () -> getVisibleTextFromEditor());
}

/**
* Waits until specified {@code expectedText} is present in editor.
*
Expand All @@ -411,11 +422,7 @@ public void waitTextIntoEditor(final String expectedText) {
*/
public void waitTextInDefinedSplitEditor(
int indexOfEditor, final int timeout, String expectedText) {
webDriverWaitFactory
.get(timeout)
.until(
(ExpectedCondition<Boolean>)
driver -> getTextFromSplitEditor(indexOfEditor).contains(expectedText));
waitForText(expectedText, timeout, () -> getTextFromSplitEditor(indexOfEditor));
}

/**
Expand Down Expand Up @@ -2082,6 +2089,14 @@ public void moveCursorToText(String text) {
By.xpath(format(Locators.TEXT_TO_MOVE_CURSOR_XPATH, text)));
}

public void waitProposalDocumentationHTML(String expectedText, int timeout) {
waitForText(expectedText, timeout, () -> getProposalDocumentationHTML());
}

public void waitProposalDocumentationHTML(String expectedText) {
waitProposalDocumentationHTML(expectedText, LOAD_PAGE_TIMEOUT_SEC);
}

public String getProposalDocumentationHTML() {
return seleniumWebDriverHelper
.waitVisibility(proposalDoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package org.eclipse.che.selenium.editor.autocomplete;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import com.google.inject.Inject;
import java.io.IOException;
Expand Down Expand Up @@ -96,8 +95,7 @@ public void shouldDisplayJavaDocOfClassMethod() throws Exception {
"concat(String part1, String part2, char divider) : String App");

// then
assertEquals(
editor.getProposalDocumentationHTML(),
editor.waitProposalDocumentationHTML(
"<p><strong>Deprecated</strong> <em>As of version 1.0, use <a href=\"jdt://contents/commons-lang-2.6.jar/org.apache.commons.lang/StringUtils.class?=app/%5C/home%5C/user%5C/.m2%5C/repository%5C/commons-lang%5C/commons-lang%5C/2.6%5C/commons-lang-2.6.jar%3Corg.apache.commons.lang%28StringUtils.class#3169\">org.apache.commons.lang.StringUtils.join(Object [], char)</a></em></p>\n"
+ "<p>Returns concatination of two strings into one divided by special symbol.</p>\n"
+ "<ul>\n"
Expand Down Expand Up @@ -134,7 +132,7 @@ public void shouldWorkAroundAbsentJavaDocOfConstructor() throws IOException {
editor.selectAutocompleteProposal("App() multimodule.App");

// then
assertEquals(editor.getProposalDocumentationHTML(), "<p>No documentation found.</p>\n");
editor.waitProposalDocumentationHTML("<p>No documentation found.</p>\n");
}

@Test
Expand All @@ -147,8 +145,7 @@ public void shouldDisplayAnotherModuleClassJavaDoc() throws IOException {
editor.selectAutocompleteProposal("isEquals(Object o) : boolean Book");

// then
assertEquals(
editor.getProposalDocumentationHTML(),
editor.waitProposalDocumentationHTML(
"<p>Returns <code>true</code> if the argument is equal to instance. otherwise <code>false</code></p>\n"
+ "<ul>\n"
+ "<li><p><strong>Parameters:</strong></p>\n"
Expand Down Expand Up @@ -190,10 +187,7 @@ public void shouldReflectChangesInJavaDoc() throws IOException {
editor.selectAutocompleteProposal("BookImpl - multimodule.model");

// then
assertTrue(
editor
.getProposalDocumentationHTML()
.contains("UPDATE. Implementation of Book interface."));
editor.waitProposalDocumentationHTML("UPDATE. Implementation of Book interface.");
}

@Test
Expand All @@ -206,12 +200,9 @@ public void shouldDisplayJavaDocOfJreClass() throws IOException {
editor.selectAutocompleteProposal("hashCode() : int Object");

// then
assertTrue(
editor
.getProposalDocumentationHTML()
.contains(
"Returns a hash code value for the object. "
+ "This method is supported for the benefit of hash tables such as those provided by"));
editor.waitProposalDocumentationHTML(
"Returns a hash code value for the object. "
+ "This method is supported for the benefit of hash tables such as those provided by");
}

@Test
Expand All @@ -227,7 +218,7 @@ public void shouldWorkAroundAbsentSourcesOfExternalLib() throws IOException {
editor.selectAutocompleteProposal("info(String msg) : void Logger");

// then
assertEquals(editor.getProposalDocumentationHTML(), ".*No documentation found.*");
editor.waitProposalDocumentationHTML(".*No documentation found.*");

// when
editor.closeAutocomplete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.ContextMenuLocator.FORMAT;
import static org.eclipse.che.selenium.pageobject.CodenvyEditor.MarkerLocator.ERROR;
import static org.openqa.selenium.Keys.F4;
import static org.testng.Assert.assertEquals;

import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;
Expand Down Expand Up @@ -95,7 +94,7 @@ public void checkAutocompleteFeature() {
editor.typeTextIntoEditor("fmt.");
editor.launchAutocompleteAndWaitContainer();

assertEquals(editor.getProposalDocumentationHTML(), "No documentation found.");
editor.waitProposalDocumentationHTML("<p>No documentation found.</p>\n");
editor.waitProposalsIntoAutocompleteContainer(expectedProposals);

editor.deleteCurrentLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ private void checkGoToDefinition() {
editor.goToPosition(25, 20);
menu.runCommand(ASSISTANT, FIND_DEFINITION);
editor.waitActiveTabFileName("testPrint.ts");
editor.waitCursorPosition(15, 6);
editor.waitCursorPosition(15, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.eclipse.che.selenium.pageobject.Preferences.DropDownLanguageServerSettings.YAML;
import static org.openqa.selenium.Keys.DELETE;
import static org.openqa.selenium.Keys.ENTER;
import static org.testng.Assert.assertEquals;

import com.google.inject.Inject;
import java.net.URL;
Expand Down Expand Up @@ -110,12 +109,11 @@ public void checkAutocompleteFeature() {
editor.launchAutocompleteAndWaitContainer();
editor.waitProposalIntoAutocompleteContainer("diskName");
editor.selectAutocompleteProposal("diskName");
assertEquals(
editor.getProposalDocumentationHTML(), "The Name of the data disk in the blob storage");
editor.waitProposalDocumentationHTML(
"<p>The Name of the data disk in the blob storage</p>\n", 2);
editor.waitProposalIntoAutocompleteContainer("diskURI");
editor.selectAutocompleteProposal("diskURI");
assertEquals(
editor.getProposalDocumentationHTML(), "The URI the data disk in the blob storage");
editor.waitProposalDocumentationHTML("<p>The URI the data disk in the blob storage</p>\n", 2);

// select proposal and check expected text in the Editor
editor.enterAutocompleteProposal("kind");
Expand Down

0 comments on commit b8f2a20

Please sign in to comment.