Skip to content

Commit

Permalink
Change static class member of ConsoleHasLabel to non static, fixes #2162
Browse files Browse the repository at this point in the history


Signed-off-by: Ondrej Dockal <odockal@redhat.com>
  • Loading branch information
odockal committed Mar 1, 2022
1 parent c5a50ef commit b546cff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class ConsoleHasLabel extends AbstractWaitCondition {

private Matcher<String> matcher;
private static ConsoleView consoleView = null;
private ConsoleView consoleView;
private String resultLabel;

/**
Expand All @@ -53,7 +53,7 @@ public ConsoleHasLabel(Matcher<String> matcher) {
*/
@Override
public boolean test() {
String consoleLabel = ConsoleHasLabel.getConsoleLabel();
String consoleLabel = getConsoleLabel();
if (matcher.matches(consoleLabel)) {
this.resultLabel = consoleLabel;
return true;
Expand All @@ -69,11 +69,13 @@ public String description() {
return "console label matches '" + matcher ;
}

private static String getConsoleLabel() {
private String getConsoleLabel() {
if (consoleView == null){
consoleView = new ConsoleView();
}
consoleView.open();
if (!consoleView.isOpen()) {
consoleView.open();
}
return consoleView.getConsoleLabel();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,32 @@
@RunWith(RedDeerSuite.class)
public class ConsoleHasLabelTest {

@SuppressWarnings("unchecked")
@Test
public void testReinitiatingCondition() {
Matcher<String> textMatcher = StringEndsWith.endsWith("Java Stack Trace Console");
public void testConsole() {

Matcher<String> textMatcher = StringEndsWith.endsWith("Java Stack Trace Console");

Matcher<String> textMatcher2 = StringEndsWith.endsWith("CVS");
Matcher<String> textMatcher2 = StringEndsWith.endsWith("Maven Console");


ConsoleHasLabel condition = new ConsoleHasLabel(textMatcher);
// First run
ConsoleView console1 = new ConsoleView();
console1.open();
var menu = new ToolItemMenuItem(new DefaultToolItem(console1.getCTabItem().getFolder(), "Open Console"), textMatcher);
menu.select();
new WaitUntil(condition);
console1.close();
// First run
ConsoleView console1 = new ConsoleView();
console1.open();
var menu = new ToolItemMenuItem(new DefaultToolItem(console1.getCTabItem().getFolder(), "Open Console"), textMatcher);
menu.select();
new WaitUntil(new ConsoleHasLabel(textMatcher));
new DefaultToolItem(console1.getCTabItem().getFolder(), "Close Console").click();
console1.close();

// Second run
ConsoleView console2 = new ConsoleView();
console2.open();
var menu2 = new ToolItemMenuItem(new DefaultToolItem(console2.getCTabItem().getFolder(), "Open Console"), textMatcher2);
menu2.select();
new WaitUntil(new ConsoleHasLabel(textMatcher2)); // Will fail because ConsoleHasLabel still refers to console1
// Second run
ConsoleView console2 = new ConsoleView();
console2.open();
var menu2 = new ToolItemMenuItem(new DefaultToolItem(console2.getCTabItem().getFolder(), "Open Console"), textMatcher2);
menu2.select();
// we need to change condition to adjust to the new expected label
new WaitUntil(new ConsoleHasLabel(textMatcher2));

}


}

0 comments on commit b546cff

Please sign in to comment.