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

[plugin-web-app] Record failed assertion for intercepted click #3601

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
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you appending an exception? What is the resulting error?
org.vividus.softassert.SoftAssert#recordFailedAssertion(java.lang.String, java.lang.Throwable)

Copy link
Contributor Author

@draker94 draker94 Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the resulting error?

interException

Why are you appending an exception?

It has pretty enough information about the error

org.vividus.softassert.SoftAssert#recordFailedAssertion(java.lang.String, java.lang.Throwable)

I think previous way (see previous pic) in the result more readable
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO you should record the exception with stacktrace

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this case that's doubtful, stack trace won't give any useful information

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, we can expand error in Allure for stack trace
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you all agree on the matter, it is up to you how to deal with the stacktrace. However, that doesn't explain why you are appending an exception instead of its message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you are appending an exception instead of its message

image
🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, is it useful for the user to have the class name in error?

}
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