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 Sarissa0993Test extends WebDriverTestCase {
33  
34      /**
35       * @throws Exception if an error occurs
36       */
37      @Test
38      @Alerts(CHROME = {"+++++++++++FF+++++", "+", "+", "+", "F++", "++", "++++F+++"},
39              EDGE = {"+++++++++++FF+++++", "+", "+", "+", "F++", "++", "++++F+++"},
40              FF = {"+++++++++++F++++++", "+", "+", "+", "F++", "++", "++++F+++"},
41              FF_ESR = {"+++++++++++F++++++", "+", "+", "+", "F++", "++", "++++F+++"})
42      public void sarissa() throws Exception {
43          startWebServer("src/test/resources/libraries/sarissa/0.9.9.3", null, null);
44          final String url = URL_FIRST + "test/testsarissa.html";
45  
46          final WebDriver driver = getWebDriver();
47          driver.get(url);
48  
49          driver.findElement(By.xpath("//button")).click();
50  
51          driver.switchTo().alert().dismiss();
52  
53          verify(driver, "SarissaTestCase", getExpectedAlerts()[0]);
54          verify(driver, "XmlHttpRequestTestCase", getExpectedAlerts()[1]);
55          verify(driver, "XMLSerializerTestCase", getExpectedAlerts()[2]);
56          verify(driver, "DOMParserTestCase", getExpectedAlerts()[3]);
57          verify(driver, "XMLDocumentTestCase", getExpectedAlerts()[4]);
58          verify(driver, "XMLElementTestCase", getExpectedAlerts()[5]);
59          verify(driver, "XSLTProcessorTestCase", getExpectedAlerts()[6]);
60      }
61  
62      /**
63       * @param expectedResult empty for successful test or in the form of "+++F+++"
64       *        for failing tests (see the results in a real browser)
65       */
66      private static void verify(final WebDriver driver, final String testName, final String expectedResult) {
67          final WebElement div =
68              driver.findElement(By.xpath("//div[@class='placeholder' and a[@name='#" + testName + "']]"));
69  
70          String text = div.getText();
71          text = text.substring(0, text.indexOf(String.valueOf(expectedResult.length()))).trim();
72          assertEquals(testName + " Results\n" + expectedResult, text);
73      }
74  }