Integration tests: run asserts last

This commit is contained in:
Arne Keller 2021-03-12 11:07:26 +01:00
parent ba8d221a42
commit 002f402691

View File

@ -5,10 +5,13 @@ import com.vaadin.flow.component.orderedlayout.testbench.HorizontalLayoutElement
import com.vaadin.testbench.Parameters; import com.vaadin.testbench.Parameters;
import com.vaadin.testbench.commands.TestBenchCommandExecutor; import com.vaadin.testbench.commands.TestBenchCommandExecutor;
import edu.kit.typicalc.view.pageobjects.*; import edu.kit.typicalc.view.pageobjects.*;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -22,6 +25,8 @@ public class ScreenshotIT extends AbstractIT {
private static final String IDENTITY_TERM = "λx.x"; private static final String IDENTITY_TERM = "λx.x";
private static final String LET_TERM = "let f = λx. g y y in f 3"; private static final String LET_TERM = "let f = λx. g y y in f 3";
private List<Boolean> matches = new ArrayList<>();
/** /**
* We'll want to perform some additional setup functions, so we override the * We'll want to perform some additional setup functions, so we override the
* setUp() method. * setUp() method.
@ -30,6 +35,8 @@ public class ScreenshotIT extends AbstractIT {
public void setUp() { public void setUp() {
super.setUp(); super.setUp();
matches = new ArrayList<>();
// Set a fixed viewport size so the screenshot is always the same // Set a fixed viewport size so the screenshot is always the same
// resolution // resolution
testBench().resizeViewPortTo(1600, 800); testBench().resizeViewPortTo(1600, 800);
@ -39,6 +46,13 @@ public class ScreenshotIT extends AbstractIT {
Parameters.setScreenshotErrorDirectory("target/screenshot_errors"); Parameters.setScreenshotErrorDirectory("target/screenshot_errors");
} }
@After
public void checkMatches() {
for (int i = 0; i < matches.size(); i++) {
assertTrue(String.format("comparison %d failed", i), matches.get(i));
}
}
@Test @Test
public void initialView() throws Exception { public void initialView() throws Exception {
// Change this calculation after running the test once to see how errors // Change this calculation after running the test once to see how errors
@ -83,29 +97,20 @@ public class ScreenshotIT extends AbstractIT {
inputBar.typeInfer(); inputBar.typeInfer();
TestBenchCommandExecutor executor = getCommandExecutor(); TestBenchCommandExecutor executor = getCommandExecutor();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue("Screenshot comparison for 'letView' failed, see " matches.add(testBench().compareScreen("letView"));
+ Parameters.getScreenshotErrorDirectory()
+ " for error images",
testBench().compareScreen("letView"));
ControlPanelElement control = $(ControlPanelElement.class).waitForFirst(); ControlPanelElement control = $(ControlPanelElement.class).waitForFirst();
control.openShareDialog(); control.openShareDialog();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue("Screenshot comparison for 'letShareDialog' failed, see " matches.add(testBench().compareScreen("letShareDialog"));
+ Parameters.getScreenshotErrorDirectory()
+ " for error images",
testBench().compareScreen("letShareDialog"));
ShareDialogElement shareDialogElement = $(ShareDialogElement.class).waitForFirst(); ShareDialogElement shareDialogElement = $(ShareDialogElement.class).waitForFirst();
String permalink = shareDialogElement.getPermalink(); String permalink = shareDialogElement.getPermalink();
getDriver().get(permalink); getDriver().get(permalink);
assertTrue("Screenshot comparison for 'letView' from permalink failed, see " matches.add(testBench().compareScreen("letView"));
+ Parameters.getScreenshotErrorDirectory()
+ " for error images",
testBench().compareScreen("letView"));
// TODO: jeden Schritt durchgehen? // TODO: jeden Schritt durchgehen?
} }
@ -118,15 +123,13 @@ public class ScreenshotIT extends AbstractIT {
String term = "λx.x"; String term = "λx.x";
exampleDialog.insertExample(term); exampleDialog.insertExample(term);
Assert.assertEquals(term, inputBar.getCurrentValue()); matches.add(term.equals(inputBar.getCurrentValue()));
TestBenchCommandExecutor executor = getCommandExecutor(); TestBenchCommandExecutor executor = getCommandExecutor();
executor.waitForVaadin(); executor.waitForVaadin();
// check that the example is copied to the input bar // check that the example is copied to the input bar
// TODO: the blinking cursor could cause issues here matches.add(testBench().compareScreen("chooseExample1"));
assertTrue("Screenshot comparison for 'chooseExample' (stage 1) failed",
testBench().compareScreen("chooseExample1"));
inputBar.typeInfer(); inputBar.typeInfer();
executor.waitForVaadin(); executor.waitForVaadin();
@ -135,66 +138,61 @@ public class ScreenshotIT extends AbstractIT {
executor.waitForVaadin(); executor.waitForVaadin();
// check that the example is inferred correctly // check that the example is inferred correctly
assertTrue("Screenshot comparison for 'chooseExample' (stage 2) failed", matches.add(testBench().compareScreen("chooseExample2"));
testBench().compareScreen("chooseExample2"));
control.lastStep(); control.lastStep();
executor.waitForVaadin(); executor.waitForVaadin();
// check that the example is unified correctly // check that the example is unified correctly
assertTrue("Screenshot comparison for 'chooseExample' (stage 3) failed", matches.add(testBench().compareScreen("chooseExample3"));
testBench().compareScreen("chooseExample3"));
} }
@Test @Test
public void exportLatexWithAssumptions() throws IOException { public void exportLatexWithAssumptions() throws IOException {
TestBenchCommandExecutor executor = getCommandExecutor(); TestBenchCommandExecutor executor = getCommandExecutor();
InputBarElement inputBar = $(InputBarElement.class).first(); InputBarElement inputBar = $(InputBarElement.class).first();
String term = "λx. f x"; String term = "λx. f x";
inputBar.setCurrentValue(term); inputBar.setCurrentValue(term);
// check if the correct term is entered // check if the correct term is entered
Assert.assertEquals(term, inputBar.getCurrentValue()); matches.add(term.equals(inputBar.getCurrentValue()));
inputBar.openTypeAssumptionsArea(); inputBar.openTypeAssumptionsArea();
TypeAssumptionsAreaElement assumptionsArea = $(TypeAssumptionsAreaElement.class).waitForFirst(); TypeAssumptionsAreaElement assumptionsArea = $(TypeAssumptionsAreaElement.class).waitForFirst();
assumptionsArea.addTypeAssumption(); assumptionsArea.addTypeAssumption();
executor.waitForVaadin(); executor.waitForVaadin();
TypeAssumptionFieldElement assumptionField = assumptionsArea.getLastTypeAssumption(); TypeAssumptionFieldElement assumptionField = assumptionsArea.getLastTypeAssumption();
String variable = "f"; String variable = "f";
String type = "int -> y"; String type = "int -> y";
assumptionField.setVariable(variable); assumptionField.setVariable(variable);
assumptionField.setType(type); assumptionField.setType(type);
assumptionsArea.$(HorizontalLayoutElement.class).first().$(ButtonElement.class).last().focus(); assumptionsArea.$(HorizontalLayoutElement.class).first().$(ButtonElement.class).last().focus();
executor.waitForVaadin(); executor.waitForVaadin();
// check if type assumption is added correctly // check if type assumption is added correctly
assertTrue("Screenshot comparison for 'exportLatexWithAssumptions' (stage 1) failed", matches.add(testBench().compareScreen("exportLatexWithAssumptions1"));
testBench().compareScreen("exportLatexWithAssumptions1"));
assumptionsArea.closeDialog(); assumptionsArea.closeDialog();
inputBar.typeInfer(); inputBar.typeInfer();
executor.waitForVaadin(); executor.waitForVaadin();
ControlPanelElement controlPanel = $(ControlPanelElement.class).waitForFirst(); ControlPanelElement controlPanel = $(ControlPanelElement.class).waitForFirst();
controlPanel.lastStep(); controlPanel.lastStep();
executor.waitForVaadin(); executor.waitForVaadin();
// check if the algorithm is processed correctly // check if the algorithm is processed correctly
assertTrue("Screenshot comparison for 'exportLatexWithAssumptions' (stage 2) failed", matches.add(testBench().compareScreen("exportLatexWithAssumptions2"));
testBench().compareScreen("exportLatexWithAssumptions2"));
controlPanel.openShareDialog(); controlPanel.openShareDialog();
executor.waitForVaadin(); executor.waitForVaadin();
// check if the share dialog content is correct // check if the share dialog content is correct
assertTrue("Screenshot comparison for 'exportLatexWithAssumptions' (stage 3) failed", matches.add(testBench().compareScreen("exportLatexWithAssumptions3"));
testBench().compareScreen("exportLatexWithAssumptions3"));
} }
@Test @Test
public void testScenario1() throws IOException { public void testScenario1() throws IOException {
TestBenchCommandExecutor executor = getCommandExecutor(); TestBenchCommandExecutor executor = getCommandExecutor();
InputBarElement inputBar = $(InputBarElement.class).first(); InputBarElement inputBar = $(InputBarElement.class).first();
String term = "λx. f x"; String term = "λx. f x";
inputBar.setCurrentValue(term); inputBar.setCurrentValue(term);
@ -205,31 +203,31 @@ public class ScreenshotIT extends AbstractIT {
ControlPanelElement controlPanelElement = $(ControlPanelElement.class).first(); ControlPanelElement controlPanelElement = $(ControlPanelElement.class).first();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue(testBench().compareScreen("testScenario1_step0")); matches.add(testBench().compareScreen("testScenario1_step0"));
controlPanelElement.nextStep(); controlPanelElement.nextStep();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue(testBench().compareScreen("testScenario1_step1")); matches.add(testBench().compareScreen("testScenario1_step1"));
controlPanelElement.nextStep(); controlPanelElement.nextStep();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue(testBench().compareScreen("testScenario1_step2")); matches.add(testBench().compareScreen("testScenario1_step2"));
controlPanelElement.nextStep(); controlPanelElement.nextStep();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue(testBench().compareScreen("testScenario1_step3")); matches.add(testBench().compareScreen("testScenario1_step3"));
controlPanelElement.nextStep(); controlPanelElement.nextStep();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue(testBench().compareScreen("testScenario1_step4")); matches.add(testBench().compareScreen("testScenario1_step4"));
controlPanelElement.previousStep(); controlPanelElement.previousStep();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue(testBench().compareScreen("testScenario1_step3")); matches.add(testBench().compareScreen("testScenario1_step3"));
controlPanelElement.previousStep(); controlPanelElement.previousStep();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue(testBench().compareScreen("testScenario1_step2")); matches.add(testBench().compareScreen("testScenario1_step2"));
controlPanelElement.firstStep(); controlPanelElement.firstStep();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue(testBench().compareScreen("testScenario1_step0")); matches.add(testBench().compareScreen("testScenario1_step0"));
controlPanelElement.lastStep(); controlPanelElement.lastStep();
executor.waitForVaadin(); executor.waitForVaadin();
assertTrue(testBench().compareScreen("testScenario1_step4gi")); matches.add(testBench().compareScreen("testScenario1_step4gi"));
} }
} }