diff --git a/src/main/java/com/xceptance/neodymium/common/browser/BrowserAfterRunner.java b/src/main/java/com/xceptance/neodymium/common/browser/BrowserAfterRunner.java index ea207851..257c095d 100644 --- a/src/main/java/com/xceptance/neodymium/common/browser/BrowserAfterRunner.java +++ b/src/main/java/com/xceptance/neodymium/common/browser/BrowserAfterRunner.java @@ -33,8 +33,8 @@ public void run(Supplier afterMethodInvocation, Method after, boolean // if browserConfiguration is null, the browser should not be started for this method and browserTag and // browserRunner are therefore not required - BrowserMethodData browserTag = browserConfiguration != null ? BrowserData.addKeepBrowserOpenInformationForBeforeOrAfter(browserConfiguration.getBrowserTag(), - after) + BrowserMethodData browserTag = browserConfiguration != null ? BrowserData.addKeepBrowserOpenInformation(browserConfiguration.getBrowserTag(), + after.getDeclaringClass(), after) : null; BrowserRunner browserRunner = browserTag != null ? new BrowserRunner(browserTag, after.getName()) : null; diff --git a/src/main/java/com/xceptance/neodymium/common/browser/BrowserBeforeRunner.java b/src/main/java/com/xceptance/neodymium/common/browser/BrowserBeforeRunner.java index a1b928d3..26e950d0 100644 --- a/src/main/java/com/xceptance/neodymium/common/browser/BrowserBeforeRunner.java +++ b/src/main/java/com/xceptance/neodymium/common/browser/BrowserBeforeRunner.java @@ -34,8 +34,8 @@ public void run(Supplier beforeMethodInvocation, Method before, boole // if browserConfiguration is null, the browser should not be started for this method and browserTag and // browserRunner are therefore not required - BrowserMethodData browserTag = browserConfiguration != null ? BrowserData.addKeepBrowserOpenInformationForBeforeOrAfter(browserConfiguration.getBrowserTag(), - before) + BrowserMethodData browserTag = browserConfiguration != null ? BrowserData.addKeepBrowserOpenInformation(browserConfiguration.getBrowserTag(), + before.getDeclaringClass(), before) : null; BrowserRunner browserRunner = browserTag != null ? new BrowserRunner(browserTag, before.getName()) : null; diff --git a/src/main/java/com/xceptance/neodymium/common/browser/BrowserData.java b/src/main/java/com/xceptance/neodymium/common/browser/BrowserData.java index 672baa11..9febeaed 100644 --- a/src/main/java/com/xceptance/neodymium/common/browser/BrowserData.java +++ b/src/main/java/com/xceptance/neodymium/common/browser/BrowserData.java @@ -39,6 +39,7 @@ public class BrowserData extends Data public BrowserData(Class testClass) { this(); + this.testClass = testClass; initClassAnnotationsFor(testClass); } @@ -201,15 +202,15 @@ else if (!classRandomBrowsersAnnotation.isEmpty() && methodBrowsers.isEmpty()) { return browsers.stream() .filter(browserTag -> systemBrowserFilter.contains(browserTag)) - .map(browserTag -> addKeepBrowserOpenInformation(browserTag, testMethod)) + .map(browserTag -> addKeepBrowserOpenInformation(browserTag, testClass, testMethod)) .collect(Collectors.toList()); } return browsers.stream() - .map(browserTag -> addKeepBrowserOpenInformation(browserTag, testMethod)) + .map(browserTag -> addKeepBrowserOpenInformation(browserTag, testClass, testMethod)) .collect(Collectors.toList()); } - public static BrowserMethodData addKeepBrowserOpenInformationForBeforeOrAfter(String browserTag, Method method) + public static BrowserMethodData addKeepBrowserOpenInformation(String browserTag, Class testClass, Method method) { List methodKeepBrowserOpenAnnotations = getAnnotations(method, KeepBrowserOpen.class); List classKeepBrowserOpenAnnotations = getAnnotations(method.getDeclaringClass(), KeepBrowserOpen.class); @@ -246,13 +247,6 @@ public static BrowserMethodData addKeepBrowserOpenInformationForBeforeOrAfter(St keepOpenOnFailure = false; } } - - return new BrowserMethodData(browserTag, keepOpen, keepOpenOnFailure, false, false, new ArrayList()); - } - - private BrowserMethodData addKeepBrowserOpenInformation(String browserTag, Method method) - { - BrowserMethodData browserMethodData = addKeepBrowserOpenInformationForBeforeOrAfter(browserTag, method); boolean junit5 = method.getAnnotation(NeodymiumTest.class) != null; List afterMethodsWithTestBrowser = List.of(testClass.getMethods()).stream() .filter(classMethod -> (junit5 ? classMethod.getAnnotation(AfterEach.class) @@ -260,8 +254,7 @@ private BrowserMethodData addKeepBrowserOpenInformation(String browserTag, Metho .collect(Collectors.toList()); if (!(Neodymium.configuration().startNewBrowserForSetUp() && Neodymium.configuration().startNewBrowserForCleanUp())) { - browserMethodData.setAfterMethodsWithTestBrowser(afterMethodsWithTestBrowser); - return browserMethodData; + return new BrowserMethodData(browserTag, keepOpen, keepOpenOnFailure, false, false, afterMethodsWithTestBrowser); } boolean separateBrowserForSetupRequired = false; @@ -294,10 +287,7 @@ private BrowserMethodData addKeepBrowserOpenInformation(String browserTag, Metho separateBrowserForCleanupRequired = afterMethodsWithTestBrowser.isEmpty() && !afterMethods.isEmpty(); } - browserMethodData.setStartBrowserOnSetUp(separateBrowserForSetupRequired); - browserMethodData.setStartBrowserOnCleanUp(separateBrowserForCleanupRequired); - browserMethodData.setAfterMethodsWithTestBrowser(afterMethodsWithTestBrowser); - return browserMethodData; + return new BrowserMethodData(browserTag, keepOpen, keepOpenOnFailure, separateBrowserForSetupRequired, separateBrowserForCleanupRequired, afterMethodsWithTestBrowser); } private List computeRandomBrowsers(final Method method, final List randomBrowsersAnnotation, diff --git a/src/main/java/com/xceptance/neodymium/common/browser/BrowserMethodData.java b/src/main/java/com/xceptance/neodymium/common/browser/BrowserMethodData.java index de88581e..ce1b7bee 100644 --- a/src/main/java/com/xceptance/neodymium/common/browser/BrowserMethodData.java +++ b/src/main/java/com/xceptance/neodymium/common/browser/BrowserMethodData.java @@ -58,19 +58,4 @@ public List getAfterMethodsWithTestBrowser() { return afterMethodsWithTestBrowser; } - - public void setStartBrowserOnSetUp(boolean startBrowserOnSetUp) - { - this.startBrowserOnSetUp = startBrowserOnSetUp; - } - - public void setStartBrowserOnCleanUp(boolean startBrowserOnCleanUp) - { - this.startBrowserOnCleanUp = startBrowserOnCleanUp; - } - - public void setAfterMethodsWithTestBrowser(List afterMethodsWithTestBrowser) - { - this.afterMethodsWithTestBrowser = afterMethodsWithTestBrowser; - } } diff --git a/src/test/java/com/xceptance/neodymium/junit4/testclasses/browser/inheritance/BrowserParent.java b/src/test/java/com/xceptance/neodymium/junit4/testclasses/browser/inheritance/BrowserParent.java index 4954c0db..778f041e 100644 --- a/src/test/java/com/xceptance/neodymium/junit4/testclasses/browser/inheritance/BrowserParent.java +++ b/src/test/java/com/xceptance/neodymium/junit4/testclasses/browser/inheritance/BrowserParent.java @@ -1,11 +1,11 @@ package com.xceptance.neodymium.junit4.testclasses.browser.inheritance; import org.junit.Assert; -import org.junit.Test; import org.junit.runner.RunWith; import com.xceptance.neodymium.common.browser.Browser; import com.xceptance.neodymium.junit4.NeodymiumRunner; +import com.xceptance.neodymium.junit5.NeodymiumTest; import com.xceptance.neodymium.junit5.tests.NeodymiumWebDriverTest; import com.xceptance.neodymium.util.Neodymium; @@ -14,7 +14,7 @@ @RunWith(NeodymiumRunner.class) public abstract class BrowserParent { - @Test + @NeodymiumTest public void testParent() { Assert.assertNotNull(Neodymium.getDriver()); diff --git a/src/test/java/com/xceptance/neodymium/junit4/tests/BrowserStatementTest.java b/src/test/java/com/xceptance/neodymium/junit4/tests/BrowserStatementTest.java index b6fe7bbe..9d2c3fc6 100644 --- a/src/test/java/com/xceptance/neodymium/junit4/tests/BrowserStatementTest.java +++ b/src/test/java/com/xceptance/neodymium/junit4/tests/BrowserStatementTest.java @@ -476,12 +476,11 @@ public void testBrowserOverwrittingInheritance() throws Throwable { String[] expected = new String[] { - "test :: Browser Chrome_1024x768", - "testParent :: Browser Chrome_1024x768" + "test :: Browser Chrome_1024x768" }; checkDescription(BrowserOverwrittingChild.class, expected); Result result = JUnitCore.runClasses(BrowserOverwrittingChild.class); - checkPass(result, 2, 0); + checkPass(result, 1, 0); } private void checkChrome(BrowserConfiguration config) diff --git a/src/test/java/com/xceptance/neodymium/junit5/tests/BrowserStatementTest.java b/src/test/java/com/xceptance/neodymium/junit5/tests/BrowserStatementTest.java index 1fb692cc..c2bb1e40 100644 --- a/src/test/java/com/xceptance/neodymium/junit5/tests/BrowserStatementTest.java +++ b/src/test/java/com/xceptance/neodymium/junit5/tests/BrowserStatementTest.java @@ -458,12 +458,11 @@ public void testBrowserOverwrittingInheritance() throws Throwable { String[] expected = new String[] { - "test :: Browser Chrome_1024x768", - "testParent :: Browser Chrome_1024x768" + "test :: Browser Chrome_1024x768" }; checkDescription(BrowserOverwrittingChild.class, expected); NeodymiumTestExecutionSummary summary = run(BrowserOverwrittingChild.class); - checkPass(summary, 2, 0); + checkPass(summary, 1, 0); } private void checkChrome(BrowserConfiguration config)