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.

CurrentTimeMillisTest.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.vaadin.tests;
  2. import java.util.List;
  3. import org.junit.Assert;
  4. import org.junit.Test;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.Keys;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.interactions.Actions;
  9. import com.vaadin.testbench.parallel.BrowserUtil;
  10. import com.vaadin.tests.tb3.MultiBrowserTest;
  11. /**
  12. * Test to check high resolution time availability in browser (depending on
  13. * browser).
  14. *
  15. * @author Vaadin Ltd
  16. */
  17. public class CurrentTimeMillisTest extends MultiBrowserTest {
  18. @Test
  19. public void testJsonParsing() {
  20. setDebug(true);
  21. openTestURL();
  22. boolean highResTimeSupported = !BrowserUtil
  23. .isIE8(getDesiredCapabilities())
  24. && !BrowserUtil.isIE(getDesiredCapabilities(), 9)
  25. && !BrowserUtil.isPhantomJS(getDesiredCapabilities())
  26. && !BrowserUtil.isSafari(getDesiredCapabilities());
  27. String time = getJsonParsingTime();
  28. Assert.assertNotNull("JSON parsing time is not found", time);
  29. time = time.trim();
  30. if (time.endsWith("ms")) {
  31. time = time.substring(0, time.length() - 2);
  32. }
  33. if (highResTimeSupported) {
  34. if (BrowserUtil.isChrome(getDesiredCapabilities())) {
  35. // Chrome (version 33 at least) sometimes doesn't use high res
  36. // time if number of ms is less then 1
  37. Assert.assertTrue(
  38. "High resolution time is not used in "
  39. + "JSON parsing mesurement. Time=" + time,
  40. time.equals("0") || time.indexOf('.') > 0);
  41. } else {
  42. Assert.assertTrue(
  43. "High resolution time is not used in "
  44. + "JSON parsing mesurement. Time=" + time,
  45. time.indexOf('.') > 0);
  46. }
  47. } else {
  48. Assert.assertFalse("Unexpected dot is detected in browser "
  49. + "that doesn't support high resolution time and "
  50. + "should report time as integer number. Time=" + time,
  51. time.indexOf('.') > 0);
  52. }
  53. }
  54. private String getJsonParsingTime() {
  55. Actions actions = new Actions(getDriver());
  56. actions.sendKeys(Keys.TAB);
  57. actions.sendKeys(Keys.SPACE).perform();
  58. findElement(By.className("v-debugwindow-tab")).click();
  59. List<WebElement> messages = findElements(
  60. By.className("v-debugwindow-message"));
  61. for (WebElement message : messages) {
  62. if (message.getAttribute("innerHTML").startsWith("JSON parsing")) {
  63. String text = message.getAttribute("innerHTML");
  64. int index = text.lastIndexOf(' ');
  65. return text.substring(index);
  66. }
  67. }
  68. return null;
  69. }
  70. }