8000 [plugin-web-app] Handle `ElementNotInteractableException` on typing text to field by valfirst · Pull Request #3940 · 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] Handle ElementNotInteractableException on typing text to field #3940

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

Merged
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
8000
Diff view
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 @@ -64,7 +64,7 @@ public CodeSteps(WebJavascriptActions javascriptActions, VariableContext variabl
* <p>
* To make a JavaScript call one can open a <b><i>JavaScript console</i></b> in a browser <i>(via Ctrl+Shift+J)</i>,
* type the <b>script</b> string and press <i>Enter</i>.
* <p>
* </p>
* Actions performed at this step:
* <ul>
* <li>Removes the value of JSON message field;
Expand Down Expand Up @@ -150,7 +150,6 @@ public List<WebElement> doesInvisibleQuantityOfElementsExists(Locator locator,
* Executes passed async javascript code on the opened page
* and saves returned value into the <b>variable</b>
* See {@link org.openqa.selenium.JavascriptExecutor#executeAsyncScript(String, Object[])}
* <p>
*
* @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of variable's scope<br>
* <i>Available scopes:</i>
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 @@ -154,7 +154,7 @@ public void clearFieldUsingKeyboard(Locator locator)
* It's allowed to add the text to elements declared using <i>{@literal <input>}</i> or <i>{@literal
* <textarea>}</i> tags and from CKE editors (they usually should be located via {@literal <body>} tag, that is
* contained in a frame as a separate HTML document).
* <p>
* </p>
*
* @param text The text to add to the field.
* @param locator The locator used to find field.
Expand All @@ -175,7 +175,7 @@ public void addTextToFieldLocatedBy(String text, Locator locator)
* It's allowed to add the text to elements declared using <i>{@literal <input>}</i> or <i>{@literal
* <textarea>}</i> tags and from CKE editors (they usually should be located via {@literal <body>} tag, that is
* contained in a frame as a separate HTML document).
* <p>
* </p>
*
* @param text The text to add to the field.
* @param locator The locator used to find field.
Expand Down Expand Up @@ -273,7 +273,7 @@ private void enterTextInField(WebElement element, String text, boolean retry, Ru
return;
}

element.sendKeys(text);
fieldActions.typeText(element, text);
applyWorkaroundIfIE(element, text);
}
catch (StaleElementReferenceException e)
Expand All @@ -300,7 +300,7 @@ private void applyWorkaroundIfIE(WebElement element, String normalizedText)
{
element.clear();
LOGGER.info("Re-typing text \"{}\" to element", normalizedText);
element.sendKeys(normalizedText);
fieldActions.typeText(element, normalizedText);
iterationsCounter--;
}
if (iterationsCounter == 0 && !isValueEqualTo(element, normalizedText))
Expand All @@ -322,7 +322,7 @@ private boolean isValueEqualTo(WebElement element, String expectedValue)
* <b>Field</b> is a {@literal <input> or <textarea>} tags in the table (or a {@literal <body>} tag if you work with
* CKE editor - a field to enter and edit text, that is contained in a {@literal <frame>} as a separate
* html-document)
* <p>
* </p>
*
* @param locator The locator used to find field.
* @deprecated Use step replacement pattern: Then number of elements found by `&lt;locator&gt;` is equal to `0`
Expand All @@ -340,7 +340,7 @@ public void doesNotFieldExist(Locator locator)
* <b>Field</b> is a {@literal <input> or <textarea>} tags in the table (or a {@literal <body>} tag if you work with
* CKE editor - a field to enter and edit text, that is contained in a {@literal <frame>} as a separate
* html-document)
* <p>
* </p>
*
* @param locator The locator used to find field.
* @return WebElement
Expand Down
6DB6
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void openMainApplicationPage()
* Loads a <b>page</b> with the given <b>URL</b>
* <p>
* Requires an <b>absolute</b> URL (like https://example.com/).
* <p>
* </p>
* @param pageURL An <b>absolute</b> URL of the page
*/
@Given("I am on page with URL `$pageURL`")
Expand All @@ -117,14 +117,13 @@ public void openPage(String pageURL)
/**
* Checks, that the current page has a correct relative URL <br>
* A <b>relative URL</b> - points to a file within a web site (like <i>'about.html'</i> or <i>'/products'</i>)<br>
* <p>
* Actions performed at this step:
* <ul>
* <li>Gets the absolute URL of the current page;
* <li>Gets relative URL from it;
* <li>Compares it with the specified relative URL.
* </ul>
* <p>
*
* @param relativeURL A string value of the relative URL
* @deprecated Use combination of step and expression:
* "Then `#{extractPathFromUrl(${current-page-url})}` is equal to `$variable2`"
Expand All @@ -148,15 +147,14 @@ public void checkPageRelativeURL(String relativeURL)
}

/**
* Checks, that the current page has a correct host
* <p>
* Checks, that the current page has a correct host.<br/>
* Actions performed at this step:
* <ul>
* <li>Gets the absolute URL of the current page;
* <li>Gets page host from it;
* <li>Compares it with the specified page host.
* </ul>
* <p>

* @param host A string value of the page host
* @deprecated Use combination of step and expression:
* "Then `#{extractHostFromUrl(${current-page-url})}` is equal to `$variable2`"
Expand Down Expand Up @@ -201,7 +199,7 @@ public void openPageUrlInNewWindow(String pageUrl)
/**
* Checks, that the <b><i>page</i></b> with certain <b>URL</b> is loaded <br>
* <b>URL</b> is the internet address of the current page which is located in the address bar
* <p>
*
* @param url String value of URL
* @deprecated Use combination of step and dynamic variable:
* "Then `${current-page-url}` is equal to `$variable2`"
Expand Down Expand Up @@ -259,13 +257,12 @@ public void checkUrlPartIsLoaded(String urlPart)
* <td>https://mysite.com/path/foo</td><td>/documents</td><td>https://mysite.com/documents</td>
* </tr>
* </table>
* <p>
* Actions performed at this step:
* <ul>
* <li>Builds the absolute URL by concatenating the base URL and the relative URL;
* <li>Loads the page with the absolute URL;
* </ul>
* <p>
*
* @param relativeURL A string value of the relative URL
*/
@When("I go to relative URL `$relativeURL`")
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 @@ -37,13 +37,13 @@ public class ScriptSteps
* <p>
* JS files are placed under <i>{@literal <script>}</i> tag having attribute <i>type</i> = "text/javascript". Their
* <b>filename</b> is specified in <i>src</i> attribute.
* <p>
* <br/>
* Actions performed at this step:
* <ul>
* <li><i>Checks</i> if the javascript file with the given filename exists in the page source code
* <li>Step passes if only one such JS file was found. Otherwise step fails.
* </ul>
* <p>
*
* @param jsFileName Value of the <i>src</i> attribute
* @return webElement found js script
*/
Expand All @@ -62,13 +62,13 @@ public WebElement thenJavascriptFileWithNameIsIncludedInTheSourceCode(String jsF
* <p>
* JS files are placed under <i>{@literal <script>}</i> tag having attribute <i>type</i> = "text/javascript".
* <b>Text</b> is actual content of <i>{@literal <script>}</i> tag.
* <p>
* <br/>
* Actions performed at this step:
* <ul>
* <li><i>Checks</i> if the javascript file with the given text exists in the page source code
* <li>Step passes if only one such JS file was found. Otherwise step fails.
* </ul>
* <p>
*
* @param jsText Content of the <i>{@literal <script>}</i> tag.
* @return webElement found js script
*/
Expand All @@ -87,13 +87,13 @@ public WebElement thenJavascriptFileWithTextIsIncludedInTheSourceCode(String jsT
* <p>
* JS files are placed under <i>{@literal <script>}</i> tag having attribute <i>type</i> = "text/javascript".
* <b>Text</b> is actual content of <i>{@literal <script>}</i> tag.
* <p>
* <br/>
* Actions performed at this step:
* <ul>
* <li><i>Checks</i> if the javascript file containing the given text exists in the page source code.
* <li>Step passes if only one such JS file was found. Otherwise step fails.
* </ul>
* <p>
*
* @param jsTextPart String which should be contained in the <i>{@literal <script>}</i> tag.
* @return webElement found js script
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void savePathFromUrl(Set<VariableScope> scopes, String variable)

/**
* Saves the number of currently opened tabs in the browser to the variable
* <p>
*
* @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of variable's scope<br>
* <i>Available scopes:</i>
* <ul>
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 @@ -141,7 +141,7 @@ public void closeCurrentWindow()
* <p>
* Note that this step can only be used if the current window was opened using the step
* 'When I open URL `$pageUrl` in new window'.
* <p>
* </p>
* @see <a href="https://html.spec.whatwg.org/#browsing-context"><i>Browsing context (Window &amp; Document)</i></a>
* @see <a href="https://www.w3schools.com/tags/default.asp"><i>HTML Element Reference</i></a>
* @see <a href="https://www.w3schools.com/jsref/event_onbeforeunload.asp"><i>Event 'onbeforeunload'</i></a>
Expand Down
Original file line number Dif 10000 f line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map.Entry;

import org.openqa.selenium.By;
import org.openqa.selenium.ElementNotInteractableException;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.Browser;
Expand Down Expand Up @@ -106,7 +107,9 @@ public void clearFieldUsingKeyboard(WebElement field)
if (field != null)
{
Entry<Keys, String> controllingKey = keysManager.getOsIndependentControlKey();
LOGGER.info("Attempting to clear field with [{} + A, Backspace] keys sequence", controllingKey.getValue());
LOGGER.atInfo()
.addArgument(controllingKey::getValue)
.log("Attempting to clear field with [{} + A, Backspace] keys sequence");
field.sendKeys(Keys.chord(controllingKey.getKey(), "a") + Keys.BACK_SPACE);
}
}
Expand Down Expand Up @@ -135,11 +138,24 @@ public void addText(WebElement element, String text)
}
else
{
element.sendKeys(normalizedText);
typeText(element, normalizedText);
}
}
}

@Override
public void typeText(WebElement element, String text)
{
try
{
element.sendKeys(text);
}
catch (ElementNotInteractableException e)
{
softAssert.recordFailedAssertion(e);
}
}

@Override
public boolean isElementContenteditable(WebElement element)
{
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 @@ -32,6 +32,13 @@ public interface IFieldActions
*/
void addText(WebElement element, String text);

/**
* Types the text in the element
* @param element The element to type text in
* @param text The text to type
*/
void typeText(WebElement element, String text);

/**
* Checks that the content of the element is editable
* @param element element to check
Expand Down
Loading
0