Path: blob/trunk/java/test/org/openqa/selenium/ClearTest.java
1865 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617package org.openqa.selenium;1819import static org.assertj.core.api.Assertions.assertThat;20import static org.assertj.core.api.Assertions.assertThatExceptionOfType;21import static org.openqa.selenium.testing.drivers.Browser.CHROME;22import static org.openqa.selenium.testing.drivers.Browser.EDGE;23import static org.openqa.selenium.testing.drivers.Browser.IE;2425import org.junit.jupiter.api.Test;26import org.openqa.selenium.testing.Ignore;27import org.openqa.selenium.testing.JupiterTestBase;28import org.openqa.selenium.testing.NotYetImplemented;2930class ClearTest extends JupiterTestBase {3132@Test33void testWritableTextInputShouldClear() {34driver.get(pages.readOnlyPage);35WebElement element = driver.findElement(By.id("writableTextInput"));36element.clear();37assertThat(element.getAttribute("value")).isEmpty();38}3940@Test41@Ignore(value = CHROME, reason = "https://bugs.chromium.org/p/chromedriver/issues/detail?id=4743")42@Ignore(value = EDGE, reason = "https://bugs.chromium.org/p/chromedriver/issues/detail?id=4743")43void testTextInputShouldNotClearWhenDisabled() {44driver.get(pages.readOnlyPage);45WebElement element = driver.findElement(By.id("textInputNotEnabled"));46assertThat(element.isEnabled()).isFalse();47assertThatExceptionOfType(InvalidElementStateException.class).isThrownBy(element::clear);48}4950@Test51void testTextInputShouldNotClearWhenReadOnly() {52driver.get(pages.readOnlyPage);53WebElement element = driver.findElement(By.id("readOnlyTextInput"));54assertThatExceptionOfType(InvalidElementStateException.class).isThrownBy(element::clear);55}5657@Test58void testWritableTextAreaShouldClear() {59driver.get(pages.readOnlyPage);60WebElement element = driver.findElement(By.id("writableTextArea"));61element.clear();62assertThat(element.getAttribute("value")).isEmpty();63}6465@Test66@Ignore(value = CHROME, reason = "https://bugs.chromium.org/p/chromedriver/issues/detail?id=4743")67@Ignore(value = EDGE, reason = "https://bugs.chromium.org/p/chromedriver/issues/detail?id=4743")68void testTextAreaShouldNotClearWhenDisabled() {69driver.get(pages.readOnlyPage);70WebElement element = driver.findElement(By.id("textAreaNotEnabled"));71assertThatExceptionOfType(InvalidElementStateException.class).isThrownBy(element::clear);72}7374@Test75void testTextAreaShouldNotClearWhenReadOnly() {76driver.get(pages.readOnlyPage);77WebElement element = driver.findElement(By.id("textAreaReadOnly"));78assertThatExceptionOfType(InvalidElementStateException.class).isThrownBy(element::clear);79}8081@Test82void testContentEditableAreaShouldClear() {83driver.get(pages.readOnlyPage);84WebElement element = driver.findElement(By.id("content-editable"));85element.clear();86assertThat(element.getText()).isEmpty();87}8889@Test90void shouldBeAbleToClearNoTypeInput() {91shouldBeAbleToClearInput(By.name("no_type"), "input with no type");92}9394@Test95void shouldBeAbleToClearNumberInput() {96shouldBeAbleToClearInput(By.name("number_input"), "42");97}9899@Test100void shouldBeAbleToClearEmailInput() {101shouldBeAbleToClearInput(By.name("email_input"), "admin@localhost");102}103104@Test105void shouldBeAbleToClearPasswordInput() {106shouldBeAbleToClearInput(By.name("password_input"), "qwerty");107}108109@Test110void shouldBeAbleToClearSearchInput() {111shouldBeAbleToClearInput(By.name("search_input"), "search");112}113114@Test115void shouldBeAbleToClearTelInput() {116shouldBeAbleToClearInput(By.name("tel_input"), "911");117}118119@Test120void shouldBeAbleToClearTextInput() {121shouldBeAbleToClearInput(By.name("text_input"), "text input");122}123124@Test125void shouldBeAbleToClearUrlInput() {126shouldBeAbleToClearInput(By.name("url_input"), "https://selenium.dev/");127}128129@Test130public void shouldBeAbleToClearRangeInput() {131shouldBeAbleToClearInput(By.name("range_input"), "42", "50");132}133134@Test135@NotYetImplemented(IE)136public void shouldBeAbleToClearColorInput() {137shouldBeAbleToClearInput(By.name("color_input"), "#00ffff", "#000000");138}139140@Test141public void shouldBeAbleToClearDateInput() {142shouldBeAbleToClearInput(By.name("date_input"), "2017-11-22");143}144145@Test146void shouldBeAbleToClearDatetimeInput() {147shouldBeAbleToClearInput(By.name("datetime_input"), "2017-11-22T11:22");148}149150@Test151public void shouldBeAbleToClearDatetimeLocalInput() {152shouldBeAbleToClearInput(By.name("datetime_local_input"), "2017-11-22T11:22");153}154155@Test156public void shouldBeAbleToClearTimeInput() {157shouldBeAbleToClearInput(By.name("time_input"), "11:22");158}159160@Test161public void shouldBeAbleToClearMonthInput() {162shouldBeAbleToClearInput(By.name("month_input"), "2017-11");163}164165@Test166public void shouldBeAbleToClearWeekInput() {167shouldBeAbleToClearInput(By.name("week_input"), "2017-W47");168}169170private void shouldBeAbleToClearInput(By locator, String oldValue) {171shouldBeAbleToClearInput(locator, oldValue, "");172}173174private void shouldBeAbleToClearInput(By locator, String oldValue, String clearedValue) {175driver.get(appServer.whereIs("inputs.html"));176WebElement element = driver.findElement(locator);177assertThat(element.getAttribute("value")).isEqualTo(oldValue);178element.clear();179assertThat(element.getAttribute("value")).isEqualTo(clearedValue);180}181}182183184