Skip to content

Commit

Permalink
Decouple junit helper classes into their own module
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanaustin committed Sep 27, 2023
1 parent c252320 commit 879da98
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 82 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<module>webfriends-pageobject-api</module>
<module>webfriends-selenium-util</module>
<module>webfriends-selenium-elements</module>
<module>webfriends-selenium-junit</module>
<module>webfriends-selenium-wc</module>
</modules>

Expand Down
10 changes: 5 additions & 5 deletions webfriends-selenium-elements/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
<scope>test</scope>
</dependency>

<!-- JUnit -->
<!-- Selenium Junits -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>provided</scope>
<groupId>com.github.bordertech.webfriends</groupId>
<artifactId>webfriends-selenium-junit</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 <T> the element type being tested
*/
public abstract class AbstractTestElement<T extends SElement> extends SmartDriverTestCase {
public abstract class AbstractTestElement<T extends SElement> extends AbstractFriendTestCase<SmartDriver> {

private T element = null;

Expand Down
43 changes: 43 additions & 0 deletions webfriends-selenium-junit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<name>webfriends-selenium-junit</name>
<artifactId>webfriends-selenium-junit</artifactId>
<description>Webfriends Selenium Junit Support</description>

<parent>
<groupId>com.github.bordertech.webfriends</groupId>
<artifactId>webfriends-parent</artifactId>
<version>0.0.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<packaging>jar</packaging>

<dependencies>

<!-- Selenium Utils -->
<dependency>
<groupId>com.github.bordertech.webfriends</groupId>
<artifactId>webfriends-selenium-util</artifactId>
<version>${project.version}</version>
</dependency>

<!-- LDE API -->
<dependency>
<groupId>com.github.bordertech.lde</groupId>
<artifactId>lde-api</artifactId>
<version>1.0.4</version>
</dependency>

<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <T> the driver type
*/
@RunWith(FriendSuite.class)
public abstract class AbstractFriendTestCase<T extends FriendDriver> implements FriendTestCase<T> {

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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.bordertech.webfriends.selenium.util.server;
package com.github.bordertech.webfriends.junit.server;

/**
* Local server launcher.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
15 changes: 0 additions & 15 deletions webfriends-selenium-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@
<version>5.5.2</version>
</dependency>

<!-- LDE API -->
<dependency>
<groupId>com.github.bordertech.lde</groupId>
<artifactId>lde-api</artifactId>
<version>1.0.4</version>
</dependency>

<!-- Didums -->
<dependency>
<groupId>com.github.bordertech.didums</groupId>
Expand All @@ -63,14 +56,6 @@
<version>1.10.0</version>
</dependency>

<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,47 @@

/**
* Friend test case used by the unit test runners.
*
* @param <T> the driver type
*/
public interface FriendTestCase {
public interface FriendTestCase<T extends FriendDriver> {

/**
* Initialize the test case.
*
* @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;
}

}

0 comments on commit 879da98

Please sign in to comment.