Path: blob/trunk/java/test/org/openqa/selenium/PageLoadingTest.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.assertThatCode;21import static org.assertj.core.api.Assertions.assertThatExceptionOfType;22import static org.openqa.selenium.WaitingConditions.elementTextToContain;23import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;24import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;25import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;26import static org.openqa.selenium.testing.drivers.Browser.CHROME;27import static org.openqa.selenium.testing.drivers.Browser.EDGE;28import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;29import static org.openqa.selenium.testing.drivers.Browser.IE;30import static org.openqa.selenium.testing.drivers.Browser.SAFARI;3132import java.time.Duration;33import org.junit.jupiter.api.Test;34import org.openqa.selenium.remote.CapabilityType;35import org.openqa.selenium.testing.Ignore;36import org.openqa.selenium.testing.JupiterTestBase;37import org.openqa.selenium.testing.NeedsFreshDriver;38import org.openqa.selenium.testing.NeedsSecureServer;39import org.openqa.selenium.testing.NoDriverAfterTest;40import org.openqa.selenium.testing.NotYetImplemented;41import org.openqa.selenium.testing.SwitchToTopAfterTest;4243@NeedsSecureServer44class PageLoadingTest extends JupiterTestBase {4546@Test47@NeedsFreshDriver48public void shouldSetAndGetPageLoadTimeout() {49Duration timeout = driver.manage().timeouts().getPageLoadTimeout();50assertThat(timeout).hasMillis(300000);51driver.manage().timeouts().pageLoadTimeout(Duration.ofMillis(3000));52Duration timeout2 = driver.manage().timeouts().getPageLoadTimeout();53assertThat(timeout2).hasMillis(3000);54}5556@Test57void testShouldFollowRedirectsSentInTheHttpResponseHeaders() {58driver.get(pages.redirectPage);59assertThat(driver.getTitle()).isEqualTo("We Arrive Here");60}6162@Test63void testShouldFollowMetaRedirects() {64driver.get(pages.metaRedirectPage);65wait.until(titleIs("We Arrive Here"));66}6768@Test69void testShouldBeAbleToGetAFragmentOnTheCurrentPage() {70driver.get(pages.xhtmlTestPage);71driver.get(pages.xhtmlTestPage + "#text");72wait.until(presenceOfElementLocated(By.id("id1")));73}7475@Test76@NotYetImplemented(CHROME)77@NotYetImplemented(EDGE)78@NotYetImplemented(FIREFOX)79public void testShouldReturnWhenGettingAUrlThatDoesNotResolve() {80assertThatCode(() -> driver.get("http://www.thisurldoesnotexist.comx/"))81.doesNotThrowAnyException();82}8384@Test85void testShouldThrowIfUrlIsMalformed() {86assertThatExceptionOfType(WebDriverException.class)87.isThrownBy(() -> driver.get("www.test.com"));88}8990@Test91@NotYetImplemented(value = SAFARI)92public void testShouldThrowIfUrlIsMalformedInPortPart() {93assertThatExceptionOfType(WebDriverException.class)94.isThrownBy(() -> driver.get("http://localhost:3001bla"));95}9697@Test98@NotYetImplemented(CHROME)99@NotYetImplemented(EDGE)100@NotYetImplemented(FIREFOX)101public void testShouldReturnWhenGettingAUrlThatDoesNotConnect() {102// Here's hoping that there's nothing here. There shouldn't be103driver.get("http://localhost:3001");104}105106@Test107void testShouldReturnURLOnNotExistedPage() {108String url = appServer.whereIs("not_existed_page.html");109driver.get(url);110assertThat(driver.getCurrentUrl()).isEqualTo(url);111}112113@SwitchToTopAfterTest114@Test115@NotYetImplemented(SAFARI)116public void testShouldBeAbleToLoadAPageWithFramesetsAndWaitUntilAllFramesAreLoaded() {117driver.get(pages.framesetPage);118119driver.switchTo().frame(0);120WebElement pageNumber = driver.findElement(By.xpath("//span[@id='pageNumber']"));121assertThat(pageNumber.getText().trim()).isEqualTo("1");122123driver.switchTo().defaultContent().switchTo().frame(1);124pageNumber = driver.findElement(By.xpath("//span[@id='pageNumber']"));125assertThat(pageNumber.getText().trim()).isEqualTo("2");126}127128@Test129@Ignore(IE)130@NotYetImplemented(value = SAFARI, reason = "does not support insecure SSL")131public void testShouldBeAbleToAccessPagesWithAnInsecureSslCertificate() {132createNewDriver(new ImmutableCapabilities(CapabilityType.ACCEPT_INSECURE_CERTS, Boolean.TRUE));133driver.get(appServer.whereIsSecure("simpleTest.html"));134135shortWait.until(titleIs("Hello WebDriver"));136}137138@Test139void testShouldBeAbleToRefreshAPage() {140driver.get(pages.xhtmlTestPage);141142driver.navigate().refresh();143144assertThat(driver.getTitle()).isEqualTo("XHTML Test Page");145}146147/**148* See https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/208149*150* <p>This test often causes the subsequent test to fail, in Firefox, on Linux, so we need a new151* driver after it. See152* https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/2282153*/154@NoDriverAfterTest155@Test156@Ignore(IE)157@Ignore(FIREFOX)158public void testShouldNotHangIfDocumentOpenCallIsNeverFollowedByDocumentCloseCall() {159driver.get(pages.documentWrite);160161// If this command succeeds, then all is well.162WebElement body = wait.until(visibilityOfElementLocated(By.tagName("body")));163wait.until(elementTextToContain(body, "world"));164}165}166167168