From 879da985f4022e4f2d7ff2da5be8bb7a0e203106 Mon Sep 17 00:00:00 2001 From: Jonathan Austin Date: Wed, 27 Sep 2023 12:33:27 +1000 Subject: [PATCH] Decouple junit helper classes into their own module --- pom.xml | 1 + webfriends-selenium-elements/pom.xml | 10 ++-- .../smart/junit/SmartDriverTestCase.java | 47 ------------------- .../selenium/element/AbstractTestElement.java | 7 +-- webfriends-selenium-junit/pom.xml | 43 +++++++++++++++++ .../junit/listener}/ClosePoolListener.java | 2 +- .../listener}/ParallelCloseListener.java | 2 +- .../listener}/ServerStartStopListener.java | 4 +- .../junit/runner/AbstractFriendTestCase.java | 34 ++++++++++++++ .../webfriends/junit/runner}/FriendSuite.java | 7 ++- .../webfriends/junit}/server/Launcher.java | 2 +- .../junit}/server/ServerProvider.java | 2 +- .../junit}/server/ServerProviderDefault.java | 2 +- webfriends-selenium-util/pom.xml | 15 ------ .../selenium/util/driver/FriendTestCase.java | 28 +++++++++-- 15 files changed, 124 insertions(+), 82 deletions(-) delete mode 100644 webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/junit/SmartDriverTestCase.java create mode 100644 webfriends-selenium-junit/pom.xml rename {webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit => webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener}/ClosePoolListener.java (82%) rename {webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit => webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener}/ParallelCloseListener.java (85%) rename {webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit => webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener}/ServerStartStopListener.java (76%) create mode 100644 webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/runner/AbstractFriendTestCase.java rename {webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit => webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/runner}/FriendSuite.java (91%) rename {webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util => webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit}/server/Launcher.java (82%) rename {webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util => webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit}/server/ServerProvider.java (84%) rename {webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util => webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit}/server/ServerProviderDefault.java (87%) diff --git a/pom.xml b/pom.xml index 8deb636..2d9d242 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,7 @@ webfriends-pageobject-api webfriends-selenium-util webfriends-selenium-elements + webfriends-selenium-junit webfriends-selenium-wc diff --git a/webfriends-selenium-elements/pom.xml b/webfriends-selenium-elements/pom.xml index 352add9..3a2fd70 100644 --- a/webfriends-selenium-elements/pom.xml +++ b/webfriends-selenium-elements/pom.xml @@ -58,12 +58,12 @@ test - + - junit - junit - 4.13.2 - provided + com.github.bordertech.webfriends + webfriends-selenium-junit + ${project.version} + test diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/junit/SmartDriverTestCase.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/junit/SmartDriverTestCase.java deleted file mode 100644 index 27be378..0000000 --- a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/junit/SmartDriverTestCase.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.bordertech.webfriends.selenium.smart.junit; - -import com.github.bordertech.webfriends.selenium.smart.driver.SmartDriver; -import com.github.bordertech.webfriends.selenium.util.driver.FriendDriver; -import com.github.bordertech.webfriends.selenium.util.driver.FriendTestCase; -import com.github.bordertech.webfriends.selenium.util.junit.FriendSuite; -import org.junit.runner.RunWith; - -/** - * Test class that uses the {@link FriendSuite}. - */ -@RunWith(FriendSuite.class) -public class SmartDriverTestCase implements FriendTestCase { - - private SmartDriver driver; - private String baseUrl; - - @Override - public void initFriendTestCase(final FriendDriver driver, final String baseUrl) { - this.driver = (SmartDriver) driver; - this.baseUrl = baseUrl; - } - - @Override - public SmartDriver getDriver() { - return driver; - } - - @Override - public String getBaseUrl() { - return baseUrl; - } - - protected void navigateToPath(final String path) { - String url = buildTestUrl(path); - getDriver().navigateToUrl(url); - } - - /** - * @param path the path of the test resource - * @return the path append to the server base URL - */ - protected String buildTestUrl(final String path) { - return getBaseUrl() + path; - } - -} diff --git a/webfriends-selenium-elements/src/test/java/com/github/bordertech/webfriends/selenium/element/AbstractTestElement.java b/webfriends-selenium-elements/src/test/java/com/github/bordertech/webfriends/selenium/element/AbstractTestElement.java index a4357bc..baa0429 100644 --- a/webfriends-selenium-elements/src/test/java/com/github/bordertech/webfriends/selenium/element/AbstractTestElement.java +++ b/webfriends-selenium-elements/src/test/java/com/github/bordertech/webfriends/selenium/element/AbstractTestElement.java @@ -1,15 +1,16 @@ package com.github.bordertech.webfriends.selenium.element; -import org.junit.Before; import com.github.bordertech.webfriends.selenium.common.tag.TagTypeSelenium; -import com.github.bordertech.webfriends.selenium.smart.junit.SmartDriverTestCase; +import com.github.bordertech.webfriends.selenium.smart.driver.SmartDriver; +import com.github.bordertech.webfriends.junit.runner.AbstractFriendTestCase; +import org.junit.Before; /** * Abstract class for testing a selenium element. * * @param the element type being tested */ -public abstract class AbstractTestElement extends SmartDriverTestCase { +public abstract class AbstractTestElement extends AbstractFriendTestCase { private T element = null; diff --git a/webfriends-selenium-junit/pom.xml b/webfriends-selenium-junit/pom.xml new file mode 100644 index 0000000..a2ae30e --- /dev/null +++ b/webfriends-selenium-junit/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + webfriends-selenium-junit + webfriends-selenium-junit + Webfriends Selenium Junit Support + + + com.github.bordertech.webfriends + webfriends-parent + 0.0.6-SNAPSHOT + ../pom.xml + + + jar + + + + + + com.github.bordertech.webfriends + webfriends-selenium-util + ${project.version} + + + + + com.github.bordertech.lde + lde-api + 1.0.4 + + + + + junit + junit + 4.13.2 + + + + + \ No newline at end of file diff --git a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/ClosePoolListener.java b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener/ClosePoolListener.java similarity index 82% rename from webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/ClosePoolListener.java rename to webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener/ClosePoolListener.java index 21eb9ac..6d9d8ff 100644 --- a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/ClosePoolListener.java +++ b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener/ClosePoolListener.java @@ -1,4 +1,4 @@ -package com.github.bordertech.webfriends.selenium.util.junit; +package com.github.bordertech.webfriends.junit.listener; import com.github.bordertech.webfriends.selenium.util.driver.DriverCache; import org.junit.runner.Result; diff --git a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/ParallelCloseListener.java b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener/ParallelCloseListener.java similarity index 85% rename from webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/ParallelCloseListener.java rename to webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener/ParallelCloseListener.java index 6567eed..109d4bb 100644 --- a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/ParallelCloseListener.java +++ b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener/ParallelCloseListener.java @@ -1,4 +1,4 @@ -package com.github.bordertech.webfriends.selenium.util.junit; +package com.github.bordertech.webfriends.junit.listener; import com.github.bordertech.webfriends.selenium.util.driver.FriendDriver; import org.junit.runner.Result; diff --git a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/ServerStartStopListener.java b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener/ServerStartStopListener.java similarity index 76% rename from webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/ServerStartStopListener.java rename to webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener/ServerStartStopListener.java index cbdccdc..a8f10e9 100644 --- a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/ServerStartStopListener.java +++ b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/listener/ServerStartStopListener.java @@ -1,6 +1,6 @@ -package com.github.bordertech.webfriends.selenium.util.junit; +package com.github.bordertech.webfriends.junit.listener; -import com.github.bordertech.webfriends.selenium.util.server.Launcher; +import com.github.bordertech.webfriends.junit.server.Launcher; import org.junit.runner.Description; import org.junit.runner.Result; import org.junit.runner.notification.RunListener; diff --git a/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/runner/AbstractFriendTestCase.java b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/runner/AbstractFriendTestCase.java new file mode 100644 index 0000000..6c0828d --- /dev/null +++ b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/runner/AbstractFriendTestCase.java @@ -0,0 +1,34 @@ +package com.github.bordertech.webfriends.junit.runner; + +import com.github.bordertech.webfriends.selenium.util.driver.FriendDriver; +import com.github.bordertech.webfriends.selenium.util.driver.FriendTestCase; +import org.junit.runner.RunWith; + +/** + * Test class that uses the {@link FriendSuite} runner. + * + * @param the driver type + */ +@RunWith(FriendSuite.class) +public abstract class AbstractFriendTestCase implements FriendTestCase { + + private T driver; + private String baseUrl; + + @Override + public void initFriendTestCase(final T driver, final String baseUrl) { + this.driver = driver; + this.baseUrl = baseUrl; + } + + @Override + public T getDriver() { + return driver; + } + + @Override + public String getBaseUrl() { + return baseUrl; + } + +} diff --git a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/FriendSuite.java b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/runner/FriendSuite.java similarity index 91% rename from webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/FriendSuite.java rename to webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/runner/FriendSuite.java index cd2268e..e4c3900 100644 --- a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/junit/FriendSuite.java +++ b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/runner/FriendSuite.java @@ -1,11 +1,14 @@ -package com.github.bordertech.webfriends.selenium.util.junit; +package com.github.bordertech.webfriends.junit.runner; +import com.github.bordertech.webfriends.junit.listener.ClosePoolListener; +import com.github.bordertech.webfriends.junit.listener.ParallelCloseListener; +import com.github.bordertech.webfriends.junit.listener.ServerStartStopListener; +import com.github.bordertech.webfriends.junit.server.Launcher; import com.github.bordertech.webfriends.selenium.util.driver.ConfigUtilProperties; import com.github.bordertech.webfriends.selenium.util.driver.DriverCache; import com.github.bordertech.webfriends.selenium.util.driver.FriendDriver; import com.github.bordertech.webfriends.selenium.util.driver.FriendTestCase; import com.github.bordertech.webfriends.selenium.util.driver.type.WebDriverType; -import com.github.bordertech.webfriends.selenium.util.server.Launcher; import java.util.ArrayList; import java.util.Collections; import java.util.List; diff --git a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/server/Launcher.java b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/server/Launcher.java similarity index 82% rename from webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/server/Launcher.java rename to webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/server/Launcher.java index 2e86a71..6bc13c3 100644 --- a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/server/Launcher.java +++ b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/server/Launcher.java @@ -1,4 +1,4 @@ -package com.github.bordertech.webfriends.selenium.util.server; +package com.github.bordertech.webfriends.junit.server; import com.github.bordertech.didums.Didums; diff --git a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/server/ServerProvider.java b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/server/ServerProvider.java similarity index 84% rename from webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/server/ServerProvider.java rename to webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/server/ServerProvider.java index b477ca8..547c11d 100644 --- a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/server/ServerProvider.java +++ b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/server/ServerProvider.java @@ -1,4 +1,4 @@ -package com.github.bordertech.webfriends.selenium.util.server; +package com.github.bordertech.webfriends.junit.server; /** * Local server launcher. diff --git a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/server/ServerProviderDefault.java b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/server/ServerProviderDefault.java similarity index 87% rename from webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/server/ServerProviderDefault.java rename to webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/server/ServerProviderDefault.java index 3ca26f9..ba7e867 100644 --- a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/server/ServerProviderDefault.java +++ b/webfriends-selenium-junit/src/main/java/com/github/bordertech/webfriends/junit/server/ServerProviderDefault.java @@ -1,4 +1,4 @@ -package com.github.bordertech.webfriends.selenium.util.server; +package com.github.bordertech.webfriends.junit.server; import com.github.bordertech.lde.api.LdeLauncher; diff --git a/webfriends-selenium-util/pom.xml b/webfriends-selenium-util/pom.xml index 6e126bc..a0ddf6a 100644 --- a/webfriends-selenium-util/pom.xml +++ b/webfriends-selenium-util/pom.xml @@ -35,13 +35,6 @@ 5.5.2 - - - com.github.bordertech.lde - lde-api - 1.0.4 - - com.github.bordertech.didums @@ -63,14 +56,6 @@ 1.10.0 - - - junit - junit - 4.13.2 - provided - - \ No newline at end of file diff --git a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/driver/FriendTestCase.java b/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/driver/FriendTestCase.java index a7780a4..40b491c 100644 --- a/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/driver/FriendTestCase.java +++ b/webfriends-selenium-util/src/main/java/com/github/bordertech/webfriends/selenium/util/driver/FriendTestCase.java @@ -2,8 +2,10 @@ /** * Friend test case used by the unit test runners. + * + * @param the driver type */ -public interface FriendTestCase { +public interface FriendTestCase { /** * Initialize the test case. @@ -11,16 +13,36 @@ public interface FriendTestCase { * @param driver the friend web driver * @param baseUrl the base URL for the tests */ - void initFriendTestCase(final FriendDriver driver, final String baseUrl); + void initFriendTestCase(final T driver, final String baseUrl); /** * @return the runner driver */ - FriendDriver getDriver(); + T getDriver(); /** * @return the base URL for the tests */ String getBaseUrl(); + /** + * Navigate to the path relative to the server base URL. + * + * @param path the path to navigate to + */ + default void navigateToPath(final String path) { + String url = buildTestUrl(path); + getDriver().navigateToUrl(url); + } + + /** + * Build the URL with the provided path appended to the server base URL. + * + * @param path the path of the test resource + * @return the path appended to the server base URL + */ + default String buildTestUrl(final String path) { + return getBaseUrl() + path; + } + }