Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

PrivateTB3Configuration.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright 2000-2013 Vaadind 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.io.File;
  18. import java.io.FileInputStream;
  19. import java.io.IOException;
  20. import java.net.InetAddress;
  21. import java.net.NetworkInterface;
  22. import java.net.SocketException;
  23. import java.util.Enumeration;
  24. import java.util.Properties;
  25. import org.openqa.selenium.WebDriver;
  26. import org.openqa.selenium.firefox.FirefoxBinary;
  27. import org.openqa.selenium.firefox.FirefoxDriver;
  28. import com.vaadin.testbench.TestBench;
  29. /**
  30. * Provides values for parameters which depend on where the test is run.
  31. * Parameters should be configured in work/eclipse-run-selected-test.properties.
  32. * A template is available in uitest/.
  33. *
  34. * @author Vaadin Ltd
  35. */
  36. public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
  37. private static final String HOSTNAME_PROPERTY = "com.vaadin.testbench.deployment.hostname";
  38. private static final String PORT_PROPERTY = "com.vaadin.testbench.deployment.port";
  39. private final Properties properties = new Properties();
  40. public PrivateTB3Configuration() {
  41. File file = new File("work", "eclipse-run-selected-test.properties");
  42. if (file.exists()) {
  43. try {
  44. properties.load(new FileInputStream(file));
  45. } catch (IOException e) {
  46. throw new RuntimeException(e);
  47. }
  48. }
  49. }
  50. private String getProperty(String name) {
  51. String property = properties.getProperty(name);
  52. if (property == null) {
  53. property = System.getProperty(name);
  54. }
  55. return property;
  56. }
  57. @Override
  58. protected String getScreenshotDirectory() {
  59. String screenshotDirectory = getProperty("com.vaadin.testbench.screenshot.directory");
  60. if (screenshotDirectory == null) {
  61. throw new RuntimeException(
  62. "No screenshot directory defined. Use -Dcom.vaadin.testbench.screenshot.directory=<path>");
  63. }
  64. return screenshotDirectory;
  65. }
  66. @Override
  67. protected String getHubHostname() {
  68. return "tb3-hub.intra.itmill.com";
  69. }
  70. @Override
  71. protected String getDeploymentHostname() {
  72. String hostName = getProperty(HOSTNAME_PROPERTY);
  73. if (hostName == null || "".equals(hostName)) {
  74. hostName = findAutoHostname();
  75. }
  76. return hostName;
  77. }
  78. @Override
  79. protected String getDeploymentPort() {
  80. String port = getProperty(PORT_PROPERTY);
  81. if (port == null || "".equals(port)) {
  82. port = "8888";
  83. }
  84. return port;
  85. }
  86. /**
  87. * Tries to automatically determine the IP address of the machine the test
  88. * is running on.
  89. *
  90. * @return An IP address of one of the network interfaces in the machine.
  91. * @throws RuntimeException
  92. * if there was an error or no IP was found
  93. */
  94. private String findAutoHostname() {
  95. try {
  96. Enumeration<NetworkInterface> interfaces = NetworkInterface
  97. .getNetworkInterfaces();
  98. while (interfaces.hasMoreElements()) {
  99. NetworkInterface current = interfaces.nextElement();
  100. if (!current.isUp() || current.isLoopback()
  101. || current.isVirtual()) {
  102. continue;
  103. }
  104. Enumeration<InetAddress> addresses = current.getInetAddresses();
  105. while (addresses.hasMoreElements()) {
  106. InetAddress current_addr = addresses.nextElement();
  107. if (current_addr.isLoopbackAddress()) {
  108. continue;
  109. }
  110. String hostAddress = current_addr.getHostAddress();
  111. if (hostAddress.startsWith("192.168.")) {
  112. return hostAddress;
  113. }
  114. }
  115. }
  116. } catch (SocketException e) {
  117. throw new RuntimeException("Could not enumerate ");
  118. }
  119. throw new RuntimeException(
  120. "No compatible (192.168.*) ip address found.");
  121. }
  122. /*
  123. * (non-Javadoc)
  124. *
  125. * @see com.vaadin.tests.tb3.AbstractTB3Test#setupLocalDriver()
  126. */
  127. @Override
  128. protected void setupLocalDriver() {
  129. String firefoxPath = getProperty("firefox.path");
  130. WebDriver driver;
  131. if (firefoxPath != null) {
  132. driver = new FirefoxDriver(
  133. new FirefoxBinary(new File(firefoxPath)), null);
  134. } else {
  135. driver = new FirefoxDriver();
  136. }
  137. setDriver(TestBench.createDriver(driver));
  138. setDesiredCapabilities(BrowserUtil
  139. .firefox(MultiBrowserTest.TESTED_FIREFOX_VERSION));
  140. }
  141. }