Skip to content

Commit

Permalink
Adding check for console tests to stop producing outputs
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Dockal <odockal@redhat.com>
  • Loading branch information
odockal committed Aug 25, 2020
1 parent e997b54 commit 6ab350b
Showing 1 changed file with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;

import java.util.Arrays;
import java.util.List;

import org.eclipse.reddeer.common.exception.RedDeerException;
Expand Down Expand Up @@ -89,6 +90,19 @@ public static void tearDownClass() {
explorer.open();
DeleteUtils.forceProjectDeletion(explorer.getProject(TEST_PROJECT_NAME),true);
}

@After
public void tearDown(){
consoleView = new ConsoleView();
consoleView.open();
// clean up all launches
while (consoleView.consoleHasLaunch()){
consoleView.toggleShowConsoleOnStandardOutChange(true);
consoleView.terminateConsole();
consoleView.removeLaunch();
}
killRunningJavaProcesses();
}

private void runTestClassAndWaitToFinish() {
runTestClass(TEST_CLASS_NAME);
Expand All @@ -98,6 +112,7 @@ private void runTestClassAndWaitToFinish() {
@Test
public void testConsoleHasAnyText() {
consoleView = new ConsoleView();
consoleView.open();
while (consoleView.consoleHasLaunch()) {
consoleView.terminateConsole();
consoleView.removeLaunch();
Expand Down Expand Up @@ -155,7 +170,7 @@ public void testRemoveAllTerminatedLaunches() {
public void testTerminateConsole() {

runTestClass(TEST_CLASS_LOOP_NAME);
AbstractWait.sleep(TimePeriod.SHORT);
AbstractWait.sleep(TimePeriod.MEDIUM);

consoleView = new ConsoleView();
consoleView.open();
Expand Down Expand Up @@ -209,18 +224,6 @@ public void getContextMenuTest() {
MenuItem clear = contextMenu.getItem("Clear");
assertNotNull(clear);
}

@After
public void tearDown(){
consoleView = new ConsoleView();
consoleView.open();
// clean up all launches
while (consoleView.consoleHasLaunch()){
consoleView.toggleShowConsoleOnStandardOutChange(true);
consoleView.terminateConsole();
consoleView.removeLaunch();
}
}

private void testGettingConsoleTest() {
consoleView = new ConsoleView();
Expand All @@ -237,6 +240,18 @@ private void testClearConsole() {
String text = consoleView.getConsoleText();
assertEquals(text,"");
}

private static void killRunningJavaProcesses() {
ProcessHandle.allProcesses()
.filter(process ->
process.info()
.commandLine()
.map(proc -> Arrays
.asList(TEST_CLASS_NAME, TEST_CLASS_NAME1, TEST_CLASS_NAME2, TEST_CLASS_LOOP_NAME, TEST_CLASS_LOOP2_NAME)
.contains(proc)).orElse(false))
.findFirst()
.ifPresent(ProcessHandle::destroy);
}

private static void createTestProject() {
PackageExplorerPart packageExplorer = new PackageExplorerPart();
Expand Down

0 comments on commit 6ab350b

Please sign in to comment.