Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use quarkus integration tests and generate screenshots on failure #34

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions integration-tests/common-test-code/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -54,6 +56,12 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

import java.util.List;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.flow.quarkus.it.regression.RemoveOldContentView;
import com.vaadin.testbench.TestBenchElement;

@QuarkusTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@QuarkusIntegrationTest
public class RemoveOldContentTest extends AbstractCdiTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

import java.io.IOException;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By;

import com.vaadin.flow.quarkus.it.routecontext.ApartBean;
Expand All @@ -43,8 +42,7 @@
import com.vaadin.flow.quarkus.it.routecontext.RerouteView;
import com.vaadin.flow.quarkus.it.routecontext.RootView;

@QuarkusTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@QuarkusIntegrationTest
public class RouteContextTest extends AbstractCdiTest {

private String uiId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

import java.io.IOException;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

Expand All @@ -34,8 +33,7 @@
import com.vaadin.flow.server.SessionInitEvent;
import com.vaadin.flow.server.UIInitEvent;

@QuarkusTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@QuarkusIntegrationTest
public class ServiceTest extends AbstractCdiTest {

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

import java.io.IOException;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -31,8 +30,7 @@
import static com.vaadin.flow.quarkus.it.sessioncontext.SessionContextView.SessionScopedBean.DESTROY_COUNT;
import static org.junit.jupiter.api.Assertions.assertTrue;

@QuarkusTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@QuarkusIntegrationTest
public class SessionContextTest extends AbstractCdiTest {

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.vaadin.flow.quarkus.it;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.flow.component.html.testbench.LabelElement;
import com.vaadin.flow.component.html.testbench.NativeButtonElement;
import com.vaadin.flow.test.AbstractChromeTest;

@QuarkusTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@QuarkusIntegrationTest
public class SmokeTest extends AbstractChromeTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@

import java.io.IOException;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import com.vaadin.flow.quarkus.it.uicontext.UIContextRootView;
import com.vaadin.flow.quarkus.it.uicontext.UINormalScopedBeanView;
import com.vaadin.flow.quarkus.it.uicontext.UIScopedBean;
import com.vaadin.flow.quarkus.it.uicontext.UIScopedLabel;
import com.vaadin.flow.quarkus.it.uicontext.UIScopedView;

@QuarkusTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@QuarkusIntegrationTest
public class UIContextTest extends AbstractCdiTest {

private String uiId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

import java.util.List;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By;

import com.vaadin.flow.quarkus.it.uievents.UIEventsView;
Expand All @@ -31,8 +30,7 @@
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.testbench.TestBenchElement;

@QuarkusTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@QuarkusIntegrationTest
public class UIEventsTest extends AbstractCdiTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.vaadin.flow.testcategory.ChromeTests;
Expand All @@ -20,6 +22,8 @@
* API
*/
@Category(ChromeTests.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(ScreenshotsOnFailureExtension.class)
public abstract class AbstractChromeTest extends ChromeBrowserTest {

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2000-2021 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.test;

import java.util.logging.Logger;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
import org.junit.runner.Description;
import org.mockito.Mockito;

import com.vaadin.testbench.ScreenshotOnFailureRule;

public class ScreenshotsOnFailureExtension
implements TestExecutionExceptionHandler {

private static class ScreenshotOnFailureRuleDelegate
extends ScreenshotOnFailureRule {
public ScreenshotOnFailureRuleDelegate(AbstractChromeTest test) {
super(test);
}

@Override
protected void failed(Throwable throwable, Description description) {
super.failed(throwable, description);
}
}

@Override
public void handleTestExecutionException(ExtensionContext context,
Throwable throwable) throws Throwable {
if (!context.getTestInstance().isPresent()) {
getLogger().warning(
"There is no test instance in the context, can't generate a screenshot");
throw throwable;
}
Object object = context.getTestInstance().get();
AbstractChromeTest test = (AbstractChromeTest) object;

ScreenshotOnFailureRuleDelegate delegate = new ScreenshotOnFailureRuleDelegate(
test);
if (!context.getTestClass().isPresent()) {
getLogger().warning(
"There is no test class in the context, can't generate a screenshot");
throw throwable;
}

Description description;
if (context.getTestMethod().isPresent()) {
description = Description.createTestDescription(
context.getTestClass().get(),
context.getTestMethod().get().getName());
} else {
description = Mockito.mock(Description.class);
Mockito.when(description.getDisplayName())
.thenReturn(context.getDisplayName());
}
delegate.failed(throwable, description);
throw throwable;
}

private Logger getLogger() {
return Logger.getLogger(ScreenshotsOnFailureExtension.class.getName());
}
}
12 changes: 11 additions & 1 deletion integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@
</dependency>
</dependencies>
</dependencyManagement>
</project>

<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>