| // <copyright file="ClearTests.cs" company="Selenium Committers"> | |
| // Licensed to the Software Freedom Conservancy (SFC) under one | |
| // or more contributor license agreements. See the NOTICE file | |
| // distributed with this work for additional information | |
| // regarding copyright ownership. The SFC licenses this file | |
| // to you under the Apache License, Version 2.0 (the | |
| // "License"); you may not use this file except in compliance | |
| // with the License. You may obtain a copy of the License at | |
| // | |
| // http://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, | |
| // software distributed under the License is distributed on an | |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| // KIND, either express or implied. See the License for the | |
| // specific language governing permissions and limitations | |
| // under the License. | |
| // </copyright> | |
| namespace OpenQA.Selenium.Tests; | |
| [TestFixture] | |
| public class ClearTests : DriverTestFixture | |
| { | |
| [Test] | |
| public void WritableTextInputShouldClear() | |
| { | |
| Driver.Url = Urls.ReadOnlyPage; | |
| IWebElement element = Driver.FindElement(By.Id("writableTextInput")); | |
| element.Clear(); | |
| Assert.That(element.GetAttribute("value"), Is.Empty); | |
| } | |
| [Test] | |
| public void TextInputShouldNotClearWhenDisabled() | |
| { | |
| Driver.Url = Urls.ReadOnlyPage; | |
| IWebElement element = Driver.FindElement(By.Id("textInputNotEnabled")); | |
| Assert.That(element.Enabled, Is.False); | |
| Assert.That( | |
| () => element.Clear(), | |
| Throws.InstanceOf<InvalidElementStateException>()); | |
| } | |
| [Test] | |
| public void TextInputShouldNotClearWhenReadOnly() | |
| { | |
| Driver.Url = Urls.ReadOnlyPage; | |
| IWebElement element = Driver.FindElement(By.Id("readOnlyTextInput")); | |
| Assert.That( | |
| () => element.Clear(), | |
| Throws.InstanceOf<InvalidElementStateException>()); | |
| } | |
| [Test] | |
| public void WritableTextAreaShouldClear() | |
| { | |
| Driver.Url = Urls.ReadOnlyPage; | |
| IWebElement element = Driver.FindElement(By.Id("writableTextArea")); | |
| element.Clear(); | |
| Assert.That(element.GetAttribute("value"), Is.Empty); | |
| } | |
| [Test] | |
| public void TextAreaShouldNotClearWhenDisabled() | |
| { | |
| Driver.Url = Urls.ReadOnlyPage; | |
| IWebElement element = Driver.FindElement(By.Id("textAreaNotEnabled")); | |
| Assert.That(() => element.Clear(), Throws.InstanceOf<InvalidElementStateException>()); | |
| } | |
| [Test] | |
| public void TextAreaShouldNotClearWhenReadOnly() | |
| { | |
| Driver.Url = Urls.ReadOnlyPage; | |
| IWebElement element = Driver.FindElement(By.Id("textAreaReadOnly")); | |
| Assert.That( | |
| () => element.Clear(), | |
| Throws.InstanceOf<InvalidElementStateException>()); | |
| } | |
| [Test] | |
| public void ContentEditableAreaShouldClear() | |
| { | |
| Driver.Url = Urls.ReadOnlyPage; | |
| IWebElement element = Driver.FindElement(By.Id("content-editable")); | |
| element.Clear(); | |
| Assert.That(element.Text, Is.Empty); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearNoTypeInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("no_type"), "input with no type"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearNumberInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("number_input"), "42"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearEmailInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("email_input"), "admin@localhost"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearPasswordInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("password_input"), "qwerty"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearSearchInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("search_input"), "search"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearTelInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("tel_input"), "911"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearTextInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("text_input"), "text input"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearUrlInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("url_input"), "https://selenium.dev/"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearRangeInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("range_input"), "42", "50"); | |
| } | |
| [Test] | |
| [IgnoreBrowser(Browser.IE, "Driver does not support clearing color elements")] | |
| public void ShouldBeAbleToClearColorInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("color_input"), "#00ffff", "#000000"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearDateInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("date_input"), "2017-11-22"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearDatetimeInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("datetime_input"), "2017-11-22T11:22"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearDatetimeLocalInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("datetime_local_input"), "2017-11-22T11:22"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearTimeInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("time_input"), "11:22"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearMonthInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("month_input"), "2017-11"); | |
| } | |
| [Test] | |
| public void ShouldBeAbleToClearWeekInput() | |
| { | |
| ShouldBeAbleToClearInput(By.Name("week_input"), "2017-W47"); | |
| } | |
| private void ShouldBeAbleToClearInput(By locator, string oldValue) | |
| { | |
| ShouldBeAbleToClearInput(locator, oldValue, string.Empty); | |
| } | |
| private void ShouldBeAbleToClearInput(By locator, string oldValue, string clearedValue) | |
| { | |
| Driver.Url = Urls.WhereIs("inputs.html"); | |
| IWebElement element = Driver.FindElement(locator); | |
| Assert.That(element.GetAttribute("value"), Is.EqualTo(oldValue)); | |
| element.Clear(); | |
| Assert.That(element.GetAttribute("value"), Is.EqualTo(clearedValue)); | |
| } | |
| } |