Path: blob/trunk/java/test/org/openqa/selenium/ElementDomPropertyTest.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;2021import java.util.List;22import org.junit.jupiter.api.Test;23import org.openqa.selenium.support.ui.ExpectedConditions;24import org.openqa.selenium.testing.JupiterTestBase;2526class ElementDomPropertyTest extends JupiterTestBase {2728@Test29void testShouldReturnNullWhenGettingTheValueOfAPropertyThatDoesNotExist() {30driver.get(pages.simpleTestPage);31WebElement head = driver.findElement(By.xpath("/html"));32assertThat(head.getDomProperty("cheese")).isNull();33}3435@Test36void testShouldReturnAnAbsoluteUrlWhenGettingSrcAttributeOfAValidImgTag() {37driver.get(pages.simpleTestPage);38WebElement img = driver.findElement(By.id("validImgTag"));39assertThat(img.getDomProperty("src")).isEqualTo(appServer.whereIs("icon.gif"));40}4142@Test43void testShouldReturnAnAbsoluteUrlWhenGettingHrefAttributeOfAValidAnchorTag() {44driver.get(pages.simpleTestPage);45WebElement img = driver.findElement(By.id("validAnchorTag"));46assertThat(img.getDomProperty("href")).isEqualTo(appServer.whereIs("icon.gif"));47}4849@Test50void testShouldReturnTheValueOfTheIndexAttributeEvenIfItIsMissing() {51driver.get(pages.formPage);52WebElement multiSelect = driver.findElement(By.id("multi"));53List<WebElement> options = multiSelect.findElements(By.tagName("option"));54assertThat(options.get(1).getDomProperty("index")).isEqualTo("1");55}5657@Test58void testShouldReturnTheValueOfCheckedForACheckboxOnlyIfItIsChecked() {59driver.get(pages.formPage);60WebElement checkbox = driver.findElement(By.xpath("//input[@id='checky']"));61assertThat(checkbox.getDomProperty("checked")).isEqualTo("false");62checkbox.click();63assertThat(checkbox.getDomProperty("checked")).isEqualTo("true");64}6566@Test67void testShouldReturnTheValueOfSelectedForOptionsOnlyIfTheyAreSelected() {68driver.get(pages.formPage);69WebElement selectBox = driver.findElement(By.xpath("//select[@name='selectomatic']"));70List<WebElement> options = selectBox.findElements(By.tagName("option"));71WebElement one = options.get(0);72WebElement two = options.get(1);73assertThat(one.isSelected()).isTrue();74assertThat(two.isSelected()).isFalse();75assertThat(one.getDomProperty("selected")).isEqualTo("true");76assertThat(two.getDomProperty("selected")).isEqualTo("false");77assertThat(selectBox.getDomProperty("selectedIndex")).isEqualTo("0");78}7980@Test81public void testShouldGetClassPropertiesOfAnElement() {82driver.get(pages.xhtmlTestPage);83WebElement heading = driver.findElement(By.cssSelector(".nameA"));84assertThat(heading.getDomProperty("class")).isNull();85assertThat(heading.getDomProperty("className")).isEqualTo("nameA nameBnoise nameC");86assertThat(heading.getDomProperty("classList")).isEqualTo("[nameA, nameBnoise, nameC]");87}8889@Test90void testShouldReturnTheContentsOfATextAreaAsItsValue() {91driver.get(pages.formPage);92WebElement withText = driver.findElement(By.id("withText"));93assertThat(withText.getDomProperty("value")).isEqualTo("Example text");94}9596@Test97void testShouldReturnInnerHtml() {98driver.get(pages.simpleTestPage);99WebElement wrapping = driver.findElement(By.id("wrappingtext"));100assertThat(wrapping.getDomProperty("innerHTML")).contains("<tbody>");101}102103@Test104void testShouldReturnHiddenTextForTextContentProperty() {105driver.get(pages.simpleTestPage);106WebElement element = driver.findElement(By.id("hiddenline"));107assertThat(element.getDomProperty("textContent")).isEqualTo("A hidden line of text");108}109110@Test111void testShouldGetNumericProperty() {112driver.get(pages.formPage);113WebElement element = driver.findElement(By.id("withText"));114assertThat(element.getDomProperty("rows")).isEqualTo("5");115}116117@Test118public void testCanReturnATextApproximationOfTheStyleProperty() {119driver.get(pages.javascriptPage);120WebElement element = driver.findElement(By.id("red-item"));121assertThat(element.getDomProperty("style").toLowerCase()).contains("background-color");122}123124@Test125void testPropertyNamesAreCaseSensitive() {126driver.get(pages.tables);127WebElement th1 = driver.findElement(By.id("th1"));128assertThat(th1.getDomProperty("colspan")).isNull();129assertThat(th1.getDomProperty("COLSPAN")).isNull();130assertThat(th1.getDomProperty("colSpan")).isEqualTo("3");131}132133@Test134void testCanRetrieveTheCurrentValueOfATextFormField_textInput() {135driver.get(pages.formPage);136WebElement element = driver.findElement(By.id("working"));137assertThat(element.getDomProperty("value")).isEmpty();138element.sendKeys("hello world");139shortWait.until(ExpectedConditions.domPropertyToBe(element, "value", "hello world"));140}141142@Test143void testCanRetrieveTheCurrentValueOfATextFormField_emailInput() {144driver.get(pages.formPage);145WebElement element = driver.findElement(By.id("email"));146assertThat(element.getDomProperty("value")).isEmpty();147element.sendKeys("[email protected]");148shortWait.until(ExpectedConditions.domPropertyToBe(element, "value", "[email protected]"));149}150151@Test152void testCanRetrieveTheCurrentValueOfATextFormField_textArea() {153driver.get(pages.formPage);154WebElement element = driver.findElement(By.id("emptyTextArea"));155assertThat(element.getDomProperty("value")).isEmpty();156element.sendKeys("hello world");157shortWait.until(ExpectedConditions.domPropertyToBe(element, "value", "hello world"));158}159160@Test161void testMultiplePropertyShouldBeTrueWhenSelectHasMultipleWithValueAsBlank() {162driver.get(pages.selectPage);163WebElement element = driver.findElement(By.id("selectWithEmptyStringMultiple"));164assertThat(element.getDomProperty("multiple")).isEqualTo("true");165}166167@Test168void testMultiplePropertyShouldBeTrueWhenSelectHasMultipleWithoutAValue() {169driver.get(pages.selectPage);170WebElement element = driver.findElement(By.id("selectWithMultipleWithoutValue"));171assertThat(element.getDomProperty("multiple")).isEqualTo("true");172}173174@Test175void testMultiplePropertyShouldBeTrueWhenSelectHasMultipleWithValueAsSomethingElse() {176driver.get(pages.selectPage);177WebElement element = driver.findElement(By.id("selectWithRandomMultipleValue"));178assertThat(element.getDomProperty("multiple")).isEqualTo("true");179}180181@Test182void testGetValueOfUserDefinedProperty() {183driver.get(pages.userDefinedProperty);184WebElement element = driver.findElement(By.id("d"));185assertThat(element.getDomProperty("dynamicProperty")).isEqualTo("sampleValue");186}187}188189190