您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DateFieldSmokeTest.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2000-2016 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.smoke;
  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.WebElement;
  22. import org.openqa.selenium.support.ui.ExpectedConditions;
  23. import com.vaadin.testbench.elements.InlineDateFieldElement;
  24. import com.vaadin.testbench.elements.PopupDateFieldElement;
  25. import com.vaadin.tests.tb3.MultiBrowserTest;
  26. /**
  27. * @author Vaadin Ltd
  28. *
  29. */
  30. public class DateFieldSmokeTest extends MultiBrowserTest {
  31. @Test
  32. public void dateFieldsSmokeTest() {
  33. openTestURL();
  34. PopupDateFieldElement popup = $(PopupDateFieldElement.class).first();
  35. Assert.assertEquals("12/28/16", popup.getValue());
  36. InlineDateFieldElement inline = $(InlineDateFieldElement.class).first();
  37. Assert.assertEquals(String.valueOf(29),
  38. inline.findElement(By.className(
  39. "v-inline-datefield-calendarpanel-day-selected"))
  40. .getText());
  41. popup.findElement(By.tagName("button")).click();
  42. waitUntil(ExpectedConditions
  43. .visibilityOfElementLocated(By.className("v-datefield-popup")));
  44. selectDay(findElement(By.className("v-datefield-popup")), 14, "v-");
  45. waitUntil(driver -> "1. Popup value is : 2016.12.14"
  46. .equals(getLogRow(0)));
  47. selectDay(inline, 13, "v-inline-");
  48. waitUntil(driver -> "2. Inline value is : 2016.12.13"
  49. .equals(getLogRow(0)));
  50. inline.findElement(By.className("v-button-prevmonth")).click();
  51. WebElement monthTitle = inline.findElement(
  52. By.className("v-inline-datefield-calendarpanel-month"));
  53. Assert.assertEquals("November 2016", monthTitle.getText());
  54. inline.findElement(By.className("v-button-nextyear")).click();
  55. monthTitle = inline.findElement(
  56. By.className("v-inline-datefield-calendarpanel-month"));
  57. Assert.assertEquals("November 2017", monthTitle.getText());
  58. }
  59. private void selectDay(WebElement calendar, int day, String cssPrefix) {
  60. List<WebElement> days = calendar.findElements(
  61. By.className(cssPrefix + "datefield-calendarpanel-day"));
  62. String dayValue = String.valueOf(day);
  63. days.stream()
  64. .filter(dayElement -> dayElement.getText().equals(dayValue))
  65. .findFirst().get().click();
  66. }
  67. }