View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.libraries;
16  
17  import java.net.URL;
18  
19  import org.eclipse.jetty.server.Server;
20  import org.htmlunit.WebDriverTestCase;
21  import org.htmlunit.WebServerTestCase;
22  import org.htmlunit.junit.BrowserRunner;
23  import org.htmlunit.junit.annotation.Alerts;
24  import org.junit.AfterClass;
25  import org.junit.BeforeClass;
26  import org.junit.Test;
27  import org.junit.runner.RunWith;
28  import org.openqa.selenium.WebDriver;
29  
30  /**
31   * Tests for Bird.
32   *
33   * @author Ronald Brill
34   */
35  @RunWith(BrowserRunner.class)
36  public class BirdTest extends WebDriverTestCase {
37  
38      /** The server. */
39      protected static Server SERVER_;
40  
41      /**
42       * @throws Exception if an error occurs
43       */
44      @BeforeClass
45      public static void startSesrver() throws Exception {
46          SERVER_ = WebServerTestCase.createWebServer("src/test/resources/libraries/bird/", null);
47      }
48  
49      /**
50       * @throws Exception if an error occurs
51       */
52      @AfterClass
53      public static void stopServer() throws Exception {
54          if (SERVER_ != null) {
55              SERVER_.stop();
56              SERVER_.destroy();
57              SERVER_ = null;
58          }
59      }
60  
61      /**
62       * @return the resource base URL
63       */
64      protected URL getBaseUrl() {
65          return URL_FIRST;
66      }
67  
68      /**
69       * @throws Exception if the test fails
70       */
71      @Test
72      @Alerts(CHROME = {"IE false", "IE6 undefined", "IE7 undefined", "IE8 undefined", "Mozilla true",
73                        "Firefox false", "Firefox2 undefined", "Firefox3 undefined", "Gecko true",
74                        "Safari true", "KHTML true", "Opera false"},
75              EDGE = {"IE false", "IE6 undefined", "IE7 undefined", "IE8 undefined", "Mozilla true",
76                      "Firefox false", "Firefox2 undefined", "Firefox3 undefined", "Gecko true",
77                      "Safari true", "KHTML true", "Opera false"},
78              FF = {"IE false", "IE6 undefined", "IE7 undefined", "IE8 undefined", "Mozilla true",
79                    "Firefox true", "Firefox2 undefined", "Firefox3 undefined", "Gecko true",
80                    "Safari false", "KHTML false", "Opera false"},
81              FF_ESR = {"IE false", "IE6 undefined", "IE7 undefined", "IE8 undefined", "Mozilla true",
82                        "Firefox true", "Firefox2 undefined", "Firefox3 undefined", "Gecko true",
83                        "Safari false", "KHTML false", "Opera false"})
84      public void browserUtility() throws Exception {
85          doTest("BrowserUtilityTest.html");
86      }
87  
88      private void doTest(final String filename) throws Exception {
89          final WebDriver driver = getWebDriver();
90          driver.get(getBaseUrl() + filename);
91  
92          verifyTextArea2(driver, getExpectedAlerts());
93      }
94  }