From fa68a51991d524916e288aca0faec3c22f6ea176 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Mon, 23 Dec 2024 16:45:42 +0100 Subject: [PATCH] Revert "Merge branch '322-bug-browser-is-not-started-for-after-method-if-its-declared-in-different-class-than-the-test-itself' into #330-improvement-stabilize-unit-tests" This reverts commit 19c6a57d2747efb2f58d8be0d64703dab9e26c3c, reversing changes made to 99666f4662e32e7ee973898aa3cef804b9e5d413. --- .../common/browser/BrowserAfterRunner.java | 3 +- .../common/browser/BrowserBeforeRunner.java | 3 +- .../neodymium/common/browser/BrowserData.java | 10 +++--- .../browser/inheritance/BrowserChildTest.java | 33 ------------------- .../browser/inheritance/BrowserParent.java | 11 +------ .../browser/inheritance/BrowserChildTest.java | 33 ------------------- .../browser/inheritance/BrowserParent.java | 12 +------ 7 files changed, 8 insertions(+), 97 deletions(-) delete mode 100644 src/test/java/com/xceptance/neodymium/junit4/testclasses/browser/inheritance/BrowserChildTest.java delete mode 100644 src/test/java/com/xceptance/neodymium/junit5/testclasses/browser/inheritance/BrowserChildTest.java 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 257c095d..d7a5e840 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,7 @@ 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.addKeepBrowserOpenInformation(browserConfiguration.getBrowserTag(), - after.getDeclaringClass(), after) + BrowserMethodData browserTag = browserConfiguration != null ? BrowserData.addKeepBrowserOpenInformation(browserConfiguration.getBrowserTag(), 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 26e950d0..6a25fe99 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,7 @@ 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.addKeepBrowserOpenInformation(browserConfiguration.getBrowserTag(), - before.getDeclaringClass(), before) + BrowserMethodData browserTag = browserConfiguration != null ? BrowserData.addKeepBrowserOpenInformation(browserConfiguration.getBrowserTag(), 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 a2011b75..f4e1db35 100644 --- a/src/main/java/com/xceptance/neodymium/common/browser/BrowserData.java +++ b/src/main/java/com/xceptance/neodymium/common/browser/BrowserData.java @@ -32,14 +32,11 @@ public class BrowserData extends Data private List classRandomBrowsersAnnotation; - private Class testClass; - private static final String SYSTEM_PROPERTY_BROWSERDEFINITION = "browserdefinition"; public BrowserData(Class testClass) { this(); - this.testClass = testClass; initClassAnnotationsFor(testClass); } @@ -201,15 +198,15 @@ else if (!classRandomBrowsersAnnotation.isEmpty() && methodBrowsers.isEmpty()) { return browsers.stream() .filter(browserTag -> systemBrowserFilter.contains(browserTag)) - .map(browserTag -> addKeepBrowserOpenInformation(browserTag, testClass, testMethod)) + .map(browserTag -> addKeepBrowserOpenInformation(browserTag, testMethod)) .collect(Collectors.toList()); } return browsers.stream() - .map(browserTag -> addKeepBrowserOpenInformation(browserTag, testClass, testMethod)) + .map(browserTag -> addKeepBrowserOpenInformation(browserTag, testMethod)) .collect(Collectors.toList()); } - public static BrowserMethodData addKeepBrowserOpenInformation(String browserTag, Class testClass, Method method) + public static BrowserMethodData addKeepBrowserOpenInformation(String browserTag, Method method) { List methodKeepBrowserOpenAnnotations = getAnnotations(method, KeepBrowserOpen.class); List classKeepBrowserOpenAnnotations = getAnnotations(method.getDeclaringClass(), KeepBrowserOpen.class); @@ -247,6 +244,7 @@ public static BrowserMethodData addKeepBrowserOpenInformation(String browserTag, } } boolean junit5 = method.getAnnotation(NeodymiumTest.class) != null; + Class testClass = method.getDeclaringClass(); List afterMethodsWithTestBrowser = List.of(testClass.getMethods()).stream() .filter(classMethod -> (junit5 ? classMethod.getAnnotation(AfterEach.class) : classMethod.getAnnotation(After.class)) != null) diff --git a/src/test/java/com/xceptance/neodymium/junit4/testclasses/browser/inheritance/BrowserChildTest.java b/src/test/java/com/xceptance/neodymium/junit4/testclasses/browser/inheritance/BrowserChildTest.java deleted file mode 100644 index 82352952..00000000 --- a/src/test/java/com/xceptance/neodymium/junit4/testclasses/browser/inheritance/BrowserChildTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.xceptance.neodymium.junit4.testclasses.browser.inheritance; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import com.xceptance.neodymium.junit4.tests.NeodymiumWebDriverTest; -import com.xceptance.neodymium.util.Neodymium; - -public class BrowserChildTest extends BrowserParent -{ - @Before - public void before() - { - Assert.assertNotNull("No browser started for @Before method", Neodymium.getDriver()); - NeodymiumWebDriverTest.assertWebDriverAlive(Neodymium.getDriver()); - } - - @Test - public void test() - { - Assert.assertNotNull("No browser started for @Test method", Neodymium.getDriver()); - NeodymiumWebDriverTest.assertWebDriverAlive(Neodymium.getDriver()); - } - - @After - public void after() - { - Assert.assertNotNull("No browser started for @After method", Neodymium.getDriver()); - NeodymiumWebDriverTest.assertWebDriverAlive(Neodymium.getDriver()); - } -} 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 778f041e..612151af 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,23 +1,14 @@ package com.xceptance.neodymium.junit4.testclasses.browser.inheritance; -import org.junit.Assert; 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; @Browser("Chrome_1024x768") @Browser("Chrome_1500x1000") @RunWith(NeodymiumRunner.class) public abstract class BrowserParent { - @NeodymiumTest - public void testParent() - { - Assert.assertNotNull(Neodymium.getDriver()); - NeodymiumWebDriverTest.assertWebDriverAlive(Neodymium.getDriver()); - } + } diff --git a/src/test/java/com/xceptance/neodymium/junit5/testclasses/browser/inheritance/BrowserChildTest.java b/src/test/java/com/xceptance/neodymium/junit5/testclasses/browser/inheritance/BrowserChildTest.java deleted file mode 100644 index 6765b2e1..00000000 --- a/src/test/java/com/xceptance/neodymium/junit5/testclasses/browser/inheritance/BrowserChildTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.xceptance.neodymium.junit5.testclasses.browser.inheritance; - -import org.junit.Assert; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; - -import com.xceptance.neodymium.junit5.NeodymiumTest; -import com.xceptance.neodymium.junit5.tests.NeodymiumWebDriverTest; -import com.xceptance.neodymium.util.Neodymium; - -public class BrowserChildTest extends BrowserParent -{ - @BeforeEach - public void before() - { - Assert.assertNotNull("No browser started for @BeforeEach method", Neodymium.getDriver()); - NeodymiumWebDriverTest.assertWebDriverAlive(Neodymium.getDriver()); - } - - @NeodymiumTest - public void test() - { - Assert.assertNotNull("No browser started for @NeodymiumTest method", Neodymium.getDriver()); - NeodymiumWebDriverTest.assertWebDriverAlive(Neodymium.getDriver()); - } - - @AfterEach - public void after() - { - Assert.assertNotNull("No browser started for @AfterEach method", Neodymium.getDriver()); - NeodymiumWebDriverTest.assertWebDriverAlive(Neodymium.getDriver()); - } -} diff --git a/src/test/java/com/xceptance/neodymium/junit5/testclasses/browser/inheritance/BrowserParent.java b/src/test/java/com/xceptance/neodymium/junit5/testclasses/browser/inheritance/BrowserParent.java index d25c0d3d..56f47867 100644 --- a/src/test/java/com/xceptance/neodymium/junit5/testclasses/browser/inheritance/BrowserParent.java +++ b/src/test/java/com/xceptance/neodymium/junit5/testclasses/browser/inheritance/BrowserParent.java @@ -1,20 +1,10 @@ package com.xceptance.neodymium.junit5.testclasses.browser.inheritance; -import org.junit.Assert; - import com.xceptance.neodymium.common.browser.Browser; -import com.xceptance.neodymium.junit5.NeodymiumTest; -import com.xceptance.neodymium.junit5.tests.NeodymiumWebDriverTest; -import com.xceptance.neodymium.util.Neodymium; @Browser("Chrome_1024x768") @Browser("Chrome_1500x1000") public abstract class BrowserParent { - @NeodymiumTest - public void testParent() - { - Assert.assertNotNull(Neodymium.getDriver()); - NeodymiumWebDriverTest.assertWebDriverAlive(Neodymium.getDriver()); - } + }