Skip to content

Commit

Permalink
[java] Fixing sendKeys to handle newline characters properly. Fixes S…
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Mar 18, 2020
1 parent bed0e21 commit 126be14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void sendKeys(CharSequence... keysToSend) {
List<File> files = Arrays.stream(allKeysToSend.split("\n"))
.map(fileDetector::getLocalFile)
.collect(Collectors.toList());
if (! files.contains(null)) {
if (!files.isEmpty() && !files.contains(null)) {
allKeysToSend = files.stream()
.map(this::upload)
.collect(Collectors.joining("\n"));
Expand Down
17 changes: 17 additions & 0 deletions java/client/test/org/openqa/selenium/TypingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.openqa.selenium.testing.TestUtilities.isFirefox;

import org.junit.Test;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;
import org.openqa.selenium.testing.NotYetImplemented;
Expand Down Expand Up @@ -657,6 +658,22 @@ public void canClearNumberInputAfterTypingInvalidInput() {
assertThat(input.getAttribute("value")).isEqualTo("3");
}

@Test
public void canTypeSingleNewLineCharacterIntoTextArea() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.id("emptyTextArea"));
element.sendKeys("\n");
shortWait.until(ExpectedConditions.attributeToBe(element, "value", "\n"));
}

@Test
public void canTypeMultipleNewLineCharactersIntoTextArea() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.id("emptyTextArea"));
element.sendKeys("\n\n\n");
shortWait.until(ExpectedConditions.attributeToBe(element, "value", "\n\n\n"));
}

private static String getValueText(WebElement el) {
// Standardize on \n and strip any trailing whitespace.
return el.getAttribute("value").replace("\r\n", "\n").trim();
Expand Down

0 comments on commit 126be14

Please sign in to comment.