8000 [plugin-web-app-to-rest-api] Add jump links verifications by uarlouski · Pull Request #4367 · vividus-framework/vividus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[plugin-web-app-to-rest-api] Add jump links verifications #4367

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.

Alrea 8000 dy on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ private void validateResources(Stream<WebPageResourceValidation> resourceValidat

private WebPageResourceValidation validate(WebPageResourceValidation r)
{
return CheckStatus.BROKEN == r.getCheckStatus() || CheckStatus.FILTERED == r.getCheckStatus()
? r
: resourceValidator.perform(r);
return r.getCheckStatus() != null ? r : resourceValidator.perform(r);
}

private Stream<WebPageResourceValidation> createResourceValidations(Collection<Element> elements,
Expand All @@ -150,7 +148,7 @@ private Stream<WebPageResourceValidation> createResourceValidations(Collection<E
.peek(rv ->
{
resourceValidator.accept(rv);
if (rv.getCheckStatus() != CheckStatus.BROKEN && !isSchemaAllowed(rv.getUriOrError().getLeft())
if (rv.getCheckStatus() == null && !isSchemaAllowed(rv.getUriOrError().getLeft())
|| excludeHrefsPattern.matcher(rv.toString()).matches())
{
rv.setCheckStatus(CheckStatus.FILTERED);
Expand All @@ -177,7 +175,22 @@ private Optional<WebPageResourceValidation> parseElement(Element element)
try
{
Pair<URI, String> elementUri = Pair.of(resolveUri(elementUriAsString), null);
return Optional.of(new WebPageResourceValidation(elementUri, elementCssSelector));
WebPageResourceValidation validation = new WebPageResourceValidation(elementUri, elementCssSelector);

if (isJumpLink(elementUriAsString))
{
String fragment = elementUri.getLeft().getFragment();
Element target = element.root().getElementById(fragment);
if (target == null)
{
return Optional.of(ResourceValidationError.MISSING_JUMPLINK_TARGET
.onAssertion(softAssert::recordFailedAssertion, elementCssSelector, fragment)
.createValidation(null, elementCssSelector, fragment));
}
validation.setCheckStatus(CheckStatus.PASSED);
}

return Optional.of(validation);
}
catch (URISyntaxException e)
{
Expand All @@ -188,6 +201,11 @@ private Optional<WebPageResourceValidation> parseElement(Element element)
}
}

private static boolean isJumpLink(String url)
{
return url.startsWith(URL_FRAGMENT) && url.length() > 1;
}

private static boolean isSchemaAllowed(URI uri)
{
return Optional.ofNullable(uri.getScheme()).map(ALLOWED_SCHEMES::contains).orElse(false);
Expand All @@ -198,7 +216,7 @@ private static String getElementUri(Element element)
String href = element.attr(HREF_ATTR);
if (!href.isEmpty())
{
if (URL_FRAGMENT.equals(href))
if (URL_FRAGMENT.equals(href) || isJumpLink(href))
{
return href;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public enum ResourceValidationError
EMPTY_HREF_SRC("Element doesn't contain href/src attributes",
"Element by selector %s doesn't contain href/src attributes"),
INVALID_HREF_SRC("Element has href/src attribute with invalid URL: %s",
"Element by selector %s has href/src attribute with invalid URL: %s");
"Element by selector %s has href/src attribute with invalid URL: %s"),
MISSING_JUMPLINK_TARGET("Jump link points to missing element with %s id",
"Jump link by selector %s points to missing element with %s id");

private final String errorFormat;
private final String assertionFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class ResourceCheckStepsTests
private static final String SELECTOR_QUERY_1 = "#query-params-one";
private static final URI VIVIDUS_QUERY_URI_2 = URI.create("https://vividus.org/products?name=smetanka");
private static final String SELECTOR_QUERY_2 = "#query-params-two";
private static final URI EXTERNAL_SECTION_LINK = URI.create("https://external.page/other#section");
private static final String EXTERNAL_SECTION_LINK_SELECTOR = "#external-section";
private static final String SECTION_SELECTOR = "#section";
private static final String JUMP_LINK_SELECTOR = "#jump-link";

private static final String INVALID_URL = "https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|"
+ "Google+Sans:400,500,700|Google+Sans+Text:400&lang=en";
Expand Down Expand Up @@ -142,6 +146,9 @@ class ResourceCheckStepsTests
<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUAAsTAAALEwEAmpwYAAAAAM4HdnM8AAAAABJRU5ErkJggg=='/>
<iframe src='https://selenide.org'/> \
<img id='shortcut-scheme' src='//images.ctfassets.net/us_cool_mint_pocketpaks_breath_strips.png'/>
<a id='external-section' href='https://external.page/other#section'>External jump link</a>
<a id='jump-link' href='#section'>Jump link</a>
<p id='section'>Section</p>
</body>
</html>""";

Expand All @@ -166,6 +173,7 @@ class ResourceCheckStepsTests
+ " <a id='link-id' href='https://vividus.org/about'>About</a>\r\n"
+ " <video id='video-id'>Some video without attributes</a>\r\n"
+ " <a id='link-id-2' href='" + INVALID_URL + "'>Fonts</a>\r\n"
+ " <a id='jump-link' href='#section'>Jump link</a>\r\n"
+ "</body>\r\n"
+ "</html>\r\n";

Expand Down Expand Up @@ -214,10 +222,13 @@ void shouldCheckDesiredResourcesAndPostAttachment() throws InterruptedException,
@SuppressWarnings(UNCHECKED)
Set<WebPageResourceValidation> validationsToReport = ((Map<String, Set<WebPageResourceValidation>>) m)
.get(RESULTS);
assertThat(validationsToReport, hasSize(13));
assertThat(validationsToReport, hasSize(15));
Iterator<WebPageResourceValidation> resourceValidations = validationsToReport.iterator();
validate(resourceValidations, URI.create(SECTION_SELECTOR), JUMP_LINK_SELECTOR, CheckStatus.PASSED, N_A);
validate(resourceValidations, SERENITY_URI, HTTP_ID, CheckStatus.PASSED, N_A);
validate(resourceValidations, imageUri, "#image", CheckStatus.PASSED, N_A);
validate(resourceValidations, EXTERNAL_SECTION_LINK, EXTERNAL_SECTION_LINK_SELECTOR, CheckStatus.PASSED,
N_A);
validate(resourceValidations, gifImageUri, "Unable to build CSS selector for 'img' element",
CheckStatus.PASSED, N_A);
validate(resourceValidations,
Expand Down Expand Up @@ -325,9 +336,12 @@ void shouldCheckResourcesFromPages() throws IOException, InterruptedException, E
@SuppressWarnings(UNCHECKED)
Set<WebPageResourceValidation> validationsToReport = ((Map<String, Set<WebPageResourceValidation>>) m)
.get(RESULTS);
assertThat(validationsToReport, hasSize(11));
assertThat(validationsToReport, hasSize(13));
Iterator<WebPageResourceValidation> resourceValidations = validationsToReport.iterator();
validate(resourceValidations.next(), URI.create(SECTION_SELECTOR), JUMP_LINK_SELECTOR, CheckStatus.PASSED);
validate(resourceValidations.next(), SERENITY_URI, HTTP_ID, CheckStatus.PASSED);
validate(resourceValidations.next(), EXTERNAL_SECTION_LINK, EXTERNAL_SECTION_LINK_SELECTOR,
CheckStatus.PASSED);
validate(resourceValidations.next(), URI.create(FIRST_PAGE_URL + SLASH), ROOT_ID, CheckStatus.PASSED);
validate(resourceValidations.next(), URI.create(FIRST_PAGE_URL + FAQ_URL), RELATIVE_ID, CheckStatus.PASSED);
validate(resourceValidations.next(), URI.create(FIRST_PAGE_URL + "/products?name=pelmeshki"),
Expand Down Expand Up @@ -362,11 +376,13 @@ void shouldCheckResourcesFromPagesWithEmptyResource() throws IOException, Interr
@SuppressWarnings(UNCHECKED)
Set<WebPageResourceValidation> validationsToReport = ((Map<String, Set<WebPageResourceValidation>>) m)
.get(RESULTS);
assertThat(validationsToReport, hasSize(3));
assertThat(validationsToReport, hasSize(4));
Iterator<WebPageResourceValidation> resourceValidations = validationsToReport.iterator();
validateError(resourceValidations.next(), "Element doesn't contain href/src attributes", "#video-id",
THIRD_PAGE_URL);
validateError(resourceValidations.next(), INVALID_HREF_ATTR_MESSAGE, "#link-id-2", THIRD_PAGE_URL);
validateError(resourceValidations.next(), "Jump link points to missing element with section id",
JUMP_LINK_SELECTOR, THIRD_PAGE_URL);
validate(resourceValidations.next(), VIVIDUS_ABOUT_URI, "#link-id", CheckStatus.PASSED);
return true;
}), eq(REPORT_NAME));
Expand Down Expand Up @@ -524,14 +540,17 @@ void shouldFilterResourceByRegExpCheckDesiredResourcesAnPostAttachment()
@SuppressWarnings(UNCHECKED)
Set<WebPageResourceValidation> validationsToReport = ((Map<String, Set<WebPageResourceValidation>>) m)
.get(RESULTS);
assertThat(validationsToReport, hasSize(10));
assertThat(validationsToReport, hasSize(12));
Iterator<WebPageResourceValidation> resourceValidations = validationsToReport.iterator();
validate(resourceValidations, EXTERNAL_SECTION_LINK, EXTERNAL_SECTION_LINK_SELECTOR, CheckStatus.PASSED,
N_A);
validate(resourceValidations, VIVIDUS_URI, HTTPS_ID, CheckStatus.PASSED, N_A);
validate(resourceValidations, ROOT_URI, ROOT_ID, CheckStatus.PASSED, N_A);
validate(resourceValidations, FAQ_URI, RELATIVE_ID, CheckStatus.PASSED, N_A);
validate(resourceValidations, VIVIDUS_QUERY_URI_1, SELECTOR_QUERY_1, CheckStatus.PASSED, N_A);
validate(resourceValidations, VIVIDUS_QUERY_URI_2, SELECTOR_QUERY_2, CheckStatus.PASSED, N_A);
validate(resourceValidations, SHARP_URI, SHARP_ID, CheckStatus.FILTERED, N_A);
validate(resourceValidations, URI.create(SECTION_SELECTOR), JUMP_LINK_SELECTOR, CheckStatus.FILTERED, N_A);
validate(resourceValidations, FTP_URI, FTP_ID, CheckStatus.FILTERED, N_A);
validate(resourceValidations, SERENITY_URI, HTTP_ID, CheckStatus.FILTERED, N_A);
validate(resourceValidations, JS_URI, JS_ID, CheckStatus.FILTERED, N_A);
Expand Down
7 changes: 7 additions & 0 deletions vividus-tests/src/main/resources/known-issues.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,12 @@
"scenarioPattern": "Known issue should should not stop the rest of the story if it's not marked as fail test suite fast",
"storyPattern": "Next known issues",
"stepPattern": "Then `vividus` matches.*"
},
"VVD-14": {
"type": "Internal",
"assertionPattern": "Jump link by selector .* points to missing element with notFound id",
"scenarioPattern": "Verification of Then all resources by selector.*",
"storyPattern": "ResourceCheckSteps",
"stepPattern": "Then all resources by selector.*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Meta:

Lifecycle:
Examples:
|pageToValidate |
|${vividus-test-site-url}|
|pageToValidate |
|${vividus-test-site-url}/links.html|

Scenario: Verification of Then all resources by selector $cssSelector from $html are valid; Source from HTTP response
When I execute HTTP GET request for resource with URL `<pageToValidate>`
Expand Down
0