diff --git a/CHANGELOG.md b/CHANGELOG.md index c01f7b012..9484d5989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to AET will be documented in this file. - [PR-396](https://github.com/Cognifide/aet/pull/396) Added horizontal scrollbar for wide pages ([#393](https://github.com/Cognifide/aet/issues/393)) - [PR-403](https://github.com/Cognifide/aet/pull/403) Conditionally passed tests can be accepted ([#400](https://github.com/Cognifide/aet/issues/400)) - [PR-387](https://github.com/Cognifide/aet/pull/387) Set max allowed page screenshot height to 35k pixels. +- [PR-401](https://github.com/Cognifide/aet/pull/401) Added new regex param `sourcePattern` to [JS Errors Data Filter](https://github.com/Cognifide/aet/wiki/JSErrorsDataFilter) - [PR-397](https://github.com/Cognifide/aet/pull/397) Add algorithm to enable taking long screenshots without resolution-sleep-resolution workaround ## Version 3.0.1 diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/datafilters/jserrorsfilter/JsErrorsFilter.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/datafilters/jserrorsfilter/JsErrorsFilter.java index 00412d330..4936548b4 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/datafilters/jserrorsfilter/JsErrorsFilter.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/datafilters/jserrorsfilter/JsErrorsFilter.java @@ -36,6 +36,8 @@ public class JsErrorsFilter extends AbstractDataModifierJob> { private static final String PARAM_SOURCE = "source"; + private static final String PARAM_SOURCE_PATTERN = "sourcePattern"; + private static final String PARAM_LINE = "line"; private String errorMessage; @@ -44,6 +46,8 @@ public class JsErrorsFilter extends AbstractDataModifierJob> { private String sourceFile; + private Pattern sourceFilePattern; + private Integer line; @Override @@ -52,8 +56,10 @@ public void setParameters(Map params) throws ParametersException errorMessagePattern = ParamsHelper.getParamAsPattern(PARAM_ERROR_PATTERN, params); line = ParamsHelper.getParamAsInteger(PARAM_LINE, params); sourceFile = ParamsHelper.getParamAsString(PARAM_SOURCE, params); + sourceFilePattern = ParamsHelper.getParamAsPattern(PARAM_SOURCE_PATTERN, params); - ParamsHelper.atLeastOneIsProvided(errorMessage, errorMessagePattern, sourceFile, line); + ParamsHelper.atLeastOneIsProvided( + errorMessage, errorMessagePattern, sourceFile, sourceFilePattern, line); } /** @@ -75,8 +81,8 @@ public Set modifyData(Set data) { } private boolean shouldBeIgnored(JsErrorLog jse) { - String source = jse.getSourceName(); - return shouldExcludeRegardingSource(source) + return ParamsHelper.matches(sourceFilePattern, jse.getSourceName()) + && shouldExcludeRegardingSource(jse.getSourceName()) && ParamsHelper.matches(errorMessagePattern, jse.getErrorMessage()) && (errorMessage == null || errorMessage.equals(jse.getErrorMessage())) && ParamsHelper.equalOrNotSet(line, jse.getLineNumber()); @@ -84,11 +90,13 @@ private boolean shouldBeIgnored(JsErrorLog jse) { private void addErrorInfo(JsErrorLog errorLog) { String errorPattern = errorMessagePattern == null ? null : errorMessagePattern.toString(); + String sourcePattern = sourceFilePattern == null ? null : sourceFilePattern.toString(); FilterInfo filterInfo = new FilterInfo() .add(PARAM_ERROR, errorMessage) .add(PARAM_ERROR_PATTERN, errorPattern) .add(PARAM_SOURCE, sourceFile) + .add(PARAM_SOURCE_PATTERN, sourcePattern) .add(PARAM_LINE, line); errorLog.addMatchedFilter(filterInfo); } @@ -111,6 +119,7 @@ public String getInfo() { return NAME + " DataModifier with parameters: " + PARAM_ERROR_PATTERN + ": " + errorMessagePattern + " " + PARAM_SOURCE + ": " + sourceFile + " " + + PARAM_SOURCE_PATTERN + ": " + sourceFilePattern + " " + PARAM_LINE + ": " + line; } diff --git a/core/jobs/src/test/java/com/cognifide/aet/job/common/datafilters/jserrorsfilter/JsErrorsFilterTest.java b/core/jobs/src/test/java/com/cognifide/aet/job/common/datafilters/jserrorsfilter/JsErrorsFilterTest.java index f0b8c0fbf..cc8def552 100644 --- a/core/jobs/src/test/java/com/cognifide/aet/job/common/datafilters/jserrorsfilter/JsErrorsFilterTest.java +++ b/core/jobs/src/test/java/com/cognifide/aet/job/common/datafilters/jserrorsfilter/JsErrorsFilterTest.java @@ -17,6 +17,7 @@ import static java.util.stream.Collectors.toSet; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; @@ -45,12 +46,16 @@ public class JsErrorsFilterTest { private static final String PARAM_SOURCE = "source"; + private static final String PARAM_SOURCE_PATTERN = "sourcePattern"; + private static final String PARAM_LINE = "line"; private static final String PARAM_ERROR_VALUE = "Error message"; private static final String PARAM_SOURCE_VALUE = "Source Value"; + private static final String PARAM_SOURCE_PATTERN_VALUE = "(?i)^Source Value$"; + private static final String PARAM_SOURCE_VALUE_SHORT = "source"; private static final String PARAM_ERROR_PATTERN = "errorPattern"; @@ -64,6 +69,7 @@ public class JsErrorsFilterTest { private static final String INFO_PATTERN = JsErrorsFilter.NAME + " DataModifier with parameters: " + PARAM_ERROR_PATTERN + ": %s " + PARAM_SOURCE + ": %s " + + PARAM_SOURCE_PATTERN + ": %s " + PARAM_LINE + ": %s"; @Mock private Set data; @@ -83,14 +89,14 @@ public void setUp() { @Test public void setParametersTest() throws ParametersException { params = createParams(PARAM_LINE_VALUE, PARAM_ERROR_PATTERN_VALUE, PARAM_SOURCE_VALUE, - PARAM_ERROR_VALUE); + PARAM_SOURCE_PATTERN_VALUE, PARAM_ERROR_VALUE); // no exceptions should occur tested.setParameters(params); } @Test public void setParametersTest_onlyOneSet() throws ParametersException { - params = createParams(null, null, PARAM_SOURCE_VALUE, null); + params = createParams(null, null, PARAM_SOURCE_VALUE, null, null); tested.setParameters(params); String expected = String.format(INFO_PATTERN, null, PARAM_SOURCE_VALUE, null, null); assertThat(tested.getInfo(), is(expected)); @@ -98,20 +104,20 @@ public void setParametersTest_onlyOneSet() throws ParametersException { @Test(expected = ParametersException.class) public void setParametersTest_allEmpty() throws ParametersException { - params = createParams(null, null, null, null); + params = createParams(null, null, null, null, null); tested.setParameters(params); } @Test(expected = ParametersException.class) public void setParametersTest_lineNotANumber() throws ParametersException { - params = createParams(PARAM_LINE_VALUE_NAN, null, null, null); + params = createParams(PARAM_LINE_VALUE_NAN, null, null, null, null); tested.setParameters(params); } @Test public void modifyDataTest_excludeByErrorMessage() throws ParametersException { - params = createParams(null, null, null, PARAM_ERROR_VALUE); + params = createParams(null, null, null, null, PARAM_ERROR_VALUE); tested.setParameters(params); Set result = tested.modifyData(data); Set ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet()); @@ -123,7 +129,7 @@ public void modifyDataTest_excludeByErrorMessage() @Test public void modifyDataTest_filterByErrorMessagePattern() throws ProcessingException, ParametersException { - params = createParams(null, PARAM_ERROR_PATTERN_VALUE, null, null); + params = createParams(null, PARAM_ERROR_PATTERN_VALUE, null, null, null); tested.setParameters(params); Set result = tested.modifyData(data); Set ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet()); @@ -134,7 +140,7 @@ public void modifyDataTest_filterByErrorMessagePattern() @Test public void modifyDataTest_filterBySource() throws ProcessingException, ParametersException { - params = createParams(null, null, PARAM_SOURCE_VALUE_SHORT, null); + params = createParams(null, null, PARAM_SOURCE_VALUE_SHORT, null, null); tested.setParameters(params); Set result = tested.modifyData(data); Set ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet()); @@ -143,9 +149,21 @@ public void modifyDataTest_filterBySource() throws ProcessingException, Paramete assertSize(ignored, 3); } + @Test + public void modifyDataTest_filterBySourcePattern() + throws ProcessingException, ParametersException { + params = createParams(null, null, null, PARAM_SOURCE_PATTERN_VALUE, null); + tested.setParameters(params); + Set result = tested.modifyData(data); + Set ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet()); + + assertSize(result, data.size()); + assertSize(ignored, 2); + } + @Test public void modifyDataTest_filterByLine() throws ProcessingException, ParametersException { - params = createParams(PARAM_LINE_VALUE, null, null, null); + params = createParams(PARAM_LINE_VALUE, null, null, null, null); tested.setParameters(params); Set result = tested.modifyData(data); Set ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet()); @@ -157,7 +175,7 @@ public void modifyDataTest_filterByLine() throws ProcessingException, Parameters @Test public void modifyDataTest_excludeByLineAndErrorMessagePattern() throws ProcessingException, ParametersException { - params = createParams(PARAM_LINE_VALUE, PARAM_ERROR_PATTERN_VALUE, null, null); + params = createParams(PARAM_LINE_VALUE, PARAM_ERROR_PATTERN_VALUE, null, null, null); tested.setParameters(params); Set result = tested.modifyData(data); Set ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet()); @@ -182,7 +200,7 @@ private void assertSize(Set jsErrors, int expectedSize) { } private Map createParams(String line, String errorPattern, String source, - String error) { + String sourcePattern, String error) { Map params = new HashMap<>(); if (StringUtils.isNotBlank(line)) { params.put(PARAM_LINE, line); @@ -193,6 +211,9 @@ private Map createParams(String line, String errorPattern, Strin if (StringUtils.isNotBlank(source)) { params.put(PARAM_SOURCE, source); } + if (StringUtils.isNotBlank(sourcePattern)) { + params.put(PARAM_SOURCE_PATTERN, sourcePattern); + } if (StringUtils.isNotBlank(error)) { params.put(PARAM_ERROR, error); } diff --git a/documentation/src/main/wiki/JSErrorsDataFilter.md b/documentation/src/main/wiki/JSErrorsDataFilter.md index d0fcd9e65..07d3c65bb 100644 --- a/documentation/src/main/wiki/JSErrorsDataFilter.md +++ b/documentation/src/main/wiki/JSErrorsDataFilter.md @@ -17,6 +17,7 @@ Resource name: js-errors | --------- | ----- | ----------- | --------- | |`error`|string error|Exact error message|At least one of parameter is required| |`source`|JavaScript filename suffix (see notes) below|Source file name in which error occurred|At least one of parameter is required| +|`sourcePattern`|JavaScript filename pattern|Regular expression that matches source file name in which error occurred|At least one of parameter is required| |`errorPattern` | pattern error text | Regular expression that matches message text of issue to be filter out|At least one parameter is required| |`line` integer line number|Line number in file in which error occurred| |At least one of parameter is required| diff --git a/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java b/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java index 4e7436473..ed0c3a51c 100644 --- a/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java +++ b/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java @@ -29,15 +29,15 @@ @Modules(GuiceModule.class) public class HomePageTilesTest { - private static final int TESTS = 147; + private static final int TESTS = 149; - private static final int EXPECTED_TESTS_SUCCESS = 84; + private static final int EXPECTED_TESTS_SUCCESS = 85; private static final int EXPECTED_TESTS_CONDITIONALLY_PASSED = 11; private static final int EXPECTED_TESTS_WARN = 5; - private static final int EXPECTED_TESTS_FAIL = 58; + private static final int EXPECTED_TESTS_FAIL = 59; @Inject private ReportHomePage page; diff --git a/integration-tests/sanity-functional/src/test/resources/features/filtering.feature b/integration-tests/sanity-functional/src/test/resources/features/filtering.feature index 08622882d..de70a55a8 100644 --- a/integration-tests/sanity-functional/src/test/resources/features/filtering.feature +++ b/integration-tests/sanity-functional/src/test/resources/features/filtering.feature @@ -43,8 +43,8 @@ Feature: Tests Results Filtering Scenario: Filtering Tests Results: jserrors Given I have opened sample tests report page When I search for tests containing "jserrors" - Then There are 14 tiles visible - And Statistics text contains "14 ( 6 / 0 / 8 (0) / 0 )" + Then There are 16 tiles visible + And Statistics text contains "16 ( 7 / 0 / 9 (0) / 0 )" Scenario: Filtering Tests Results: source Given I have opened sample tests report page diff --git a/integration-tests/test-suite/partials/js-errors-filter-by-sourcePattern.xml b/integration-tests/test-suite/partials/js-errors-filter-by-sourcePattern.xml new file mode 100644 index 000000000..a86418101 --- /dev/null +++ b/integration-tests/test-suite/partials/js-errors-filter-by-sourcePattern.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/integration-tests/test-suite/test-suite-assembly.xsl b/integration-tests/test-suite/test-suite-assembly.xsl index c1440e077..a8cfe3f93 100644 --- a/integration-tests/test-suite/test-suite-assembly.xsl +++ b/integration-tests/test-suite/test-suite-assembly.xsl @@ -27,6 +27,7 @@ +