Browse Source

Updated local screenshot testing configurations. (#11814)

* A separate screenshot module hasn't been in use for a while but local
testing configurations and instructions weren't updated to the new model
at the time. Could use some further cleanup but this covers the basics.
* Some tweaks to ScreenshotBrowser to get it functional again, although
the actions for automatically replacing or adding alternative
screenshots still require work and have thus been disabled.
tags/8.10.0.alpha1
Anna Koskinen 4 years ago
parent
commit
346d564dfe
No account linked to committer's email address

+ 1
- 1
README-TESTS.md View File

Before running any tests from your IDE you need to Before running any tests from your IDE you need to
1. copy `uitest/eclipse-run-selected-test.properties` to `work/eclipse-run-selected-test.properties` 1. copy `uitest/eclipse-run-selected-test.properties` to `work/eclipse-run-selected-test.properties`
2. edit `work/eclipse-run-selected-test.properties` 2. edit `work/eclipse-run-selected-test.properties`
1. Define `com.vaadin.testbench.screenshot.directory` as the directory where you checked out the screenshots repository (this directory contains the “references” subdirectory)
1. Define `com.vaadin.testbench.screenshot.directory` as the `uitest` repository (this directory contains the “reference-screenshots” subdirectory)
2. Set `com.vaadin.testbench.deployment.url=http://localhost:8888/` 2. Set `com.vaadin.testbench.deployment.url=http://localhost:8888/`
3. Set `com.vaadin.testbench.runLocally=chrome` to only run tests on Chrome. On Ubuntu you can then install Chrome driver easily: 3. Set `com.vaadin.testbench.runLocally=chrome` to only run tests on Chrome. On Ubuntu you can then install Chrome driver easily:
`sudo apt install chromium-chromedriver` `sudo apt install chromium-chromedriver`

+ 2
- 2
test/servlet-containers/generic/build.xml View File

<target name="clean-testbench-errors"><!--todo remove when have got rid of screenshots--> <target name="clean-testbench-errors"><!--todo remove when have got rid of screenshots-->
<fail unless="com.vaadin.testbench.screenshot.directory" <fail unless="com.vaadin.testbench.screenshot.directory"
message="Define screenshot directory using -Dcom.vaadin.testbench.screenshot.directory" /> message="Define screenshot directory using -Dcom.vaadin.testbench.screenshot.directory" />
<mkdir dir="${com.vaadin.testbench.screenshot.directory}/errors" />
<mkdir dir="${com.vaadin.testbench.screenshot.directory}/error-screenshots" />
<delete> <delete>
<fileset <fileset
dir="${com.vaadin.testbench.screenshot.directory}/errors">
dir="${com.vaadin.testbench.screenshot.directory}/error-screenshots">
<include name="*" /> <include name="*" />
</fileset> </fileset>
</delete> </delete>

+ 1
- 1
uitest/eclipse-run-selected-test.properties View File

# Location of the screenshot directory. This is mutually exclusive with the folder settings for XVFB testing. # Location of the screenshot directory. This is mutually exclusive with the folder settings for XVFB testing.
# This is the directory that contains the "references" directory # This is the directory that contains the "references" directory


com.vaadin.testbench.screenshot.directory=<enter the full path to the screenshots directory, parent of "references" directory>
com.vaadin.testbench.screenshot.directory=<enter the full path to the "uitest" directory, parent of "reference-screenshots" directory>


# Deployment url to use for testing. Context path must be / # Deployment url to use for testing. Context path must be /



+ 32
- 21
uitest/src/main/java/com/vaadin/screenshotbrowser/ScreenshotBrowser.java View File

import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;


import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter;

import com.vaadin.event.ShortcutAction.KeyCode; import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.event.ShortcutListener; import com.vaadin.event.ShortcutListener;
import com.vaadin.server.ExternalResource; import com.vaadin.server.ExternalResource;
* 3 - platform * 3 - platform
* 4 - browser name * 4 - browser name
* 5 - browser version * 5 - browser version
* 6 - additional qualifiers
* 7 - identifier
* 6 - identifier
* 7 - additional identifiers
*/ */
private static final Pattern screenshotNamePattern = Pattern private static final Pattern screenshotNamePattern = Pattern
.compile("(.+?)-(.+?)_(.+?)_(.+?)_(.+?)(_.+)?_(.+?)\\.png\\.html");
.compile("(.+?)-(.+?)_(.+?)_(.+?)_(.*?)_(.+?)(_.+)?\\.png\\.html");


public static enum Action { public static enum Action {
ACCEPT { ACCEPT {
} }


private static File getReferenceDir() { private static File getReferenceDir() {
return new File(screenshotDir, "reference");
return new File(screenshotDir, "reference-screenshots");
} }


private static File getAlternative(File baseFile, private static File getAlternative(File baseFile,
return matcher.group(4) + " " + matcher.group(5); return matcher.group(4) + " " + matcher.group(5);
} }


public String getQualifiers() {
return matcher.group(6);
}

public String getIdentifier() { public String getIdentifier() {
return matcher.group(7);
String additional = matcher.group(7);
if (additional != null) {
return matcher.group(6) + additional;
}
return matcher.group(6);
} }


public void setAction(Action action) { public void setAction(Action action) {


left.setMargin(true); left.setMargin(true);
left.setSpacing(true); left.setSpacing(true);
left.setSizeFull();
left.setSizeUndefined();
left.setWidth("270px");


left.addComponent( left.addComponent(
createActionButton("Accept changes", 'j', Action.ACCEPT)); createActionButton("Accept changes", 'j', Action.ACCEPT));
left.addComponent(expandSpacer); left.addComponent(expandSpacer);
left.setExpandRatio(expandSpacer, 1); left.setExpandRatio(expandSpacer, 1);


left.addComponent(new Label(
"Press the j, k or l keys to quickly select an action for the selected item."));
Label instructions = new Label(
"Press the j, k or l keys to quickly select an action for the selected item.");
instructions.setWidth("100%");
left.addComponent(instructions);


root.setExpandRatio(left, 1); root.setExpandRatio(left, 1);
root.setSizeFull(); root.setSizeFull();


setCompositionRoot(root); setCompositionRoot(root);
setHeight("850px"); setHeight("850px");
setWidth("100%");
setWidth("1800px");
} }


private Button createActionButton(String caption, char shortcut, private Button createActionButton(String caption, char shortcut,
caption + " <strong>" + shortcut + "</strong>", caption + " <strong>" + shortcut + "</strong>",
createSetActionListener(action)); createSetActionListener(action));
button.setCaptionAsHtml(true); button.setCaptionAsHtml(true);
if (!Action.IGNORE.equals(action)) {
// other actions disabled for now since the functionality was
// designed for a different directory structure, needs reworking
button.setEnabled(false);
}
return button; return button;
} }


@Override @Override
protected void init(VaadinRequest request) { protected void init(VaadinRequest request) {
table.setWidth("100%"); table.setWidth("100%");
table.setHeight("100%");
table.setPageLength(10);


table.setMultiSelect(true); table.setMultiSelect(true);
table.addValueChangeListener(event -> { table.addValueChangeListener(event -> {


refreshTableContainer(); refreshTableContainer();


VerticalLayout mainLayout = new VerticalLayout(table, viewer);
mainLayout.setExpandRatio(table, 1);
mainLayout.setSizeFull();
VerticalLayout mainLayout = new VerticalLayout(viewer, table);
mainLayout.setSizeUndefined();


setSizeFull(); setSizeFull();
setContent(mainLayout); setContent(mainLayout);
} }


private void refreshTableContainer() { private void refreshTableContainer() {
File errorsDir = new File(screenshotDir, "errors");
File errorsDir = new File(screenshotDir, "error-screenshots");


File[] failures = errorsDir
.listFiles((dir, name) -> name.endsWith(".html"));
Collection<File> failures = FileUtils.listFiles(errorsDir,
new SuffixFileFilter(".html"), DirectoryFileFilter.DIRECTORY);


BeanItemContainer<ComparisonFailure> container = new BeanItemContainer<>( BeanItemContainer<ComparisonFailure> container = new BeanItemContainer<>(
ComparisonFailure.class); ComparisonFailure.class);


table.setContainerDataSource(container); table.setContainerDataSource(container);
table.setVisibleColumns("testClass", "testMethod", "browser", table.setVisibleColumns("testClass", "testMethod", "browser",
"qualifiers", "identifier", "action");
"identifier", "action");
if (container.size() > 0) { if (container.size() > 0) {
table.select(container.firstItemId()); table.select(container.firstItemId());
} }

+ 3
- 2
uitest/src/test/java/com/vaadin/tests/tb3/PrivateTB3Configuration.java View File

String dir = System.getProperty(SCREENSHOT_DIRECTORY, String dir = System.getProperty(SCREENSHOT_DIRECTORY,
properties.getProperty(SCREENSHOT_DIRECTORY)); properties.getProperty(SCREENSHOT_DIRECTORY));
if (dir != null && !dir.isEmpty()) { if (dir != null && !dir.isEmpty()) {
String reference = Paths.get(dir, "reference").toString();
String errors = Paths.get(dir, "errors").toString();
String reference = Paths.get(dir, "reference-screenshots")
.toString();
String errors = Paths.get(dir, "error-screenshots").toString();
Parameters.setScreenshotReferenceDirectory(reference); Parameters.setScreenshotReferenceDirectory(reference);
Parameters.setScreenshotErrorDirectory(errors); Parameters.setScreenshotErrorDirectory(errors);
} else { } else {

+ 1
- 1
uitest/src/test/java/com/vaadin/tests/tb3/VaadinBrowserFactory.java View File

case PHANTOMJS: case PHANTOMJS:
return create(browser, "1", Platform.LINUX); return create(browser, "1", Platform.LINUX);
case CHROME: case CHROME:
return create(browser, "40", Platform.VISTA);
return create(browser, "", Platform.ANY);
case FIREFOX: case FIREFOX:
default: default:
DesiredCapabilities dc = create(Browser.FIREFOX, "45", DesiredCapabilities dc = create(Browser.FIREFOX, "45",

Loading…
Cancel
Save