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 TextInput.setText #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected void fillRadio(WebElement element, String value) {

protected void fillInput(WebElement element, String value) {
TextInput input = new TextInput(element);
input.sendKeys(input.getClearCharSequence() + value);
input.setText(value);
}

protected void fillSelect(WebElement element, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public void sendKeys(CharSequence... keys) {
getWrappedElement().sendKeys(keys);
}

/**
* Sets this text input's value.
Copy link
Contributor

@ham1 ham1 Jun 13, 2016

Choose a reason for hiding this comment

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

Perhaps be explicit about using getClearCharSequence() and not using clear()?

*
* @param newValue New value for this text input.
*/
public void setText(String newValue) {
getWrappedElement().sendKeys(getClearCharSequence() + newValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think instead the getClearCharSequence() + should be added to TextInput.sendKeys method. This way everybody who wants to change input value has no need to prepend it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would break backward compatibility and would be counterintuitive.
Also there may be situations when you don't want to clear anything, you just want to press a key.

}

/**
* @return Text entered into the text input.
* @deprecated Use getText() instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public void fillForm() {
// Prepare data to fill form with
Map<String, Object> data = new HashMap<String, Object>();
data.put(MockedForm.TEXT_INPUT_NAME, INPUT_TEXT_TO_SEND);
data.put(MockedForm.TEXT_INPUT_WITH_TEXT_NAME, INPUT_TEXT_TO_SEND);
data.put(MockedForm.CHECKBOX_NAME, CHECKBOX_VALUE_TO_SET);
data.put(MockedForm.RADIO_NAME, MockedForm.RADIO_BUTTON_VALUE);
data.put(MockedForm.SELECT_NAME, MockedForm.SELECT_OPTION_VALUE);
Expand All @@ -39,7 +38,6 @@ public void fillForm() {
public void formFieldsShouldBeFilledCorrectly() {
fillForm();
verify(form.getTextInput()).sendKeys(INPUT_TEXT_TO_SEND);
verify(form.getTextInputWithText()).sendKeys(INPUT_WITH_TEXT_KEYS_TO_SEND);
verify(form.getCheckBox()).click();
verify(form.getRadioButton()).click();
verify(form.getSelectOption()).click();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ru.yandex.qatools.htmlelements;

import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import ru.yandex.qatools.htmlelements.element.TextInput;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
* @author Alexander Kedrik [email protected]
* Date: 08.09.15
*/
public class TextInputSetTextMethodTest {
private final WebElement webElement = mock(WebElement.class);
private final TextInput textInput = new TextInput(webElement);

@Test
public void setTextShouldNotAddClearKeysForTextInputWithEmptyText() {
when(webElement.getAttribute("value")).thenReturn("");
textInput.setText("qwerty");
Copy link
Contributor

Choose a reason for hiding this comment

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

where is assertion for this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

verify(webElement).sendKeys("qwerty");
}

@Test
public void setTextShouldAddClearKeysForTextInputWithNonEmptyText() {
when(webElement.getAttribute("value")).thenReturn("12");
textInput.setText("qwerty");
verify(webElement).sendKeys(Keys.DELETE.toString() + Keys.BACK_SPACE + Keys.DELETE + Keys.BACK_SPACE + "qwerty");
}
}