Skip to content

Commit

Permalink
[plugin-web-app] Record failed assertion for intercepted click
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow committed Feb 1, 2023
1 parent 321c018 commit 5fe1eaa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
11 changes: 11 additions & 0 deletions docs/modules/plugins/partials/plugin-web-app-steps.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ The atomic actions performed are:
words if https://www.selenium.dev/exceptions/#stale_element_reference[StaleElementReferenceException]
is occurred at any atomic action.

[NOTE]
====
If element by the specified locator is not clickable (overlapped by another element, problems with page/context loading or the element is disabled) the step will fail with corresponding error:
[source]
----
Could not click on the element: org.openqa.selenium.ElementClickInterceptedException: element click intercepted:
Element <a href="#where-to-buy" data-tab-name="..." role="button">Where to Buy</a> is not clickable at point (1619, 275).
Other element would receive the click: <div class="content">...</div>
----
====

[source,gherkin]
----
When I click on element located by `$locator`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -91,10 +91,9 @@ private void tryToWorkaroundException(WebElement element, Optional<Action> defau
{
try
{
if (webDriverManager.isBrowserAnyOf(Browser.CHROME)
&& message.contains(". Other element would receive the click"))
if (message.contains(". Other element would receive the click"))
{
javascriptActions.click(element);
softAssert.recordFailedAssertion(COULD_NOT_CLICK_ERROR_MESSAGE + webDriverException);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -195,7 +195,6 @@ void clickElementExpectedException()
@Test
void clickElementNotClickableStaleReferenceExceptionNotChrome()
{
when(webDriverManager.isBrowserAnyOf(Browser.CHROME)).thenReturn(false);
mockBodySearch();

WebDriverException e = new WebDriverException(ELEMENT_IS_NOT_CLICKABLE_AT_POINT);
Expand Down Expand Up @@ -248,7 +247,6 @@ void clickElementGenericWebDriverException()
@Test
void clickElementNotClickableExceptionNoExceptionNotChrome()
{
when(webDriverManager.isBrowserAnyOf(Browser.CHROME)).thenReturn(false);
mockBodySearch();

WebDriverException e = new WebDriverException(ELEMENT_IS_NOT_CLICKABLE_AT_POINT);
Expand All @@ -261,7 +259,6 @@ void clickElementNotClickableExceptionNoExceptionNotChrome()
@Test
void clickElementNotClickableExceptionStaleExceptionChrome()
{
when(webDriverManager.isBrowserAnyOf(Browser.CHROME)).thenReturn(true);
mockBodySearch();

WebDriverException e = new WebDriverException(ELEMENT_IS_NOT_CLICKABLE_AT_POINT);
Expand All @@ -277,7 +274,6 @@ void clickElementNotClickableExceptionStaleExceptionChrome()
@Test
void clickElementNotClickableExceptionNoExceptionChrome()
{
when(webDriverManager.isBrowserAnyOf(Browser.CHROME)).thenReturn(true);
mockBodySearch();

WebDriverException e = new WebDriverException(ELEMENT_IS_NOT_CLICKABLE_AT_POINT);
Expand All @@ -286,38 +282,19 @@ void clickElementNotClickableExceptionNoExceptionChrome()
}

@Test
void clickElementNotClickableExceptionWithJsChrome()
void shouldRecordFailedAssertionWhenClickOverlappedElement()
{
when(webDriverManager.isBrowserAnyOf(Browser.CHROME)).thenReturn(true);
mockBodySearch();

WebDriverException e = new WebDriverException(OTHER_ELEMENT_WOULD_RECEIVE_CLICK);
doThrow(e).when(webElement).click();
ClickResult result = mouseActions.click(webElement);
assertFalse(result.isNewPageLoaded());
InOrder ordered = inOrder(javascriptActions, alertActions, eventBus, uiContext, softAssert);
ordered.verify(javascriptActions).scrollElementIntoViewportCenter(webElement);
ordered.verify(javascriptActions).click(webElement);
ordered.verify(alertActions).waitForAlert(webDriver);
ordered.verify(eventBus).post(any(PageLoadEndEvent.class));
ordered.verifyNoMoreInteractions();
}

@Test
void clickElementNotClickableExceptionWithoutJsNotChrome()
{
when(webDriverManager.isBrowserAnyOf(Browser.CHROME)).thenReturn(false);
mockBodySearch();

WebDriverException e = new WebDriverException(OTHER_ELEMENT_WOULD_RECEIVE_CLICK);
doThrow(e).doNothing().when(webElement).click();
testClickWithElementNotClickableException();
var exception = new WebDriverException(OTHER_ELEMENT_WOULD_RECEIVE_CLICK);
doThrow(exception).when(webElement).click();
testClick(false, false);
verify(softAssert).recordFailedAssertion(COULD_NOT_CLICK_ERROR_MESSAGE + exception);
}

@Test
void clickElementNotClickableExceptionAndWebDriverExceptionInChromeWorkaround()
{
when(webDriverManager.isBrowserAnyOf(Browser.CHROME)).thenReturn(true);
mockBodySearch();

WebDriverException e = new WebDriverException(ELEMENT_IS_NOT_CLICKABLE_AT_POINT);
Expand Down

0 comments on commit 5fe1eaa

Please sign in to comment.