Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SetFirstVisibleHourOfDayTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.calendar;
  17. import java.util.List;
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.StaleElementReferenceException;
  22. import org.openqa.selenium.WebElement;
  23. import com.vaadin.testbench.parallel.BrowserUtil;
  24. import com.vaadin.tests.tb3.MultiBrowserTest;
  25. /**
  26. * Tests that calendar week and day views are correct when using
  27. * setFirstVisibleHourOfDay()
  28. */
  29. public class SetFirstVisibleHourOfDayTest extends MultiBrowserTest {
  30. @Override
  31. protected boolean requireWindowFocusForIE() {
  32. return true;
  33. }
  34. @Test
  35. public void testDayView() {
  36. openTestURL();
  37. waitForElementPresent(By.className("v-calendar"));
  38. // open day view
  39. clickElement("v-calendar-day-number", "5");
  40. // first of all check if event is present in calendar view
  41. waitForElementPresent(By.className("v-calendar-event-content"));
  42. WebElement event = getDriver().findElement(
  43. By.className("v-calendar-event-content"));
  44. WebElement dateSlot = getDriver().findElement(
  45. By.className("v-datecellslot"));
  46. Assert.assertEquals(
  47. "The height of shown part of calendar event should be equal to 12 datecell slots",
  48. dateSlot.getSize().getHeight() * 12, event.getSize()
  49. .getHeight());
  50. }
  51. @Test
  52. public void testWeekView() {
  53. openTestURL();
  54. waitForElementPresent(By.className("v-calendar"));
  55. // open week view
  56. clickElement("v-calendar-week-number", "36");
  57. // first of all check if event is present in calendar view
  58. waitForElementPresent(By.className("v-calendar-event-content"));
  59. WebElement event = getDriver().findElement(
  60. By.className("v-calendar-event-content"));
  61. WebElement dateSlot = getDriver().findElement(
  62. By.className("v-datecellslot"));
  63. Assert.assertEquals(
  64. "The height of shown part of calendar event should be equal to 12 datecell slots",
  65. dateSlot.getSize().getHeight() * 12, event.getSize()
  66. .getHeight());
  67. }
  68. private void clickElement(String className, String text) {
  69. List<WebElement> elements = findElements(By.className(className));
  70. boolean found = false;
  71. for (WebElement webElement : elements) {
  72. if (webElement.getText().equals(text)) {
  73. webElement.click();
  74. if (BrowserUtil.isIE8(getDesiredCapabilities())) {
  75. try {
  76. // sometimes the element only gets focus from click and
  77. // we need to click the text, which is in the right edge
  78. // of the element
  79. testBenchElement(webElement).click(
  80. webElement.getSize().getWidth() - 5, 9);
  81. } catch (StaleElementReferenceException e) {
  82. // the first click succeeded after all
  83. }
  84. }
  85. found = true;
  86. break;
  87. }
  88. }
  89. if (!found) {
  90. Assert.fail("Element " + className + " with text " + text
  91. + " not found.");
  92. }
  93. }
  94. }