2 * Copyright 2000-2014 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.tests.elements.abstracttextfield;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
22 import com.vaadin.testbench.elements.AbstractTextFieldElement;
23 import com.vaadin.testbench.elements.DateFieldElement;
24 import com.vaadin.testbench.elements.LabelElement;
25 import com.vaadin.testbench.elements.PasswordFieldElement;
26 import com.vaadin.testbench.elements.TextAreaElement;
27 import com.vaadin.testbench.elements.TextFieldElement;
28 import com.vaadin.tests.tb3.MultiBrowserTest;
35 public class AbstractTextElementSetValueTest extends MultiBrowserTest {
36 private final static String TYPED_STRING = "this is typed string";
44 public void textFieldSetValue() {
45 checkType($(TextFieldElement.class).get(0),
46 $(LabelElement.class).get(1));
50 public void passwordFieldSetValue() {
51 checkType($(PasswordFieldElement.class).get(0),
52 $(LabelElement.class).get(2));
56 public void textAreaSetValue() {
57 checkType($(TextAreaElement.class).get(0),
58 $(LabelElement.class).get(3));
62 public void dateFieldSetValue() {
63 DateFieldElement elem = $(DateFieldElement.class).get(0);
64 LabelElement eventCount = $(LabelElement.class).get(4);
65 // we can type any string in date field element
66 elem.setValue(TYPED_STRING);
67 // invalid values are cleared stays
68 Assert.assertEquals(TYPED_STRING, elem.getValue());
72 // checks that setValue method works
73 private void checkType(AbstractTextFieldElement elem,
74 LabelElement eventCount) {
75 // check first that the initial value is set
76 Assert.assertEquals(AbstractTextElementSetValue.INITIAL_VALUE,
78 elem.setValue(TYPED_STRING);
80 // check that typed value is the same
81 Assert.assertEquals(TYPED_STRING, elem.getValue());
83 // checks that there was only one change value event
84 Assert.assertEquals("1", eventCount.getText());