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.

MultiBrowserTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.tb3;
  17. import java.util.ArrayList;
  18. import java.util.Calendar;
  19. import java.util.List;
  20. import org.junit.Rule;
  21. import org.junit.rules.TestName;
  22. import org.openqa.selenium.ie.InternetExplorerDriver;
  23. import org.openqa.selenium.remote.DesiredCapabilities;
  24. import com.vaadin.testbench.parallel.Browser;
  25. import com.vaadin.testbench.parallel.BrowserUtil;
  26. /**
  27. * Base class for tests which should be run on all supported browsers. The test
  28. * is automatically launched for multiple browsers in parallel by the test
  29. * runner.
  30. *
  31. * Sub classes can, but typically should not, restrict the browsers used by
  32. * implementing a
  33. *
  34. * <pre>
  35. * &#064;Parameters
  36. * public static Collection&lt;DesiredCapabilities&gt; getBrowsersForTest() {
  37. * }
  38. * </pre>
  39. *
  40. * @author Vaadin Ltd
  41. */
  42. public abstract class MultiBrowserTest extends PrivateTB3Configuration {
  43. @Rule
  44. public TestName testName = new TestName();
  45. protected List<DesiredCapabilities> getBrowsersSupportingWebSocket() {
  46. // No WebSocket support in IE8-9 and PhantomJS
  47. return getBrowserCapabilities(Browser.IE10, Browser.IE11,
  48. Browser.FIREFOX, Browser.CHROME);
  49. }
  50. protected List<DesiredCapabilities> getBrowsersExcludingPhantomJS() {
  51. return getBrowserCapabilities(Browser.IE8, Browser.IE9, Browser.IE10,
  52. Browser.IE11, Browser.CHROME, Browser.FIREFOX);
  53. }
  54. protected List<DesiredCapabilities> getBrowsersExcludingIE() {
  55. return getBrowserCapabilities(Browser.FIREFOX, Browser.CHROME,
  56. Browser.PHANTOMJS);
  57. }
  58. protected List<DesiredCapabilities> getBrowsersExcludingIE8() {
  59. return getBrowserCapabilities(Browser.IE9, Browser.IE10, Browser.IE11,
  60. Browser.FIREFOX, Browser.CHROME, Browser.PHANTOMJS);
  61. }
  62. protected List<DesiredCapabilities> getBrowsersSupportingShiftClick() {
  63. return getBrowserCapabilities(Browser.IE8, Browser.IE9, Browser.IE10,
  64. Browser.IE11, Browser.CHROME);
  65. }
  66. protected List<DesiredCapabilities> getIEBrowsersOnly() {
  67. return getBrowserCapabilities(Browser.IE8, Browser.IE9, Browser.IE10,
  68. Browser.IE11);
  69. }
  70. protected List<DesiredCapabilities> getBrowsersSupportingContextMenu() {
  71. // context menu doesn't work in phantom JS and works weirdly with IE8
  72. // and selenium.
  73. return getBrowserCapabilities(Browser.IE9, Browser.IE10, Browser.IE11,
  74. Browser.FIREFOX, Browser.CHROME);
  75. }
  76. @Override
  77. public void setDesiredCapabilities(DesiredCapabilities desiredCapabilities) {
  78. super.setDesiredCapabilities(desiredCapabilities);
  79. if (BrowserUtil.isIE(desiredCapabilities)) {
  80. if (requireWindowFocusForIE()) {
  81. desiredCapabilities.setCapability(
  82. InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);
  83. }
  84. if (!usePersistentHoverForIE()) {
  85. desiredCapabilities.setCapability(
  86. InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING,
  87. false);
  88. }
  89. }
  90. desiredCapabilities.setCapability("project", "Vaadin Framework");
  91. desiredCapabilities.setCapability("build", String.format("%s / %s",
  92. getDeploymentHostname(), Calendar.getInstance().getTime()));
  93. desiredCapabilities.setCapability(
  94. "name",
  95. String.format("%s.%s", getClass().getCanonicalName(),
  96. testName.getMethodName()));
  97. }
  98. @Override
  99. public List<DesiredCapabilities> getBrowsersToTest() {
  100. // Uncomment Safari and Opera if those become tested browsers again.
  101. return getBrowserCapabilities(Browser.IE8, Browser.IE9, Browser.IE10,
  102. Browser.IE11, Browser.FIREFOX, Browser.CHROME,
  103. Browser.PHANTOMJS /* , Browser.SAFARI, Browser.OPERA */);
  104. }
  105. protected List<DesiredCapabilities> getBrowserCapabilities(
  106. Browser... browsers) {
  107. List<DesiredCapabilities> capabilities = new ArrayList<DesiredCapabilities>();
  108. for (Browser browser : browsers) {
  109. capabilities.add(browser.getDesiredCapabilities());
  110. }
  111. return capabilities;
  112. }
  113. }