Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
#293 JUnit5 working in IDEA, finally!
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrzyzanowski committed Oct 25, 2018
1 parent 38496f2 commit 5152ac9
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 59 deletions.
4 changes: 4 additions & 0 deletions bb-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ limitations under the License.
</dependency>

<!-- tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
Expand Down
15 changes: 7 additions & 8 deletions bb-core/src/main/java/com/cognifide/qa/bb/wait/BobcatWait.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import com.cognifide.qa.bb.guice.ThreadScoped;
import com.google.inject.Inject;
import com.google.inject.Provider;

/**
* This is the go-to solution for handling dynamic elements with Bobcat.
Expand All @@ -49,12 +50,8 @@ public class BobcatWait {

private List<Class<? extends Throwable>> ignoredExceptions = new ArrayList<>();

private WebDriver webDriver;

@Inject
public BobcatWait(WebDriver webDriver) {
this.webDriver = webDriver;
}
private Provider<WebDriver> webDriverProvider;

/**
* Allows to customize the timings (explicit &amp; implicit timeout + polling time).
Expand Down Expand Up @@ -125,20 +122,22 @@ public boolean isConditionMet(final ExpectedCondition<?> condition) {
* Sets implicit timeout to {@value Timings#NEAR_ZERO} milliseconds.
*/
protected void setImplicitTimeoutToNearZero() {
webDriver.manage().timeouts().implicitlyWait(Timings.NEAR_ZERO, TimeUnit.SECONDS);
webDriverProvider.get().manage().timeouts().implicitlyWait(Timings.NEAR_ZERO, TimeUnit.SECONDS);
}

/**
* Restores implicit timeout to the value defined in the {@link Timings} instance.
*/
protected void restoreImplicitTimeout() {
webDriver.manage().timeouts().implicitlyWait(timings.getImplicitTimeout(), TimeUnit.SECONDS);
webDriverProvider.get().manage().timeouts()
.implicitlyWait(timings.getImplicitTimeout(), TimeUnit.SECONDS);
}

/**
* @return an instance of {@link WebDriverWait} based on the provided {@link Timings}
*/
protected WebDriverWait getWebDriverWait() {
return new WebDriverWait(webDriver, timings.getExplicitTimeout(), timings.getPollingInterval());
return new WebDriverWait(webDriverProvider.get(), timings.getExplicitTimeout(),
timings.getPollingInterval());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InOrder;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;

import com.cognifide.qa.bb.provider.selenium.webdriver.WebDriverProvider;

@ExtendWith(MockitoExtension.class)
public class BobcatWaitTest {

@Mock
private WebDriverProvider webDriverProvider;

@Mock
private WebDriver webDriver;

Expand All @@ -49,14 +55,15 @@ public class BobcatWaitTest {
@Mock
private ExpectedCondition<Boolean> condition;

@InjectMocks
private BobcatWait tested;

@BeforeEach
public void setup() {
when(webDriver.manage()).thenReturn(options);
when(options.timeouts()).thenReturn(timeouts);
when(timeouts.implicitlyWait(anyLong(), any())).thenReturn(timeouts);
tested = new BobcatWait(webDriver);
when(webDriverProvider.get()).thenReturn(webDriver);
}

@Test
Expand Down
25 changes: 15 additions & 10 deletions bb-email/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,21 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<!--<dependency>-->
<!--<groupId>org.junit.jupiter</groupId>-->
<!--<artifactId>junit-jupiter-engine</artifactId>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.junit.jupiter</groupId>-->
<!--<artifactId>junit-jupiter-params</artifactId>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions bb-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<configurationParameters>
junit.jupiter.extensions.autodetection.enabled = true
</configurationParameters>
</properties>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@

public class YamlConfigTest {

@BeforeEach
public void cleanProperties() {
System.setProperties(new Properties());
}

@Test
public void additionalContextsShouldBeLoadedWhenSelectedInConfig() {
Properties properties = getInjector().getInstance(Properties.class);
Expand Down
5 changes: 0 additions & 5 deletions bb-junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
<artifactId>junit-jupiter-api</artifactId>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
Expand Down
43 changes: 13 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ See the License for the specific language governing permissions and
limitations under the License.
#L%
-->
<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">
<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>

<groupId>com.cognifide.qa.bb</groupId>
Expand All @@ -30,8 +28,7 @@ limitations under the License.

<name>Bobcat</name>
<description>Bobcat is an automated testing framework for functional testing of web
applications.
</description>
applications.</description>
<url>https://github.com/cognifide/bobcat</url>
<inceptionYear>2016</inceptionYear>

Expand Down Expand Up @@ -88,11 +85,15 @@ limitations under the License.

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>

<jacoco.version>0.8.2</jacoco.version>
<selenium.version>3.14.0</selenium.version>
<guice.version>4.2.0</guice.version>
<cucumber.version>3.0.2</cucumber.version>
<version.logback>1.2.3</version.logback>
<junit.jupiter.version>5.3.1</junit.jupiter.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -214,22 +215,17 @@ limitations under the License.
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.3.1</version>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.2.0</version>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down Expand Up @@ -265,12 +261,6 @@ limitations under the License.
<artifactId>greenmail</artifactId>
<version>1.5.8</version>
<scope>test</scope>
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>junit</groupId>-->
<!--<artifactId>junit</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
</dependency>

<dependency>
Expand Down Expand Up @@ -319,17 +309,6 @@ limitations under the License.
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<fork>true</fork>
<source>1.8</source>
<target>1.8</target>
<compilerVersion>1.8</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
Expand Down Expand Up @@ -477,6 +456,10 @@ limitations under the License.
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
Expand Down

0 comments on commit 5152ac9

Please sign in to comment.