Skip to content

Commit 63bba6c

Browse files
committed
[Examples] Fix java webbit websockets selenium
Updated dependencies and added spiffy new webdriver factory that in combination with the driver-binary-downloader-maven-plugin just works. Related issues: - #1033 This fixes #1033
1 parent c70c0ec commit 63bba6c

File tree

26 files changed

+290
-136
lines changed

26 files changed

+290
-136
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cache:
1919
matrix:
2020
include:
2121
- jdk: openjdk7
22-
script: mvn -q install -P examples
22+
script: mvn -q install
2323
- jdk: oraclejdk7
2424
script: mvn -q install
2525
after_success: mvn -q deploy --settings .travis-settings.xml -Dno.gem.deploy=true -DskipTests=true -Dmaven.javadoc.skip=true

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ Now release everything (replace X.Y.Z below with the next release number):
128128

129129
```
130130
mvn release:clean
131-
mvn --batch-mode -P release-sign-artifacts release:prepare -DautoVersionSubmodules=true -DdevelopmentVersion=X.Y.Z-SNAPSHOT
132-
mvn -P release-sign-artifacts release:perform
131+
mvn --batch-mode release:prepare -DautoVersionSubmodules=true -DdevelopmentVersion=X.Y.Z-SNAPSHOT
132+
mvn release:perform
133133
```
134134

135135
Post release the API docs must be generated for each module and manually copied over to a working copy of the [cucumber.github.com](https://github.com/cucumber/cucumber.github.com) which must be a sibling of `cucumber-jvm` (this repo):

examples/android/cukeulator-test/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<parent>
77
<groupId>io.cucumber.android-examples</groupId>
88
<artifactId>android-examples</artifactId>
9-
<relativePath>../pom.xml</relativePath>
109
<version>2.0.0-SNAPSHOT</version>
1110
</parent>
1211

examples/android/pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
<parent>
77
<groupId>io.cucumber</groupId>
8-
<artifactId>cucumber-jvm</artifactId>
9-
<relativePath>../../pom.xml</relativePath>
8+
<artifactId>cucumber-examples</artifactId>
109
<version>2.0.0-SNAPSHOT</version>
1110
</parent>
1211

examples/clojure_cukes/pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
<parent>
66
<groupId>io.cucumber</groupId>
7-
<artifactId>cucumber-jvm</artifactId>
8-
<relativePath>../../pom.xml</relativePath>
7+
<artifactId>cucumber-examples</artifactId>
98
<version>2.0.0-SNAPSHOT</version>
109
</parent>
1110

examples/groovy-calculator/pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
<parent>
55
<groupId>io.cucumber</groupId>
6-
<artifactId>cucumber-jvm</artifactId>
7-
<relativePath>../../pom.xml</relativePath>
6+
<artifactId>cucumber-examples</artifactId>
87
<version>2.0.0-SNAPSHOT</version>
98
</parent>
109

examples/java-calculator-testng/pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
<parent>
55
<groupId>io.cucumber</groupId>
6-
<artifactId>cucumber-jvm</artifactId>
7-
<relativePath>../../pom.xml</relativePath>
6+
<artifactId>cucumber-examples</artifactId>
87
<version>2.0.0-SNAPSHOT</version>
98
</parent>
109

examples/java-calculator/pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
<parent>
55
<groupId>io.cucumber</groupId>
6-
<artifactId>cucumber-jvm</artifactId>
7-
<relativePath>../../pom.xml</relativePath>
6+
<artifactId>cucumber-examples</artifactId>
87
<version>2.0.0-SNAPSHOT</version>
98
</parent>
109

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
selenium_standalone/
2+
selenium_standalone_zips/

examples/java-webbit-websockets-selenium/pom.xml

+78-11
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,104 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24
<modelVersion>4.0.0</modelVersion>
35

46
<parent>
57
<groupId>io.cucumber</groupId>
6-
<artifactId>cucumber-jvm</artifactId>
7-
<relativePath>../../pom.xml</relativePath>
8+
<artifactId>cucumber-examples</artifactId>
89
<version>2.0.0-SNAPSHOT</version>
910
</parent>
1011

1112
<artifactId>java-webbit-websockets-selenium</artifactId>
1213
<packaging>jar</packaging>
1314
<name>Examples: Webbit WebSockets tested with Selenium</name>
1415

15-
<!-- skipTests -->
1616
<build>
1717
<plugins>
18+
<plugin>
19+
<groupId>com.lazerycode.selenium</groupId>
20+
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
21+
<executions>
22+
<execution>
23+
<goals>
24+
<goal>selenium</goal>
25+
</goals>
26+
</execution>
27+
</executions>
28+
</plugin>
29+
1830
<plugin>
1931
<groupId>org.apache.maven.plugins</groupId>
2032
<artifactId>maven-surefire-plugin</artifactId>
2133
<configuration>
22-
<!-- we don't want to run these tests on travis TRAVIS will be set to true in the travis CI
23-
They WILL be compiled -->
24-
<!-- TODO: there's PhantomJS, and xvfb, so we could maybe re-enable these -->
25-
<skipTests>${env.TRAVIS}</skipTests>
34+
<systemPropertyVariables>
35+
<!--
36+
Run phantomjs by default. It probably works every where.
37+
38+
Check the develop profile to configure which web driver to use
39+
when developing.
40+
-->
41+
<webdriver>phantomjs</webdriver>
42+
<!--Provided by the driver-binary-downloader-maven-plugin-->
43+
<!--suppress MavenModelInspection -->
44+
<webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver>
45+
<!--suppress MavenModelInspection -->
46+
<webdriver.chrome.driver>${webdriver.chrome.driver}
47+
</webdriver.chrome.driver>
48+
<!--suppress MavenModelInspection -->
49+
<webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
50+
<!--suppress MavenModelInspection -->
51+
<phantomjs.binary.path>${phantomjs.binary.path}</phantomjs.binary.path>
52+
<!--suppress MavenModelInspection -->
53+
<webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
54+
<!--suppress MavenModelInspection -->
55+
<webdriver.edge.driver>${webdriver.ie.driver}</webdriver.edge.driver>
56+
</systemPropertyVariables>
57+
</configuration>
58+
</plugin>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-compiler-plugin</artifactId>
62+
<configuration>
63+
<source>1.8</source>
64+
<target>1.8</target>
65+
</configuration>
66+
</plugin>
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-surefire-plugin</artifactId>
70+
<configuration>
71+
<systemPropertyVariables>
72+
<!--
73+
Change this to select the browser to use. E.g: firefox, chrome, edge, ect.
74+
-->
75+
<webdriver>firefox</webdriver>
76+
</systemPropertyVariables>
2677
</configuration>
2778
</plugin>
2879
</plugins>
2980
</build>
3081

82+
<profiles>
83+
<profile>
84+
<id>develop</id>
85+
<activation>
86+
<property>
87+
<name>!env.TRAVIS</name>
88+
</property>
89+
</activation>
90+
</profile>
91+
</profiles>
92+
3193
<dependencies>
3294
<dependency>
3395
<groupId>org.webbitserver</groupId>
3496
<artifactId>webbit</artifactId>
3597
</dependency>
3698

3799
<dependency>
38-
<groupId>info.cukes</groupId>
39-
<artifactId>cucumber-jvm-deps</artifactId>
100+
<groupId>io.cucumber</groupId>
101+
<artifactId>cucumber-java8</artifactId>
40102
<scope>test</scope>
41103
</dependency>
42104
<dependency>
@@ -56,7 +118,12 @@
56118
</dependency>
57119
<dependency>
58120
<groupId>org.seleniumhq.selenium</groupId>
59-
<artifactId>selenium-firefox-driver</artifactId>
121+
<artifactId>selenium-java</artifactId>
122+
<scope>test</scope>
123+
</dependency>
124+
<dependency>
125+
<groupId>org.seleniumhq.selenium</groupId>
126+
<artifactId>selenium-remote-driver</artifactId>
60127
<scope>test</scope>
61128
</dependency>
62129
<dependency>

examples/java-webbit-websockets-selenium/src/main/java/cucumber/examples/java/websockets/TemperatureServer.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ private double roundOneDecimal(double n) {
4040
return (double) Math.round(n * 10) / 10;
4141
}
4242

43-
public void start() throws IOException, ExecutionException, InterruptedException {
43+
public TemperatureServer start() throws IOException, ExecutionException, InterruptedException {
4444
webServer.start().get();
45+
return this;
4546
}
4647

47-
public void stop() throws IOException, ExecutionException, InterruptedException {
48+
public TemperatureServer stop() throws IOException, ExecutionException, InterruptedException {
4849
webServer.stop().get();
50+
return this;
4951
}
5052

5153
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
package cucumber.examples.java.websockets;
22

3-
import cucumber.api.java.en.Given;
3+
import cucumber.api.java8.En;
44
import org.openqa.selenium.By;
5-
import org.openqa.selenium.WebDriver;
65
import org.openqa.selenium.support.ui.ExpectedConditions;
76
import org.openqa.selenium.support.ui.WebDriverWait;
87

9-
public class NavigationStepdefs {
10-
private final WebDriver webDriver;
8+
public class NavigationStepdefs implements En {
119

1210
public NavigationStepdefs(SharedDriver webDriver) {
13-
this.webDriver = webDriver;
14-
}
15-
16-
@Given("^I am on the front page$")
17-
public void i_am_on_the_front_page() throws InterruptedException {
18-
webDriver.get("http://localhost:" + ServerHooks.PORT);
11+
Given("^I am on the front page$", () -> {
12+
webDriver.get("http://localhost:" + ServerHooks.PORT);
1913

20-
// The input fields won't be enabled until the WebSocket has established
21-
// a connection. Wait for this to happen.
22-
WebDriverWait wait = new WebDriverWait(webDriver, 1);
23-
wait.until(ExpectedConditions.elementToBeClickable(By.id("celcius")));
14+
// The input fields won't be enabled until the WebSocket has established
15+
// a connection. Wait for this to happen.
16+
WebDriverWait wait = new WebDriverWait(webDriver, 1);
17+
wait.until(ExpectedConditions.elementToBeClickable(By.id("celcius")));
18+
});
2419
}
2520
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
package cucumber.examples.java.websockets;
22

3-
import cucumber.api.java.After;
4-
import cucumber.api.java.Before;
3+
import cucumber.api.java8.En;
54

6-
import java.io.IOException;
7-
import java.util.concurrent.ExecutionException;
8-
9-
public class ServerHooks {
10-
public static final int PORT = 8887;
5+
public class ServerHooks implements En {
6+
static final int PORT = 8887;
117

128
private TemperatureServer temperatureServer;
139

14-
@Before
15-
public void startServer() throws IOException, ExecutionException, InterruptedException {
16-
temperatureServer = new TemperatureServer(PORT);
17-
temperatureServer.start();
18-
}
19-
20-
@After
21-
public void stopServer() throws IOException, ExecutionException, InterruptedException {
22-
temperatureServer.stop();
10+
public ServerHooks(){
11+
Before(() -> temperatureServer = new TemperatureServer(PORT).start());
12+
After(() -> temperatureServer.stop());
2313
}
2414
}

examples/java-webbit-websockets-selenium/src/test/java/cucumber/examples/java/websockets/SharedDriver.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
* </p>
3131
*/
3232
public class SharedDriver extends EventFiringWebDriver {
33-
private static final WebDriver REAL_DRIVER = new FirefoxDriver();
33+
private static final WebDriver REAL_DRIVER = WebDriverFactory.create();
34+
3435
private static final Thread CLOSE_THREAD = new Thread() {
3536
@Override
3637
public void run() {
@@ -47,11 +48,11 @@ public SharedDriver() {
4748
}
4849

4950
@Override
50-
public void close() {
51+
public void quit() {
5152
if (Thread.currentThread() != CLOSE_THREAD) {
52-
throw new UnsupportedOperationException("You shouldn't close this WebDriver. It's shared and will close when the JVM exits.");
53+
throw new UnsupportedOperationException("You shouldn't quit this WebDriver. It's shared and will quit when the JVM exits.");
5354
}
54-
super.close();
55+
super.quit();
5556
}
5657

5758
@Before
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
package cucumber.examples.java.websockets;
22

3-
import cucumber.api.java.en.Then;
4-
import cucumber.api.java.en.When;
5-
import org.openqa.selenium.By;
6-
import org.openqa.selenium.WebDriver;
7-
83
import static org.junit.Assert.assertEquals;
94

10-
public class TemperatureStepdefs {
11-
private final WebDriver webDriver;
5+
import cucumber.api.java8.En;
6+
import org.openqa.selenium.By;
7+
8+
public class TemperatureStepdefs implements En {
129

1310
public TemperatureStepdefs(SharedDriver webDriver) {
14-
this.webDriver = webDriver;
15-
}
1611

17-
@When("^I enter (.+) (celcius|fahrenheit)$")
18-
public void i_enter_temperature(double value, String unit) {
19-
webDriver.findElement(By.id(unit)).sendKeys(String.valueOf(value));
20-
}
12+
When("^I enter (.+) (celcius|fahrenheit)$", (Double value, String unit) ->
13+
webDriver.findElement(By.id(unit)).sendKeys(String.valueOf(value)));
2114

22-
@Then("^I should see (.+) (celcius|fahrenheit)$")
23-
public void i_should_see_temperature(double value, String unit) {
24-
assertEquals(String.valueOf(value), webDriver.findElement(By.id(unit)).getAttribute("value"));
15+
Then("^I should see (.+) (celcius|fahrenheit)$", (Double value, String unit) ->
16+
assertEquals(String.valueOf(value), webDriver.findElement(By.id(unit)).getAttribute("value")));
2517
}
2618
}

0 commit comments

Comments
 (0)