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.

LocaleChangeTest.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.datefield;
  17. import static org.junit.Assert.assertEquals;
  18. import org.junit.Test;
  19. import org.openqa.selenium.By;
  20. import com.vaadin.testbench.parallel.BrowserUtil;
  21. import com.vaadin.tests.tb3.MultiBrowserTest;
  22. public class LocaleChangeTest extends MultiBrowserTest {
  23. @Test
  24. public void testLocaleChange() {
  25. openTestURL();
  26. // Check the initial value and that popup can be opened.
  27. assertEquals("22/05/14 20:00:00", getDateValue());
  28. toggleDatePopup();
  29. assertPopupOpen(true);
  30. // Close the popup and change the locale.
  31. toggleDatePopupWorkaroundClosePopupIE();
  32. assertPopupOpen(false);
  33. driver.findElement(By.className("v-button")).click(); // Locale change.
  34. // Check that the value has changed and the popup can still be opened
  35. // without problems.
  36. assertEquals("5/22/14 08:00:00 PM", getDateValue());
  37. toggleDatePopup();
  38. assertPopupOpen(true);
  39. }
  40. private void assertPopupOpen(boolean open) {
  41. assertEquals("Date popup was not " + (open ? "open" : "closed") + ".",
  42. (open ? 1 : 0),
  43. driver.findElements(By.className("v-datefield-popup")).size());
  44. }
  45. private void toggleDatePopup() {
  46. driver.findElement(By.className("v-datefield-button")).click();
  47. }
  48. /*
  49. * Work around bug reported in ticket #14086. Delete this method once fixed
  50. * andd use toggleDatePopup() instead.
  51. */
  52. private void toggleDatePopupWorkaroundClosePopupIE() {
  53. if (!BrowserUtil.isIE(getDesiredCapabilities())) {
  54. driver.findElement(By.className("v-datefield-button")).click();
  55. } else {
  56. boolean popupOpen = driver.findElements(
  57. By.className("v-datefield-popup")).size() == 1;
  58. if (popupOpen) {
  59. driver.findElement(
  60. By.className("v-datefield-calendarpanel-day-selected"))
  61. .click();
  62. } else {
  63. driver.findElement(By.className("v-datefield-button")).click();
  64. }
  65. }
  66. }
  67. private String getDateValue() {
  68. return driver.findElement(By.className("v-datefield-textfield"))
  69. .getAttribute("value");
  70. }
  71. }