Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix concurrency bugs in Selenium Webbit example.

Also switched from Chrome to Firefox, since it doesn't require the installation
of the chromedriver command line tool.
  • Loading branch information...
commit 15ade0bb5e2107ccdb34e49b4ca2d04d36a1afc8 1 parent 3739de8
@aslakhellesoy aslakhellesoy authored
View
1  History.md
@@ -1,5 +1,6 @@
## [1-1-6-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.5...master)
+* [Examples] Fixed concurrency bugs in Webbit Selenium example (Aslak Hellesøy)
* [Core] Fixed thread leak in timeout implementation. ([#639](https://github.com/cucumber/cucumber-jvm/issues/639), [#640](https://github.com/cucumber/cucumber-jvm/pull/640), Nikolay Volnov)
* [TestNG] Allow TestNG Cucumber runner to use composition instead of inheritance. ([#622](https://github.com/cucumber/cucumber-jvm/pull/622) Marty Kube)
* [Core] New Snippet text. ([#618](https://github.com/cucumber/cucumber-jvm/issues/618) Jeff Nyman, Matt Wynne, Aslak Hellesøy)
View
2  examples/java-webbit-websockets-selenium/pom.xml
@@ -56,7 +56,7 @@
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
- <artifactId>selenium-chrome-driver</artifactId>
+ <artifactId>selenium-firefox-driver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
View
11 ...s/java-webbit-websockets-selenium/src/main/java/cucumber/examples/java/websockets/TemperatureServer.java
@@ -9,6 +9,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
public class TemperatureServer {
@@ -39,15 +40,15 @@ private double roundOneDecimal(double n) {
return (double) Math.round(n * 10) / 10;
}
- public void start() throws IOException {
- webServer.start();
+ public void start() throws IOException, ExecutionException, InterruptedException {
+ webServer.start().get();
}
- public void stop() throws IOException {
- webServer.stop();
+ public void stop() throws IOException, ExecutionException, InterruptedException {
+ webServer.stop().get();
}
- public static void main(String[] args) throws IOException {
+ public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
new TemperatureServer(9988).start();
}
}
View
4 examples/java-webbit-websockets-selenium/src/main/resources/web/index.html
@@ -7,9 +7,9 @@
</head>
<body>
<label for="celcius">Celcius</label>
-<input type="text" id="celcius">
+<input type="text" id="celcius" disabled>
<label for="fahrenheit">Fahrenheit</label>
-<input type="text" id="fahrenheit">
+<input type="text" id="fahrenheit" disabled>
</body>
</html>
View
39 examples/java-webbit-websockets-selenium/src/main/resources/web/temperature.js
@@ -1,19 +1,26 @@
window.onload = function () {
- var ws = new WebSocket('ws://' + document.location.host + '/temperature');
- ws.onmessage = function (e) {
- var temp = e.data.split(':');
- document.getElementById(temp[0]).value = temp[1];
- };
+ var ws = new WebSocket('ws://' + document.location.host + '/temperature');
+
+ ws.onopen = function () {
+ // Only enable the input fields after we have established a WebSocket connection.
+ document.getElementById("celcius").disabled = false;
+ document.getElementById("fahrenheit").disabled = false;
+ };
- function setupEvent(unit) {
- var c = document.getElementById(unit);
- c.onkeyup = function (e) {
- setTimeout(function () {
- ws.send(unit + ':' + e.target.value);
- }, 0);
- };
- }
+ ws.onmessage = function (e) {
+ var temp = e.data.split(':');
+ document.getElementById(temp[0]).value = temp[1];
+ };
+
+ function setupEvent(unit) {
+ var c = document.getElementById(unit);
+ c.onkeyup = function (e) {
+ setTimeout(function () {
+ ws.send(unit + ':' + e.target.value);
+ }, 0);
+ };
+ }
- setupEvent('celcius');
- setupEvent('fahrenheit');
-};
+ setupEvent('celcius');
+ setupEvent('fahrenheit');
+};
View
10 .../java-webbit-websockets-selenium/src/test/java/cucumber/examples/java/websockets/NavigationStepdefs.java
@@ -1,7 +1,10 @@
package cucumber.examples.java.websockets;
import cucumber.api.java.en.Given;
+import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
public class NavigationStepdefs {
private final WebDriver webDriver;
@@ -11,7 +14,12 @@ public NavigationStepdefs(SharedDriver webDriver) {
}
@Given("^I am on the front page$")
- public void i_am_on_the_front_page() {
+ public void i_am_on_the_front_page() throws InterruptedException {
webDriver.get("http://localhost:" + ServerHooks.PORT);
+
+ // The input fields won't be enabled until the WebSocket has established
+ // a connection. Wait for this to happen.
+ WebDriverWait wait = new WebDriverWait(webDriver, 1);
+ wait.until(ExpectedConditions.elementToBeClickable(By.id("celcius")));
}
}
View
5 examples/java-webbit-websockets-selenium/src/test/java/cucumber/examples/java/websockets/ServerHooks.java
@@ -4,6 +4,7 @@
import cucumber.api.java.Before;
import java.io.IOException;
+import java.util.concurrent.ExecutionException;
public class ServerHooks {
public static final int PORT = 8887;
@@ -11,13 +12,13 @@
private TemperatureServer temperatureServer;
@Before
- public void startServer() throws IOException {
+ public void startServer() throws IOException, ExecutionException, InterruptedException {
temperatureServer = new TemperatureServer(PORT);
temperatureServer.start();
}
@After
- public void stopServer() throws IOException {
+ public void stopServer() throws IOException, ExecutionException, InterruptedException {
temperatureServer.stop();
}
}
View
4 examples/java-webbit-websockets-selenium/src/test/java/cucumber/examples/java/websockets/SharedDriver.java
@@ -6,7 +6,7 @@
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
-import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
/**
@@ -30,7 +30,7 @@
* </p>
*/
public class SharedDriver extends EventFiringWebDriver {
- private static final WebDriver REAL_DRIVER = new ChromeDriver();
+ private static final WebDriver REAL_DRIVER = new FirefoxDriver();
private static final Thread CLOSE_THREAD = new Thread() {
@Override
public void run() {
View
5 pom.xml
@@ -38,7 +38,7 @@
<junit.version>4.11</junit.version>
<jython.version>2.7-b1</jython.version>
<mockito.version>1.9.5</mockito.version>
- <selenium.version>2.35.0</selenium.version>
+ <selenium.version>2.38.0</selenium.version>
<webbit.version>0.4.15</webbit.version>
<webbit-rest.version>0.3.0</webbit-rest.version>
<jruby.version>1.7.4</jruby.version>
@@ -328,7 +328,7 @@
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
- <artifactId>selenium-chrome-driver</artifactId>
+ <artifactId>selenium-firefox-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
@@ -340,7 +340,6 @@
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.webbitserver</groupId>
Please sign in to comment.
Something went wrong with that request. Please try again.