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.BrowserRunner;
19  import org.htmlunit.junit.annotation.Alerts;
20  import org.junit.Before;
21  import org.junit.Test;
22  import org.junit.runner.RunWith;
23  import org.openqa.selenium.By;
24  import org.openqa.selenium.WebDriver;
25  
26  /**
27   * <p>Tests for <a href="https://vuejs.org/">Vue.js</a>.</p>
28   *
29   * @author Ronald Brill
30   */
31  @RunWith(BrowserRunner.class)
32  public class VueTest extends WebDriverTestCase {
33  
34      /**
35       * @throws Exception if an error occurs
36       */
37      @Test
38      @Alerts("Hello World")
39      public void hello() throws Exception {
40          final String url = URL_FIRST + "hello.html";
41  
42          final WebDriver driver = getWebDriver();
43          driver.get(url);
44  
45          assertEquals(getExpectedAlerts()[0], driver.findElement(By.id("app")).getText());
46      }
47  
48      /**
49       * @throws Exception if an error occurs
50       */
51      @Test
52      @Alerts("Hello World")
53      public void helloMin() throws Exception {
54          final String url = URL_FIRST + "hello.min.html";
55  
56          final WebDriver driver = getWebDriver();
57          driver.get(url);
58  
59          assertEquals(getExpectedAlerts()[0], driver.findElement(By.id("app")).getText());
60      }
61  
62      /**
63       * @throws Exception if an error occurs
64       */
65      @Test
66      @Alerts("Hello from HtmlUnit!")
67      public void helloButton() throws Exception {
68          final String url = URL_FIRST + "hello_button.html";
69  
70          final WebDriver driver = getWebDriver();
71          driver.get(url);
72  
73          driver.findElement(By.id("tester")).click();
74          verifyAlerts(driver, getExpectedAlerts());
75      }
76  
77      /**
78       * @throws Exception if an error occurs
79       */
80      @Test
81      @Alerts("Hello from HtmlUnit!")
82      public void helloButtonMin() throws Exception {
83          final String url = URL_FIRST + "hello_button.min.html";
84  
85          final WebDriver driver = getWebDriver();
86          driver.get(url);
87  
88          driver.findElement(By.id("tester")).click();
89          verifyAlerts(driver, getExpectedAlerts());
90      }
91  
92      /**
93       * Performs pre-test initialization.
94       * @throws Exception if an error occurs
95       */
96      @Before
97      public void setUp() throws Exception {
98          startWebServer("src/test/resources/libraries/vue/hello_world", null, null);
99      }
100 }