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 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.Collections;
  19. import java.util.List;
  20. import org.openqa.selenium.remote.DesiredCapabilities;
  21. /**
  22. * Base class for tests which should be run on all supported browsers. The test
  23. * is automatically launched for multiple browsers in parallel by the test
  24. * runner.
  25. *
  26. * Sub classes can, but typically should not, restrict the browsers used by
  27. * implementing a
  28. *
  29. * <pre>
  30. * &#064;Parameters
  31. * public static Collection&lt;DesiredCapabilities&gt; getBrowsersForTest() {
  32. * }
  33. * </pre>
  34. *
  35. * @author Vaadin Ltd
  36. */
  37. public abstract class MultiBrowserTest extends PrivateTB3Configuration {
  38. protected List<DesiredCapabilities> getBrowsersExcludingIE() {
  39. List<DesiredCapabilities> browsers = new ArrayList<DesiredCapabilities>(
  40. getAllBrowsers());
  41. browsers.remove(Browser.IE8.getDesiredCapabilities());
  42. browsers.remove(Browser.IE9.getDesiredCapabilities());
  43. browsers.remove(Browser.IE10.getDesiredCapabilities());
  44. browsers.remove(Browser.IE11.getDesiredCapabilities());
  45. return browsers;
  46. }
  47. protected List<DesiredCapabilities> getBrowsersExcludingPhantomJS() {
  48. List<DesiredCapabilities> browsers = new ArrayList<DesiredCapabilities>(
  49. getAllBrowsers());
  50. browsers.remove(Browser.PHANTOMJS.getDesiredCapabilities());
  51. return browsers;
  52. }
  53. public enum Browser {
  54. FIREFOX(BrowserUtil.firefox(24)), CHROME(BrowserUtil.chrome(33)), SAFARI(
  55. BrowserUtil.safari(7)), IE8(BrowserUtil.ie(8)), IE9(BrowserUtil
  56. .ie(9)), IE10(BrowserUtil.ie(10)), IE11(BrowserUtil.ie(11)), OPERA(
  57. BrowserUtil.opera(17)), PHANTOMJS(BrowserUtil.phantomJS(1));
  58. private DesiredCapabilities desiredCapabilities;
  59. private Browser(DesiredCapabilities desiredCapabilities) {
  60. this.desiredCapabilities = desiredCapabilities;
  61. }
  62. public DesiredCapabilities getDesiredCapabilities() {
  63. return desiredCapabilities;
  64. }
  65. }
  66. static List<DesiredCapabilities> allBrowsers = new ArrayList<DesiredCapabilities>();
  67. static {
  68. allBrowsers.add(Browser.IE8.getDesiredCapabilities());
  69. allBrowsers.add(Browser.IE9.getDesiredCapabilities());
  70. allBrowsers.add(Browser.IE10.getDesiredCapabilities());
  71. allBrowsers.add(Browser.IE11.getDesiredCapabilities());
  72. allBrowsers.add(Browser.FIREFOX.getDesiredCapabilities());
  73. // Uncomment once we have the capability to run on Safari 6
  74. // allBrowsers.add(SAFARI);
  75. allBrowsers.add(Browser.CHROME.getDesiredCapabilities());
  76. allBrowsers.add(Browser.PHANTOMJS.getDesiredCapabilities());
  77. // Re-enable this when it is possible to run on a modern Opera version
  78. // allBrowsers.add(Browser.OPERA.getDesiredCapabilities());
  79. }
  80. /**
  81. * @return all supported browsers which are actively tested
  82. */
  83. public static List<DesiredCapabilities> getAllBrowsers() {
  84. return Collections.unmodifiableList(allBrowsers);
  85. }
  86. @Override
  87. public List<DesiredCapabilities> getBrowsersToTest() {
  88. // Return a copy so sub classes can do
  89. // super.getBrowseresToTest().remove(something)
  90. return new ArrayList<DesiredCapabilities>(getAllBrowsers());
  91. }
  92. }