mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
Integration test: example scenario
This commit is contained in:
parent
bb7954d393
commit
24454a26ee
@ -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());
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
* <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;
|
||||
}
|
||||
@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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ 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() {
|
||||
@ -32,15 +31,4 @@ public class ViewMainIT extends AbstractIT {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 62 KiB |
Binary file not shown.
After Width: | Height: | Size: 51 KiB |
Binary file not shown.
After Width: | Height: | Size: 51 KiB |
Loading…
Reference in New Issue
Block a user