You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ElementExistsTest.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.elements;
  17. import static org.junit.Assert.assertFalse;
  18. import static org.junit.Assert.assertTrue;
  19. import org.junit.Test;
  20. import com.vaadin.testbench.elements.ButtonElement;
  21. import com.vaadin.tests.tb3.MultiBrowserTest;
  22. public class ElementExistsTest extends MultiBrowserTest {
  23. @Test
  24. public void testExistsWithoutUI() {
  25. // Test that an exists query does not throw an exception even when the
  26. // initialization of the UI has not been done (#14808).
  27. boolean buttonExists = $(ButtonElement.class).exists();
  28. assertFalse(
  29. "$(ButtonElement.class).exists() returned true, but there should be no buttons.",
  30. buttonExists);
  31. buttonExists = $(ButtonElement.class).caption("b").exists();
  32. assertFalse(
  33. "$(ButtonElement.class).caption(\"b\").exists() returned true, "
  34. + "but there should be no buttons.",
  35. buttonExists);
  36. }
  37. @Test
  38. public void testExistsWithUI() {
  39. // Test the expected case where the UI has been properly set up.
  40. openTestURL();
  41. boolean buttonExists = $(ButtonElement.class).exists();
  42. assertTrue(
  43. "No button was found, although one should be present in the UI.",
  44. buttonExists);
  45. buttonExists = $(ButtonElement.class).caption("b").exists();
  46. assertTrue(
  47. "No button with caption 'b' was found, although one should be present in the UI.",
  48. buttonExists);
  49. buttonExists = $(ButtonElement.class).caption("Button 2").exists();
  50. assertFalse(
  51. "$(ButtonElement.class).caption(\"Button 2\") returned true, but "
  52. + "there should be no button with that caption.",
  53. buttonExists);
  54. }
  55. }