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.WebClient;
21  import org.htmlunit.WebDriverTestCase;
22  import org.htmlunit.WebServerTestCase;
23  import org.htmlunit.junit.BrowserRunner;
24  import org.htmlunit.junit.annotation.Alerts;
25  import org.htmlunit.junit.annotation.HtmlUnitNYI;
26  import org.junit.AfterClass;
27  import org.junit.BeforeClass;
28  import org.junit.Test;
29  import org.junit.runner.RunWith;
30  import org.openqa.selenium.By;
31  import org.openqa.selenium.WebDriver;
32  import org.openqa.selenium.htmlunit.HtmlUnitDriver;
33  
34  /**
35   * Tests for https://github.com/slab/quill.
36   *
37   * @author Ronald Brill
38   */
39  @RunWith(BrowserRunner.class)
40  public class QuillTest extends WebDriverTestCase {
41  
42      /** The server. */
43      protected static Server SERVER_;
44  
45      /**
46       * @throws Exception if an error occurs
47       */
48      @BeforeClass
49      public static void startSesrver() throws Exception {
50          SERVER_ = WebServerTestCase.createWebServer("src/test/resources/libraries/quill/", null);
51      }
52  
53      /**
54       * @throws Exception if an error occurs
55       */
56      @AfterClass
57      public static void stopServer() throws Exception {
58          if (SERVER_ != null) {
59              SERVER_.stop();
60              SERVER_.destroy();
61              SERVER_ = null;
62          }
63      }
64  
65      /**
66       * @return the resource base URL
67       */
68      protected URL getBaseUrl() {
69          return URL_FIRST;
70      }
71  
72      /**
73       * @throws Exception if the test fails
74       */
75      @Test
76      @Alerts("Bold Italic\\nHello World!\\nSome initial bold text")
77      @HtmlUnitNYI
78      public void basic() throws Exception {
79          // fails because the lib uses classes
80          doTest("QuillTest.html");
81      }
82  
83      private void doTest(final String filename) throws Exception {
84          final WebDriver driver = getWebDriver();
85          if (driver instanceof HtmlUnitDriver) {
86              final WebClient webClient = ((HtmlUnitDriver) driver).getWebClient();
87              webClient.getOptions().setThrowExceptionOnScriptError(false);
88          }
89  
90          driver.get(getBaseUrl() + filename);
91  
92          String content = driver.findElement(By.tagName("body")).getText();
93          content = content.replace("\r", "").replace("\n", "\\n");
94          assertEquals(getExpectedAlerts()[0], content);
95      }
96  }