Path: blob/trunk/java/test/org/openqa/selenium/MiscTest.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.testing.drivers.Browser.ALL;21import static org.openqa.selenium.testing.drivers.Browser.CHROME;22import static org.openqa.selenium.testing.drivers.Browser.EDGE;23import static org.openqa.selenium.testing.drivers.Browser.IE;24import static org.openqa.selenium.testing.drivers.Browser.SAFARI;2526import org.junit.jupiter.api.Test;27import org.openqa.selenium.testing.Ignore;28import org.openqa.selenium.testing.JupiterTestBase;29import org.openqa.selenium.testing.NotYetImplemented;3031class MiscTest extends JupiterTestBase {3233@Test34void testShouldReturnTitleOfPageIfSet() {35driver.get(pages.xhtmlTestPage);36assertThat(driver.getTitle()).isEqualTo(("XHTML Test Page"));3738driver.get(pages.simpleTestPage);39assertThat(driver.getTitle()).isEqualTo("Hello WebDriver");40}4142@Test43void testShouldReportTheCurrentUrlCorrectly() {44driver.get(pages.simpleTestPage);45assertThat(driver.getCurrentUrl()).isEqualToIgnoringCase(pages.simpleTestPage);4647driver.get(pages.javascriptPage);48assertThat(driver.getCurrentUrl()).isEqualToIgnoringCase(pages.javascriptPage);49}5051@Test52void shouldReturnTagName() {53driver.get(pages.formPage);54WebElement selectBox = driver.findElement(By.id("cheese"));55assertThat(selectBox.getTagName()).isEqualToIgnoringCase("input");56}5758@Test59void testShouldReturnTheSourceOfAPage() {60driver.get(pages.simpleTestPage);6162String source = driver.getPageSource().toLowerCase();6364assertThat(source)65.contains(66"<html",67"</html",68"an inline element",69"<p id=",70"lotsofspaces",71"with document.write and with document.write again");72}7374@Test75@Ignore(value = CHROME, reason = "returns XML content formatted for display as HTML document")76@Ignore(value = EDGE, reason = "returns XML content formatted for display as HTML document")77@NotYetImplemented(78value = SAFARI,79reason = "returns XML content formatted for display as HTML document")80@Ignore(IE)81public void testShouldBeAbleToGetTheSourceOfAnXmlDocument() {82driver.get(pages.simpleXmlDocument);83String source = driver.getPageSource().toLowerCase();84assertThat(source).isEqualToIgnoringWhitespace("<xml><foo><bar>baz</bar></foo></xml>");85}8687@Test88@Ignore(value = ALL, reason = "issue 2282")89public void testStimulatesStrangeOnloadInteractionInFirefox() {90driver.get(pages.documentWrite);9192// If this command succeeds, then all is well.93driver.findElement(By.xpath("//body"));9495driver.get(pages.simpleTestPage);96driver.findElement(By.id("links"));97}9899@Test100void testClickingShouldNotTrampleWOrHInGlobalScope() {101driver.get(appServer.whereIs("globalscope.html"));102String[] vars = new String[] {"w", "h"};103for (String var : vars) {104assertThat(getGlobalVar(driver, var)).isEqualTo(var);105}106driver.findElement(By.id("toclick")).click();107for (String var : vars) {108assertThat(getGlobalVar(driver, var)).isEqualTo(var);109}110}111112private String getGlobalVar(WebDriver driver, String var) {113Object val = ((JavascriptExecutor) driver).executeScript("return window." + var + ";");114return val == null ? "null" : val.toString();115}116}117118119