mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 10:20:41 +00:00
First integration test
This commit is contained in:
parent
5b3a0f3a0f
commit
370acda75c
26
pom.xml
26
pom.xml
@ -103,6 +103,17 @@
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
@ -172,6 +183,21 @@
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<trimStackTrace>false</trimStackTrace>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
|
27
src/test/java/edu/kit/typicalc/view/AbstractIT.java
Normal file
27
src/test/java/edu/kit/typicalc/view/AbstractIT.java
Normal file
@ -0,0 +1,27 @@
|
||||
package edu.kit.typicalc.view;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
||||
import com.vaadin.testbench.IPAddress;
|
||||
import com.vaadin.testbench.ScreenshotOnFailureRule;
|
||||
import com.vaadin.testbench.TestBenchTestCase;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
|
||||
/**
|
||||
* Base class for all our integration tests, allowing us to change the applicable driver,
|
||||
* test URL or other configurations in one place.
|
||||
*/
|
||||
public abstract class AbstractIT extends TestBenchTestCase {
|
||||
|
||||
@Rule
|
||||
public ScreenshotOnFailureRule rule = new ScreenshotOnFailureRule(this,
|
||||
true);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
setDriver(new FirefoxDriver());
|
||||
getDriver().get("http://127.0.0.1:8080");
|
||||
}
|
||||
|
||||
}
|
93
src/test/java/edu/kit/typicalc/view/ScreenshotIT.java
Normal file
93
src/test/java/edu/kit/typicalc/view/ScreenshotIT.java
Normal file
@ -0,0 +1,93 @@
|
||||
package edu.kit.typicalc.view;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import edu.kit.typicalc.view.main.MainViewImpl;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.HasCapabilities;
|
||||
|
||||
import com.vaadin.testbench.Parameters;
|
||||
import com.vaadin.testbench.commands.TestBenchCommandExecutor;
|
||||
|
||||
/**
|
||||
* This example contains usage examples of screenshot comparison feature.
|
||||
* <p>
|
||||
*/
|
||||
public class ScreenshotIT extends AbstractIT {
|
||||
|
||||
/**
|
||||
* We'll want to perform some additional setup functions, so we override the
|
||||
* setUp() method.
|
||||
*/
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
|
||||
// Set a fixed viewport size so the screenshot is always the same
|
||||
// resolution
|
||||
testBench().resizeViewPortTo(1000, 500);
|
||||
|
||||
// Define the directory for reference screenshots and for error files
|
||||
Parameters.setScreenshotReferenceDirectory("src/test/resources/screenshots");
|
||||
Parameters.setScreenshotErrorDirectory("target/screenshot_errors");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialView() throws Exception {
|
||||
// Change this calculation after running the test once to see how errors
|
||||
// in screenshots are verified.
|
||||
// The output is placed in target/screenshot_errors
|
||||
|
||||
generateReferenceIfNotFound("initialView");
|
||||
|
||||
// Compare screen with reference image with id "oneplustwo" from the
|
||||
// reference image directory. Reference image filenames also contain
|
||||
// browser, version and platform.
|
||||
assertTrue(
|
||||
"Screenshot comparison for 'initialView' failed, see "
|
||||
+ Parameters.getScreenshotErrorDirectory()
|
||||
+ " for error images",
|
||||
testBench().compareScreen("initialView"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a reference screenshot if no reference exists.
|
||||
* <p>
|
||||
* This method only exists for demonstration purposes. Normally you should
|
||||
* perform this task manually after verifying that the screenshots look
|
||||
* correct.
|
||||
*
|
||||
* @param referenceId
|
||||
* the id of the reference image
|
||||
* @throws IOException
|
||||
*/
|
||||
private void generateReferenceIfNotFound(String referenceId)
|
||||
throws IOException {
|
||||
String refName = ((TestBenchCommandExecutor) testBench())
|
||||
.getReferenceNameGenerator().generateName(referenceId,
|
||||
((HasCapabilities) getDriver()).getCapabilities());
|
||||
File referenceFile = new File(
|
||||
Parameters.getScreenshotReferenceDirectory(), refName + ".png");
|
||||
if (referenceFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!referenceFile.getParentFile().exists()) {
|
||||
referenceFile.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
File errorFile = new File(Parameters.getScreenshotErrorDirectory(),
|
||||
referenceFile.getName());
|
||||
|
||||
// Take a screenshot and move it to the reference location
|
||||
testBench().compareScreen(referenceId);
|
||||
errorFile.renameTo(referenceFile);
|
||||
|
||||
System.out.println("Created new reference file in " + referenceFile);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -5,5 +5,6 @@
|
||||
|
||||
<suppressions>
|
||||
<suppress files="src/main/resources/*" checks=".*" />
|
||||
<suppress files="src/test/resources/*" checks=".*" />
|
||||
</suppressions>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user