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 org.htmlunit.WebDriverTestCase;
18  import org.htmlunit.junit.annotation.Alerts;
19  import org.junit.jupiter.api.Test;
20  import org.openqa.selenium.By;
21  import org.openqa.selenium.WebDriver;
22  import org.openqa.selenium.WebElement;
23  
24  /**
25   * Tests for 0.9.9.3 version of <a href="http://sarissa.sourceforge.net">Sarissa</a>.
26   *
27   * @author Ahmed Ashour
28   * @author Marc Guillemot
29   * @author Frank Danek
30   * @author Ronald Brill
31   */
32  public class Sarissa0997Test extends WebDriverTestCase {
33  
34      /**
35       * @throws Exception if an error occurs
36       */
37      @Test
38      @Alerts({"++++++++++++++++++", "+", "+", "+", "+++", "++", "++++++++"})
39      public void sarissa() throws Exception {
40          startWebServer("src/test/resources/libraries/sarissa/0.9.9.7", null, null);
41          final String url = URL_FIRST + "test/testsarissa.html";
42  
43          final WebDriver driver = getWebDriver();
44          driver.get(url);
45  
46          driver.switchTo().alert().dismiss();
47  
48          verify(driver, "SarissaTestCase", getExpectedAlerts()[0]);
49          verify(driver, "XmlHttpRequestTestCase", getExpectedAlerts()[1]);
50          verify(driver, "XMLSerializerTestCase", getExpectedAlerts()[2]);
51          verify(driver, "DOMParserTestCase", getExpectedAlerts()[3]);
52          verify(driver, "XMLDocumentTestCase", getExpectedAlerts()[4]);
53          verify(driver, "XMLElementTestCase", getExpectedAlerts()[5]);
54          verify(driver, "XSLTProcessorTestCase", getExpectedAlerts()[6]);
55      }
56  
57      /**
58       * @param expectedResult empty for successful test or in the form of "+++F+++"
59       *        for failing tests (see the results in a real browser)
60       */
61      private static void verify(final WebDriver driver, final String testName, final String expectedResult) {
62          final WebElement div =
63              driver.findElement(By.xpath("//div[@class='placeholder' and a[@name='#" + testName + "']]"));
64  
65          String text = div.getText();
66          text = text.substring(0, text.indexOf(String.valueOf(expectedResult.length()))).trim();
67          assertEquals(testName + " Results\n" + expectedResult, text);
68      }
69  }