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.
|
* Provides a GUI in form of buttons for the user to navigate through steps.
|
||||||
*/
|
*/
|
||||||
public class ControlPanel extends HorizontalLayout {
|
public class ControlPanel extends HorizontalLayout {
|
||||||
|
public static final String ID = "control-panel";
|
||||||
|
|
||||||
private final Button firstStep;
|
private final Button firstStep;
|
||||||
private final Button lastStep;
|
private final Button lastStep;
|
||||||
@ -26,6 +27,7 @@ public class ControlPanel extends HorizontalLayout {
|
|||||||
* @param focusArea the component key shortcuts should work in
|
* @param focusArea the component key shortcuts should work in
|
||||||
*/
|
*/
|
||||||
public ControlPanel(ControlPanelView view, Component focusArea) {
|
public ControlPanel(ControlPanelView view, Component focusArea) {
|
||||||
|
setId(ID);
|
||||||
firstStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_LEFT), evt -> view.firstStepButton());
|
firstStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_LEFT), evt -> view.firstStepButton());
|
||||||
lastStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_RIGHT), evt -> view.lastStepButton());
|
lastStep = new Button(new Icon(VaadinIcon.ANGLE_DOUBLE_RIGHT), evt -> view.lastStepButton());
|
||||||
nextStep = new Button(new Icon(VaadinIcon.ANGLE_RIGHT), evt -> view.nextStepButton());
|
nextStep = new Button(new Icon(VaadinIcon.ANGLE_RIGHT), evt -> view.nextStepButton());
|
||||||
|
@ -22,7 +22,13 @@ public abstract class AbstractIT extends TestBenchTestCase {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
setDriver(new FirefoxDriver());
|
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.Parameters;
|
||||||
import com.vaadin.testbench.commands.TestBenchCommandExecutor;
|
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 edu.kit.typicalc.view.pageobjects.InputBarElement;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.openqa.selenium.HasCapabilities;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This example contains usage examples of screenshot comparison feature.
|
* 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
|
// Set a fixed viewport size so the screenshot is always the same
|
||||||
// resolution
|
// resolution
|
||||||
testBench().resizeViewPortTo(1000, 500);
|
testBench().resizeViewPortTo(1600, 800);
|
||||||
|
|
||||||
// Define the directory for reference screenshots and for error files
|
// Define the directory for reference screenshots and for error files
|
||||||
Parameters.setScreenshotReferenceDirectory("src/test/resources/screenshots");
|
Parameters.setScreenshotReferenceDirectory("src/test/resources/screenshots");
|
||||||
@ -43,8 +43,6 @@ public class ScreenshotIT extends AbstractIT {
|
|||||||
// in screenshots are verified.
|
// in screenshots are verified.
|
||||||
// The output is placed in target/screenshot_errors
|
// The output is placed in target/screenshot_errors
|
||||||
|
|
||||||
generateReferenceIfNotFound("initialView");
|
|
||||||
|
|
||||||
// Compare screen with reference image with id "oneplustwo" from the
|
// Compare screen with reference image with id "oneplustwo" from the
|
||||||
// reference image directory. Reference image filenames also contain
|
// reference image directory. Reference image filenames also contain
|
||||||
// browser, version and platform.
|
// browser, version and platform.
|
||||||
@ -73,40 +71,39 @@ public class ScreenshotIT extends AbstractIT {
|
|||||||
testBench().compareScreen("identityView"));
|
testBench().compareScreen("identityView"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Test
|
||||||
* Generates a reference screenshot if no reference exists.
|
public void chooseExample() throws IOException {
|
||||||
* <p>
|
InputBarElement inputBar = $(InputBarElement.class).first();
|
||||||
* This method only exists for demonstration purposes. Normally you should
|
inputBar.openExampleDialog();
|
||||||
* perform this task manually after verifying that the screenshots look
|
|
||||||
* correct.
|
ExampleDialogElement exampleDialog = $(ExampleDialogElement.class).waitForFirst();
|
||||||
*
|
String term = "λx.x";
|
||||||
* @param referenceId the id of the reference image
|
exampleDialog.insertExample(term);
|
||||||
* @throws IOException
|
|
||||||
*/
|
Assert.assertEquals(term, inputBar.getCurrentValue());
|
||||||
private void generateReferenceIfNotFound(String referenceId)
|
|
||||||
throws IOException {
|
TestBenchCommandExecutor executor = getCommandExecutor();
|
||||||
String refName = ((TestBenchCommandExecutor) testBench())
|
executor.waitForVaadin();
|
||||||
.getReferenceNameGenerator().generateName(referenceId,
|
|
||||||
((HasCapabilities) getDriver()).getCapabilities());
|
// check that the example is copied to the input bar
|
||||||
File referenceFile = new File(
|
// TODO: the blinking cursor could cause issues here
|
||||||
Parameters.getScreenshotReferenceDirectory(), refName + ".png");
|
assertTrue("Screenshot comparison for 'chooseExample' (stage 1) failed",
|
||||||
if (referenceFile.exists()) {
|
testBench().compareScreen("chooseExample1"));
|
||||||
return;
|
|
||||||
|
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import edu.kit.typicalc.view.pageobjects.InputBarElement;
|
|||||||
public class ViewMainIT extends AbstractIT {
|
public class ViewMainIT extends AbstractIT {
|
||||||
|
|
||||||
private static final String EMPTY_INPUT_ERROR = "Falsche Eingabe! Der Term endet abrupt.";
|
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
|
@Test
|
||||||
public void emptyInput() {
|
public void emptyInput() {
|
||||||
@ -32,15 +31,4 @@ public class ViewMainIT extends AbstractIT {
|
|||||||
errorNotification.close();
|
errorNotification.close();
|
||||||
assertFalse(errorNotification.isOpen());
|
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