/** * Gets highlighted information from test console. Some parts of output (like file links) may be * highlighted, and you need to check them. * * @return pair of [[ranges], [texts]] where range is [from,to] in doc. for each region, and * "text" is text extracted from this region. For example assume that in document "spam eggs * ham" words "ham" and "spam" are highlighted. You should have 2 ranges (0, 4) and (10, 13) * and 2 strings (spam and ham) */ @NotNull public Pair<List<Pair<Integer, Integer>>, List<String>> getHighlightedStringsInConsole() { final List<String> resultStrings = new ArrayList<>(); final List<Pair<Integer, Integer>> resultRanges = new ArrayList<>(); ApplicationManager.getApplication() .invokeAndWait( () -> { myConsole.flushDeferredText(); final Editor editor = myConsole.getEditor(); for (final RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) { if (highlighter instanceof RangeHighlighterEx) { final int start = ((RangeHighlighterEx) highlighter).getAffectedAreaStartOffset(); final int end = ((RangeHighlighterEx) highlighter).getAffectedAreaEndOffset(); resultRanges.add(Pair.create(start, end)); resultStrings.add(editor.getDocument().getText().substring(start, end)); } } }, ModalityState.NON_MODAL); return Pair.create(resultRanges, resultStrings); }
/** @return Short-cut to get text from console */ @NotNull public String getAllConsoleText() { return myConsole.getEditor().getDocument().getText(); }