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.

TabSheetErrorTooltipTest.java 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.components.tabsheet;
  17. import static org.hamcrest.core.Is.is;
  18. import static org.junit.Assert.assertThat;
  19. import java.io.IOException;
  20. import org.junit.Assert;
  21. import org.junit.Test;
  22. import org.openqa.selenium.By;
  23. import org.openqa.selenium.WebElement;
  24. import org.openqa.selenium.interactions.HasInputDevices;
  25. import org.openqa.selenium.interactions.Mouse;
  26. import org.openqa.selenium.interactions.internal.Coordinates;
  27. import org.openqa.selenium.internal.Locatable;
  28. import com.vaadin.tests.tb3.MultiBrowserTest;
  29. public class TabSheetErrorTooltipTest extends MultiBrowserTest {
  30. @Test
  31. public void checkTooltips() throws IOException {
  32. openTestURL();
  33. assertTabHasNoTooltipNorError(0);
  34. assertTabHasTooltipAndError(1, "", "Error!");
  35. assertTabHasTooltipAndError(2, "This is a tab", "");
  36. assertTabHasTooltipAndError(3,
  37. "This tab has both an error and a description", "Error!");
  38. }
  39. private void assertTabHasTooltipAndError(int index, String tooltip,
  40. String errorMessage) {
  41. showTooltip(index);
  42. assertTooltip(tooltip);
  43. assertErrorMessage(errorMessage);
  44. }
  45. private void assertTabHasNoTooltipNorError(int index) {
  46. showTooltip(index);
  47. WebElement tooltip = getCurrentTooltip();
  48. assertThat(tooltip.getText(), is(""));
  49. WebElement errorMessage = getCurrentErrorMessage();
  50. assertThat(errorMessage.isDisplayed(), is(false));
  51. }
  52. private void showTooltip(int index) {
  53. Coordinates elementCoordinates = ((Locatable) getTab(index))
  54. .getCoordinates();
  55. Mouse mouse = ((HasInputDevices) getDriver()).getMouse();
  56. mouse.mouseMove(elementCoordinates);
  57. }
  58. private WebElement getTab(int index) {
  59. return vaadinElement("/VTabsheet[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild["
  60. + index + "]/domChild[0]");
  61. }
  62. private WebElement getCurrentTooltip() {
  63. return getDriver().findElement(
  64. By.xpath("//div[@class='v-tooltip-text']"));
  65. }
  66. private WebElement getCurrentErrorMessage() {
  67. return getDriver().findElement(
  68. By.xpath("//div[@class='v-errormessage']"));
  69. }
  70. private void assertTooltip(String tooltip) {
  71. Assert.assertEquals(tooltip, getCurrentTooltip().getText());
  72. }
  73. private void assertErrorMessage(String message) {
  74. Assert.assertEquals(message, getCurrentErrorMessage().getText());
  75. }
  76. }