Path: blob/trunk/py/test/selenium/webdriver/common/page_loading_tests.py
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.1617# import pytest18#19# from selenium.common.exceptions import WebDriverException20# from selenium.webdriver.common.by import By21# from selenium.webdriver.support.wait import WebDriverWait22# from selenium.webdriver.support import expected_conditions as EC232425def test_should_wait_for_document_to_be_loaded(driver, pages):26pages.load("simpleTest.html")27assert driver.title == "Hello WebDriver"282930# Disabled till Java WebServer is used31# def test_should_follow_redirects_sent_in_the_http_response_headers(driver, pages):32# pages.load("redirect.html")33# assert driver.title == "We Arrive Here"343536# Disabled till the Java WebServer is used37# def test_should_follow_meta_redirects(driver, pages):38# pages.load("metaRedirect.html")39# assert driver.title == "We Arrive Here"404142# def test_should_be_able_to_get_afragment_on_the_current_page(driver, pages):43# pages.load("xhtmlTest.html")44# location = driver.current_url45# driver.get(location + "#text")46# driver.find_element(by=By.ID, value="id1")474849# @pytest.mark.xfail_firefox(raises=WebDriverException)50# @pytest.mark.xfail_remote(raises=WebDriverException)51# def test_should_return_when_getting_aurl_that_does_not_resolve(driver):52# # Of course, we're up the creek if this ever does get registered53# driver.get("http://www.thisurldoesnotexist.comx/")545556# @pytest.mark.xfail_firefox(raises=WebDriverException)57# @pytest.mark.xfail_remote(raises=WebDriverException)58# def test_should_return_when_getting_aurl_that_does_not_connect(driver):59# # Here's hoping that there's nothing here. There shouldn't be60# driver.get("http://localhost:3001")6162# def test_should_be_able_to_load_apage_with_framesets_and_wait_until_all_frames_are_loaded() {63# driver.get(pages.framesetPage)64#65# driver.switchTo().frame(0)66# WebElement pageNumber = driver.findElement(By.xpath("#span[@id='pageNumber']"))67# self.assertEqual((pageNumber.getText().trim(), equalTo("1"))68#69# driver.switchTo().defaultContent().switchTo().frame(1)70# pageNumber = driver.findElement(By.xpath("#span[@id='pageNumber']"))71# self.assertEqual((pageNumber.getText().trim(), equalTo("2"))7273# Need to implement this decorator74# @NeedsFreshDriver75# def test_sould_do_nothing_if_there_is_nothing_to_go_back_to() {76# originalTitle = driver.getTitle();77# driver.get(pages.formPage);78# driver.back();79# # We may have returned to the browser's home page80# self.assertEqual(driver.title, anyOf(equalTo(originalTitle), equalTo("We Leave From Here")));818283# @pytest.mark.xfail_safari84# def test_should_be_able_to_navigate_back_in_the_browser_history(driver, pages):85# pages.load("formPage.html")8687# driver.find_element(by=By.ID, value="imageButton").submit()88# WebDriverWait(driver, 3).until(EC.title_is("We Arrive Here"))8990# driver.back()91# assert driver.title == "We Leave From Here"929394# @pytest.mark.xfail_safari95# def test_should_be_able_to_navigate_back_in_the_browser_history_in_presence_of_iframes(driver, pages):96# pages.load("xhtmlTest.html")9798# driver.find_element(by=By.NAME, value="sameWindow").click()99100# assert driver.title == "This page has iframes"101102# driver.back()103# assert driver.title == "XHTML Test Page"104105106# def test_should_be_able_to_navigate_forwards_in_the_browser_history(driver, pages):107# pages.load("formPage.html")108109# driver.find_element(by=By.ID, value="imageButton").submit()110# WebDriverWait(driver, 3).until(EC.title_is("We Arrive Here"))111112# driver.back()113# assert driver.title == "We Leave From Here"114115# driver.forward()116# assert driver.title == "We Arrive Here"117118119# @pytest.mark.xfail_ie120# @pytest.mark.xfail_firefox(run=False)121# @pytest.mark.xfail_remote(run=False)122# @pytest.mark.xfail_chrome(run=False)123# @pytest.mark.xfail_edge(run=False)124# def test_should_not_hang_if_document_open_call_is_never_followed_by_document_close_call(driver, pages):125# pages.load("document_write_in_onload.html")126# driver.find_element(By.XPATH, "//body")127128129# def test_should_be_able_to_refresh_apage(driver, pages):130# pages.load("xhtmlTest.html")131132# driver.refresh()133134# assert driver.title == "XHTML Test Page"135136137