Path: blob/trunk/java/test/org/openqa/selenium/ClickTest.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.openqa.selenium.WaitingConditions.newWindowIsOpened;21import static org.openqa.selenium.WaitingConditions.pageSourceToContain;22import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;23import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;24import static org.openqa.selenium.testing.drivers.Browser.IE;25import static org.openqa.selenium.testing.drivers.Browser.SAFARI;2627import java.util.Set;28import org.junit.jupiter.api.BeforeEach;29import org.junit.jupiter.api.Test;30import org.openqa.selenium.testing.Ignore;31import org.openqa.selenium.testing.JupiterTestBase;32import org.openqa.selenium.testing.NoDriverAfterTest;33import org.openqa.selenium.testing.NotYetImplemented;34import org.openqa.selenium.testing.SwitchToTopAfterTest;3536class ClickTest extends JupiterTestBase {3738@BeforeEach39public void setUp() {40driver.get(pages.clicksPage);41}4243@Test44void testCanClickOnALinkAndFollowIt() {45driver.findElement(By.id("normal")).click();4647wait.until(titleIs("XHTML Test Page"));48}4950@Test51void testCanClickOnALinkThatOverflowsAndFollowIt() {52driver.findElement(By.id("overflowLink")).click();5354wait.until(titleIs("XHTML Test Page"));55}5657@Test58void testCanClickOnAnAnchorAndNotReloadThePage() {59((JavascriptExecutor) driver).executeScript("document.latch = true");6061driver.findElement(By.id("anchor")).click();6263Boolean samePage =64(Boolean) ((JavascriptExecutor) driver).executeScript("return document.latch");6566assertThat(samePage).as("Latch was reset").isTrue();67}6869@SwitchToTopAfterTest70@Test71void testCanClickOnALinkThatUpdatesAnotherFrame() {72driver.switchTo().frame("source");7374driver.findElement(By.id("otherframe")).click();75driver.switchTo().defaultContent().switchTo().frame("target");7677wait.until(pageSourceToContain("Hello WebDriver"));78}7980@SwitchToTopAfterTest81@Test82void testElementsFoundByJsCanLoadUpdatesInAnotherFrame() {83driver.switchTo().frame("source");8485WebElement toClick =86(WebElement)87((JavascriptExecutor) driver)88.executeScript("return document.getElementById('otherframe');");89toClick.click();90driver.switchTo().defaultContent().switchTo().frame("target");9192wait.until(pageSourceToContain("Hello WebDriver"));93}9495@SwitchToTopAfterTest96@Test97void testJsLocatedElementsCanUpdateFramesIfFoundSomehowElse() {98driver.switchTo().frame("source");99100// Prime the cache of elements101driver.findElement(By.id("otherframe"));102103// This _should_ return the same element104WebElement toClick =105(WebElement)106((JavascriptExecutor) driver)107.executeScript("return document.getElementById('otherframe');");108toClick.click();109driver.switchTo().defaultContent().switchTo().frame("target");110111wait.until(pageSourceToContain("Hello WebDriver"));112}113114@Test115void testCanClickOnAnElementWithTopSetToANegativeNumber() {116String page = appServer.whereIs("styledPage.html");117driver.get(page);118WebElement searchBox = driver.findElement(By.name("searchBox"));119searchBox.sendKeys("Cheese");120driver.findElement(By.name("btn")).click();121122String log = driver.findElement(By.id("log")).getText();123assertThat(log).isEqualTo("click");124}125126@Test127@NotYetImplemented(SAFARI)128public void testShouldSetRelatedTargetForMouseOver() {129driver.get(pages.javascriptPage);130131driver.findElement(By.id("movable")).click();132133String log = driver.findElement(By.id("result")).getText();134135assertThat(log).isEqualTo("parent matches? true");136}137138@Test139@NotYetImplemented(SAFARI)140public void testShouldClickOnFirstBoundingClientRectWithNonZeroSize() {141driver.findElement(By.id("twoClientRects")).click();142wait.until(titleIs("XHTML Test Page"));143}144145@NoDriverAfterTest(failedOnly = true)146@Test147void testShouldOnlyFollowHrefOnce() {148driver.get(pages.clicksPage);149String current = driver.getWindowHandle();150Set<String> currentWindowHandles = driver.getWindowHandles();151152try {153driver.findElement(By.id("new-window")).click();154String newWindowHandle = wait.until(newWindowIsOpened(currentWindowHandles));155driver.switchTo().window(newWindowHandle);156driver.close();157} finally {158driver.switchTo().window(current);159}160}161162@Test163@NotYetImplemented(SAFARI)164public void testClickingLabelShouldSetCheckbox() {165driver.get(pages.formPage);166167driver.findElement(By.id("label-for-checkbox-with-label")).click();168169assertThat(driver.findElement(By.id("checkbox-with-label")).isSelected()).isTrue();170}171172@Test173@NotYetImplemented(SAFARI)174public void testCanClickOnALinkWithEnclosedImage() {175driver.findElement(By.id("link-with-enclosed-image")).click();176177wait.until(titleIs("XHTML Test Page"));178}179180@Test181void testCanClickOnAnImageEnclosedInALink() {182driver.findElement(By.id("link-with-enclosed-image")).findElement(By.tagName("img")).click();183184wait.until(titleIs("XHTML Test Page"));185}186187@Test188@NotYetImplemented(SAFARI)189public void testCanClickOnALinkThatContainsTextWrappedInASpan() {190driver.findElement(By.id("link-with-enclosed-span")).click();191192wait.until(titleIs("XHTML Test Page"));193}194195@Test196@Ignore(197value = FIREFOX,198reason = "block can't be scrolled into view",199issue = "https://github.com/mozilla/geckodriver/issues/653")200@NotYetImplemented(SAFARI)201public void testCanClickOnALinkThatContainsEmbeddedBlockElements() {202driver.findElement(By.id("embeddedBlock")).click();203wait.until(titleIs("XHTML Test Page"));204}205206@Test207void testCanClickOnAnElementEnclosedInALink() {208driver.findElement(By.id("link-with-enclosed-span")).findElement(By.tagName("span")).click();209210wait.until(titleIs("XHTML Test Page"));211}212213@Test214void testShouldBeAbleToClickOnAnElementInTheViewport() {215String url = appServer.whereIs("click_out_of_bounds.html");216217driver.get(url);218WebElement button = driver.findElement(By.id("button"));219button.click();220}221222@Test223@NotYetImplemented(SAFARI)224public void testClicksASurroundingStrongTag() {225driver.get(appServer.whereIs("ClickTest_testClicksASurroundingStrongTag.html"));226driver.findElement(By.tagName("a")).click();227wait.until(titleIs("XHTML Test Page"));228}229230@Test231@Ignore(IE)232@Ignore(233value = FIREFOX,234reason = "imagemap can't be scrolled into view",235issue = "https://bugzilla.mozilla.org/show_bug.cgi?id=1502636")236@NotYetImplemented(SAFARI)237public void testCanClickAnImageMapArea() {238driver.get(appServer.whereIs("click_tests/google_map.html"));239driver.findElement(By.id("rectG")).click();240wait.until(titleIs("Target Page 1"));241242driver.get(appServer.whereIs("click_tests/google_map.html"));243driver.findElement(By.id("circleO")).click();244wait.until(titleIs("Target Page 2"));245246driver.get(appServer.whereIs("click_tests/google_map.html"));247driver.findElement(By.id("polyLE")).click();248wait.until(titleIs("Target Page 3"));249}250251@Test252@Ignore(253value = FIREFOX,254reason = "Large element can't be scrolled into view",255issue = "https://bugzilla.mozilla.org/show_bug.cgi?id=1422272")256@NotYetImplemented(SAFARI)257public void testShouldBeAbleToClickOnAnElementGreaterThanTwoViewports() {258String url = appServer.whereIs("click_too_big.html");259driver.get(url);260261WebElement element = driver.findElement(By.id("click"));262263element.click();264265wait.until(titleIs("clicks"));266}267268@SwitchToTopAfterTest269@Test270@NotYetImplemented(SAFARI)271@Ignore(272value = FIREFOX,273reason =274"Clicking on element doesn't work if element is in iframe outside of viewport in Beta",275issue = "https://bugzilla.mozilla.org/show_bug.cgi?id=1937115")276public void testShouldBeAbleToClickOnAnElementInFrameGreaterThanTwoViewports() {277String url = appServer.whereIs("click_too_big_in_frame.html");278driver.get(url);279280WebElement frame = driver.findElement(By.id("iframe1"));281driver.switchTo().frame(frame);282283WebElement element = driver.findElement(By.id("click"));284element.click();285286wait.until(titleIs("clicks"));287}288289@Test290void testShouldBeAbleToClickOnRTLLanguageLink() {291String url = appServer.whereIs("click_rtl.html");292driver.get(url);293294WebElement element = driver.findElement(By.id("ar_link"));295element.click();296297wait.until(titleIs("clicks"));298}299300@Test301void testShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooter() {302String url = appServer.whereIs("fixedFooterNoScroll.html");303driver.get(url);304305WebElement element = driver.findElement(By.id("link"));306element.click();307308wait.until(titleIs("XHTML Test Page"));309}310311@Test312void testShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooterInQuirksMode() {313String url = appServer.whereIs("fixedFooterNoScrollQuirksMode.html");314driver.get(url);315316WebElement element = driver.findElement(By.id("link"));317element.click();318319wait.until(titleIs("XHTML Test Page"));320}321322@Test323void testShouldBeAbleToClickOnLinksWithNoHrefAttribute() {324driver.get(pages.javascriptPage);325326WebElement element = driver.findElement(By.linkText("No href"));327element.click();328329wait.until(titleIs("Changed"));330}331332@Test333void testShouldBeAbleToClickOnALinkThatWrapsToTheNextLine() {334driver.get(appServer.whereIs("click_tests/link_that_wraps.html"));335336driver.findElement(By.id("link")).click();337338wait.until(titleIs("Submitted Successfully!"));339}340341@Test342void testShouldBeAbleToClickOnASpanThatWrapsToTheNextLine() {343driver.get(appServer.whereIs("click_tests/span_that_wraps.html"));344345driver.findElement(By.id("span")).click();346347wait.until(titleIs("Submitted Successfully!"));348}349350@Test351void clickingOnADisabledElementIsANoOp() {352driver.get(appServer.whereIs("click_tests/disabled_element.html"));353354driver.findElement(By.name("disabled")).click(); // Should not throw355}356}357358359