Skip to content

Commit e8a7d5b

Browse files
committed
[plugin-web-app-to-rest-api] Revert back safe building of CSS selectors
1 parent a82b2b9 commit e8a7d5b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

vividus-plugin-web-app-to-rest-api/src/main/java/org/vividus/steps/integration/ResourceCheckSteps.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.jbehave.core.model.ExamplesTable;
3939
import org.jsoup.nodes.Document;
4040
import org.jsoup.nodes.Element;
41+
import org.jsoup.select.Selector.SelectorParseException;
4142
import org.vividus.html.HtmlLocatorType;
4243
import org.vividus.html.JsoupUtils;
4344
import org.vividus.http.HttpMethod;
@@ -162,7 +163,7 @@ private Optional<WebPageResourceValidation> parseElement(Element element, boolea
162163
return Optional.empty();
163164
}
164165

165-
String elementCssSelector = element.cssSelector();
166+
String elementCssSelector = getCssSelector(element);
166167
if (elementUriAsString.isEmpty())
167168
{
168169
return Optional.of(ResourceValidationError.EMPTY_HREF_SRC
@@ -246,6 +247,18 @@ private static String getElementUri(Element element)
246247
return element.attr("src");
247248
}
248249

250+
private String getCssSelector(Element element)
251+
{
252+
try
253+
{
254+
return element.cssSelector();
255+
}
256+
catch (SelectorParseException exception)
257+
{
258+
return String.format("Unable to build CSS selector for '%s' element", element.tagName());
259+
}
260+
}
261+
249262
private URI resolveUri(String uri) throws URISyntaxException
250263
{
251264
URI uriToCheck = new URI(uri);

vividus-plugin-web-app-to-rest-api/src/test/java/org/vividus/steps/integration/ResourceCheckStepsTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class ResourceCheckStepsTests
154154
<p id='section'>Section</p>
155155
<a id='jump-link-using-name' href='#named-section'>Jump link using name</a>
156156
<p name='named-section'>Named Section</a>
157+
<img class="vds-flex_1 vds-d_block lg:vds-d_flex vds-flex_column vds-items_flex-end
158+
[&amp;_>_*:first-child]:vds-pt_0"
159+
href="https://docs.vividus.dev/vividus/latest/_images/subscribe-to-releases.gif"></img>
157160
</body>
158161
</html>""";
159162

@@ -228,13 +231,16 @@ void shouldCheckDesiredResourcesAndPostAttachment() throws InterruptedException,
228231
@SuppressWarnings(UNCHECKED)
229232
Set<WebPageResourceValidation> validationsToReport = ((Map<String, Set<WebPageResourceValidation>>) m)
230233
.get(RESULTS);
231-
assertThat(validationsToReport, hasSize(16));
234+
assertThat(validationsToReport, hasSize(17));
232235
Iterator<WebPageResourceValidation> resourceValidations = validationsToReport.iterator();
233236
validate(resourceValidations, URI.create(NAMED_SECTION_SELECTOR), JUMP_LINK_USING_NAME_SELECTOR,
234237
CheckStatus.PASSED, N_A);
235238
validate(resourceValidations, URI.create(SECTION_SELECTOR), JUMP_LINK_SELECTOR, CheckStatus.PASSED, N_A);
236239
validate(resourceValidations, SERENITY_URI, HTTP_ID, CheckStatus.PASSED, N_A);
237240
validate(resourceValidations, imageUri, "#image", CheckStatus.PASSED, N_A);
241+
validate(resourceValidations,
242+
URI.create("https://docs.vividus.dev/vividus/latest/_images/subscribe-to-releases.gif"),
243+
"Unable to build CSS selector for 'img' element", CheckStatus.PASSED, N_A);
238244
validate(resourceValidations, EXTERNAL_SECTION_LINK, EXTERNAL_SECTION_LINK_SELECTOR, CheckStatus.PASSED,
239245
N_A);
240246
validate(resourceValidations, gifImageUri, "html > body > img.image.\\(gif\\)",

0 commit comments

Comments
 (0)