diff --git a/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java b/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java index 4bbd1de..c3d4c57 100644 --- a/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java +++ b/src/main/java/edu/kit/typicalc/view/content/ControlPanel.java @@ -12,6 +12,7 @@ import com.vaadin.flow.component.orderedlayout.HorizontalLayout; * Provides a GUI in form of buttons for the user to navigate through steps. */ public class ControlPanel extends HorizontalLayout { + public static final String ID = "control-panel"; private final Button firstStep; private final Button lastStep; @@ -26,6 +27,7 @@ public class ControlPanel extends HorizontalLayout { * @param focusArea the component key shortcuts should work in */ public ControlPanel(ControlPanelView view, Component focusArea) { + setId(ID); firstStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_LEFT), evt -> view.firstStepButton()); lastStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_RIGHT), evt -> view.lastStepButton()); nextStep = new Button(new Icon(VaadinIcon.ANGLE_RIGHT), evt -> view.nextStepButton()); diff --git a/src/test/java/edu/kit/typicalc/view/AbstractIT.java b/src/test/java/edu/kit/typicalc/view/AbstractIT.java index a80915c..d9022bf 100644 --- a/src/test/java/edu/kit/typicalc/view/AbstractIT.java +++ b/src/test/java/edu/kit/typicalc/view/AbstractIT.java @@ -22,7 +22,13 @@ public abstract class AbstractIT extends TestBenchTestCase { @Before public void setUp() { setDriver(new FirefoxDriver()); - getDriver().get("http://" + IPAddress.findSiteLocalAddress() + ":8080"); + String ip; + if (System.getProperty("testbench.use127001") != null) { + ip = "127.0.0.1"; + } else { + ip = IPAddress.findSiteLocalAddress(); + } + getDriver().get("http://" + ip + ":8080"); } } diff --git a/src/test/java/edu/kit/typicalc/view/ScreenshotIT.java b/src/test/java/edu/kit/typicalc/view/ScreenshotIT.java index d2430e8..81dae80 100644 --- a/src/test/java/edu/kit/typicalc/view/ScreenshotIT.java +++ b/src/test/java/edu/kit/typicalc/view/ScreenshotIT.java @@ -2,15 +2,15 @@ package edu.kit.typicalc.view; import com.vaadin.testbench.Parameters; import com.vaadin.testbench.commands.TestBenchCommandExecutor; +import edu.kit.typicalc.view.pageobjects.ControlPanelElement; +import edu.kit.typicalc.view.pageobjects.ExampleDialogElement; import edu.kit.typicalc.view.pageobjects.InputBarElement; +import org.junit.Assert; import org.junit.Test; -import org.openqa.selenium.HasCapabilities; -import java.io.File; import java.io.IOException; -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.Assert.*; /** * This example contains usage examples of screenshot comparison feature. @@ -30,7 +30,7 @@ public class ScreenshotIT extends AbstractIT { // Set a fixed viewport size so the screenshot is always the same // resolution - testBench().resizeViewPortTo(1000, 500); + testBench().resizeViewPortTo(1600, 800); // Define the directory for reference screenshots and for error files Parameters.setScreenshotReferenceDirectory("src/test/resources/screenshots"); @@ -43,8 +43,6 @@ public class ScreenshotIT extends AbstractIT { // 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. @@ -73,40 +71,39 @@ public class ScreenshotIT extends AbstractIT { testBench().compareScreen("identityView")); } - /** - * Generates a reference screenshot if no reference exists. - *
- * 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; - } + @Test + public void chooseExample() throws IOException { + InputBarElement inputBar = $(InputBarElement.class).first(); + inputBar.openExampleDialog(); - if (!referenceFile.getParentFile().exists()) { - referenceFile.getParentFile().mkdirs(); - } + ExampleDialogElement exampleDialog = $(ExampleDialogElement.class).waitForFirst(); + String term = "λx.x"; + exampleDialog.insertExample(term); - File errorFile = new File(Parameters.getScreenshotErrorDirectory(), - referenceFile.getName()); + Assert.assertEquals(term, inputBar.getCurrentValue()); - // Take a screenshot and move it to the reference location - testBench().compareScreen(referenceId); - errorFile.renameTo(referenceFile); + TestBenchCommandExecutor executor = getCommandExecutor(); + executor.waitForVaadin(); - System.out.println("Created new reference file in " + referenceFile); + // check that the example is copied to the input bar + // TODO: the blinking cursor could cause issues here + assertTrue("Screenshot comparison for 'chooseExample' (stage 1) failed", + testBench().compareScreen("chooseExample1")); + inputBar.typeInfer(); + executor.waitForVaadin(); + ControlPanelElement control = $(ControlPanelElement.class).waitForFirst(); + control.lastStep(); + executor.waitForVaadin(); + + // check that the example is inferred correctly + assertTrue("Screenshot comparison for 'chooseExample' (stage 2) failed", + testBench().compareScreen("chooseExample2")); + + control.lastStep(); + executor.waitForVaadin(); + // check that the example is unified correctly + assertTrue("Screenshot comparison for 'chooseExample' (stage 3) failed", + testBench().compareScreen("chooseExample3")); } - } diff --git a/src/test/java/edu/kit/typicalc/view/ViewMainIT.java b/src/test/java/edu/kit/typicalc/view/ViewMainIT.java index 65456e8..4439ad4 100644 --- a/src/test/java/edu/kit/typicalc/view/ViewMainIT.java +++ b/src/test/java/edu/kit/typicalc/view/ViewMainIT.java @@ -12,35 +12,23 @@ import edu.kit.typicalc.view.pageobjects.ExampleDialogElement; import edu.kit.typicalc.view.pageobjects.InputBarElement; public class ViewMainIT extends AbstractIT { - + private static final String EMPTY_INPUT_ERROR = "Falsche Eingabe! Der Term endet abrupt."; - private static final String INPUT_EXAMPLE = "let f = λx. g y y in f 3"; @Test public void emptyInput() { InputBarElement inputBar = $(InputBarElement.class).first(); inputBar.setCurrentValue(StringUtils.EMPTY); - + assertEquals(StringUtils.EMPTY, inputBar.getCurrentValue()); inputBar.typeInfer(); - + ErrorNotificationElement errorNotification = $(ErrorNotificationElement.class).waitForFirst(); assertTrue(errorNotification.isOpen()); String errorMessage = errorNotification.getErrorParagraph().getText(); assertEquals(EMPTY_INPUT_ERROR, errorMessage); - + errorNotification.close(); assertFalse(errorNotification.isOpen()); } - - @Test - public void chooseExample() { - InputBarElement inputBar = $(InputBarElement.class).first(); - inputBar.openExampleDialog(); - - ExampleDialogElement exampleDialog = $(ExampleDialogElement.class).waitForFirst(); - exampleDialog.insertExample(INPUT_EXAMPLE); - - assertEquals(INPUT_EXAMPLE, inputBar.getCurrentValue()); - } } diff --git a/src/test/java/edu/kit/typicalc/view/pageobjects/ControlPanelElement.java b/src/test/java/edu/kit/typicalc/view/pageobjects/ControlPanelElement.java new file mode 100644 index 0000000..3b7c800 --- /dev/null +++ b/src/test/java/edu/kit/typicalc/view/pageobjects/ControlPanelElement.java @@ -0,0 +1,12 @@ +package edu.kit.typicalc.view.pageobjects; + +import com.vaadin.flow.component.button.testbench.ButtonElement; +import com.vaadin.flow.component.orderedlayout.testbench.HorizontalLayoutElement; +import com.vaadin.testbench.annotations.Attribute; + +@Attribute(name = "id", value = "control-panel") +public class ControlPanelElement extends HorizontalLayoutElement { + public void lastStep() { + $(ButtonElement.class).get(4).click(); + } +} diff --git a/src/test/resources/screenshots/chooseExample1_linux_firefox_84.png b/src/test/resources/screenshots/chooseExample1_linux_firefox_84.png new file mode 100644 index 0000000..e8f981b Binary files /dev/null and b/src/test/resources/screenshots/chooseExample1_linux_firefox_84.png differ diff --git a/src/test/resources/screenshots/chooseExample2_linux_firefox_84.png b/src/test/resources/screenshots/chooseExample2_linux_firefox_84.png new file mode 100644 index 0000000..43fe9a7 Binary files /dev/null and b/src/test/resources/screenshots/chooseExample2_linux_firefox_84.png differ diff --git a/src/test/resources/screenshots/chooseExample3_linux_firefox_84.png b/src/test/resources/screenshots/chooseExample3_linux_firefox_84.png new file mode 100644 index 0000000..1b1c688 Binary files /dev/null and b/src/test/resources/screenshots/chooseExample3_linux_firefox_84.png differ