Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new regex param sourcePattern to js errors data filter. #401

Merged
merged 4 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class JsErrorsFilter extends AbstractDataModifierJob<Set<JsErrorLog>> {

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;
Expand All @@ -44,6 +46,8 @@ public class JsErrorsFilter extends AbstractDataModifierJob<Set<JsErrorLog>> {

private String sourceFile;

private Pattern sourceFilePattern;

private Integer line;

@Override
Expand All @@ -52,8 +56,10 @@ public void setParameters(Map<String, String> 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);
}

/**
Expand All @@ -75,20 +81,22 @@ public Set<JsErrorLog> modifyData(Set<JsErrorLog> 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());
}

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);
}
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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";
Expand All @@ -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<JsErrorLog> data;
Expand All @@ -83,35 +89,35 @@ 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));
}

@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<JsErrorLog> result = tested.modifyData(data);
Set<JsErrorLog> ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet());
Expand All @@ -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<JsErrorLog> result = tested.modifyData(data);
Set<JsErrorLog> ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet());
Expand All @@ -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<JsErrorLog> result = tested.modifyData(data);
Set<JsErrorLog> ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet());
Expand All @@ -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<JsErrorLog> result = tested.modifyData(data);
Set<JsErrorLog> 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<JsErrorLog> result = tested.modifyData(data);
Set<JsErrorLog> ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet());
Expand All @@ -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<JsErrorLog> result = tested.modifyData(data);
Set<JsErrorLog> ignored = result.stream().filter(JsErrorLog::isIgnored).collect(toSet());
Expand All @@ -182,7 +200,7 @@ private void assertSize(Set<JsErrorLog> jsErrors, int expectedSize) {
}

private Map<String, String> createParams(String line, String errorPattern, String source,
String error) {
String sourcePattern, String error) {
Map<String, String> params = new HashMap<>();
if (StringUtils.isNotBlank(line)) {
params.put(PARAM_LINE, line);
Expand All @@ -193,6 +211,9 @@ private Map<String, String> 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);
}
Expand Down
1 change: 1 addition & 0 deletions documentation/src/main/wiki/JSErrorsDataFilter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

AET

Copyright (C) 2013 Cognifide Limited

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<suite name="main" company="aet" domain="http://192.168.123.100:9090/sample-site/sanity/" project="aet">
<test name="S-comparator-JsErrors-all-errors-filtered">
<collect>
<open />
<sleep duration="2000" />
<js-errors />
</collect>
<compare>
<js-errors>
<js-errors-filter sourcePattern=".*failed.jsp" />
</js-errors>
</compare>
<urls>
<url href="comparators/jserrors/failed.jsp" />
</urls>
</test>

<test name="F-comparator-JsErrors-no-errors-filtered">
<collect>
<open />
<sleep duration="2000" />
<js-errors />
</collect>
<compare>
<js-errors>
<js-errors-filter sourcePattern=".*non-existing-source.*" />
</js-errors>
</compare>
<urls>
<url href="comparators/jserrors/failed.jsp" />
</urls>
</test>
</suite>
1 change: 1 addition & 0 deletions integration-tests/test-suite/test-suite-assembly.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<xsl:apply-templates select="document('partials/js-errors-filter-by-error.xml')/*/test"/>
<xsl:apply-templates select="document('partials/js-errors-filter-by-errorPattern.xml')/*/test"/>
<xsl:apply-templates select="document('partials/js-errors-filter-by-source-and-line.xml')/*/test"/>
<xsl:apply-templates select="document('partials/js-errors-filter-by-sourcePattern.xml')/*/test"/>
<xsl:apply-templates select="document('partials/status-codes.xml')/*/test"/>
<xsl:apply-templates select="document('partials/w3c-html5.xml')/*/test"/>
<xsl:apply-templates select="document('partials/w3c-html5-filtered.xml')/*/test"/>
Expand Down