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 ability to hide Shadow DOM attachments in report #5432

Merged
merged 1 commit into from
Oct 9, 2024
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
6 changes: 6 additions & 0 deletions docs/modules/plugins/pages/plugin-web-app.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ include::partial$common-web-app-properties.adoc[]
|`25`
|Before the click VIVIDUS scrolls element into the viewport, the property defines top edge indent in viewport percent for the scroll

|`ui.publish-shadow-dom-source-on-failure`
a|`true` +
`false`
|`true`
|Whether to publish the source code of Shadow DOM elements on failure or not

|===

=== Configure driver path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class WebContextSourceCodeProvider implements ContextSourceCodeProvider
private final IUiContext uiContext;
private final WebJavascriptActions webJavascriptActions;

private boolean collectShadowDomSourceCode;

protected WebContextSourceCodeProvider(IUiContext uiContext, WebJavascriptActions webJavascriptActions)
{
this.uiContext = uiContext;
Expand All @@ -62,7 +64,10 @@ else if (searchContext instanceof WebDriver webDriver)
{
sources.put(APPLICATION_SOURCE_CODE, sourceCode);
}
sources.putAll(getShadowDomSourceCode(elementInContext, searchContext));
if (collectShadowDomSourceCode)
{
sources.putAll(getShadowDomSourceCode(elementInContext, searchContext));
}
return sources;
}

Expand Down Expand Up @@ -103,4 +108,9 @@ private String getElementSource(SearchContext searchContext)
return null;
}
}

public void setCollectShadowDomSourceCode(boolean collectShadowDomSourceCode)
{
this.collectShadowDomSourceCode = collectShadowDomSourceCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ selenium.screenshot.full-page=true
selenium.screenshot.indent=300
# highlighter types: DEFAULT, BLUR, MONOCHROME
selenium.screenshot.highlighter=DEFAULT

ui.publish-shadow-dom-source-on-failure=true
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@
<bean class="org.vividus.ui.web.monitor.PublishingWebScreenshotOnFailureMonitor"
parent="abstractPublishingScreenshotOnFailureMonitor"/>

<bean class="org.vividus.selenium.WebContextSourceCodeProvider" />
<bean class="org.vividus.selenium.WebContextSourceCodeProvider">
<property name="collectShadowDomSourceCode" value="${ui.publish-shadow-dom-source-on-failure}" />
</bean>

<bean class="org.vividus.ui.listener.SourceCodePublishingOnFailureListener" lazy-init="false">
<property name="publishSourceOnFailure" value="${ui.publish-source-on-failure}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;

import java.util.List;
Expand Down Expand Up @@ -73,6 +74,7 @@ class WebContextSourceCodeProviderTests
@Test
void shouldReturnWholePageForDriverContext()
{
sourceCodeProvider.setCollectShadowDomSourceCode(true);
var webDriver = mock(WebDriver.class);
when(uiContext.getSearchContext()).thenReturn(webDriver);
var pageSource = "<html/>";
Expand All @@ -85,9 +87,23 @@ void shouldReturnWholePageForDriverContext()
sourceCodeProvider.getSourceCode());
}

@SuppressFBWarnings("VA_FORMAT_STRING_USES_NEWLINE")
@Test
void shouldReturnWholePageForDriverContextNoShadowDom()
{
sourceCodeProvider.setCollectShadowDomSourceCode(false);
var webDriver = mock(WebDriver.class);
when(uiContext.getSearchContext()).thenReturn(webDriver);
var pageSource = "<html></html>";
when(webDriver.getPageSource()).thenReturn(pageSource);
assertEquals(Map.of(APPLICATION_SOURCE_CODE, pageSource), sourceCodeProvider.getSourceCode());
verifyNoInteractions(webJavascriptActions);
}

@Test
void shouldReturnElementSourceForElementContext()
{
sourceCodeProvider.setCollectShadowDomSourceCode(true);
var webElement = mock(WebElement.class);
when(uiContext.getSearchContext()).thenReturn(webElement);
var elementSource = "<div/>";
Expand All @@ -101,6 +117,7 @@ void shouldReturnElementSourceForElementContext()
@Test
void shouldHandleStaleElementsCorrectly()
{
sourceCodeProvider.setCollectShadowDomSourceCode(true);
var webElement = mock(WebElement.class);
when(uiContext.getSearchContext()).thenReturn(webElement);
when(webJavascriptActions.executeScript(OUTER_HTML_SCRIPT, webElement)).thenThrow(
Expand All @@ -113,6 +130,7 @@ void shouldHandleStaleElementsCorrectly()
@Test
void shouldReturnEmptyValueForNullSearchContext()
{
sourceCodeProvider.setCollectShadowDomSourceCode(true);
when(uiContext.getSearchContext()).thenReturn(null);
when(webJavascriptActions.executeScript(any(String.class))).thenReturn(Map.of());
assertEquals(Map.of(), sourceCodeProvider.getSourceCode());
Expand Down
Loading