19
19
20
20
import static java .util .concurrent .TimeUnit .SECONDS ;
21
21
22
- import com .google .common .io .Files ;
23
-
24
- import org .openqa .selenium .Build ;
22
+ import org .openqa .selenium .BuckBuild ;
25
23
import org .openqa .selenium .Capabilities ;
26
24
import org .openqa .selenium .net .NetworkUtils ;
27
25
import org .openqa .selenium .net .PortProber ;
30
28
import org .openqa .selenium .remote .DesiredCapabilities ;
31
29
import org .openqa .selenium .testing .InProject ;
32
30
33
- import java .io .File ;
34
31
import java .io .IOException ;
35
32
import java .net .MalformedURLException ;
36
33
import java .net .URL ;
37
- import java .nio .charset . Charset ;
34
+ import java .nio .file . Path ;
38
35
import java .util .LinkedList ;
39
36
import java .util .List ;
40
37
import java .util .logging .Logger ;
@@ -56,30 +53,25 @@ public void enableLogCapture() {
56
53
*
57
54
* @return The new server.
58
55
*/
59
- public OutOfProcessSeleniumServer start () {
56
+ public OutOfProcessSeleniumServer start () throws IOException {
60
57
log .info ("Got a request to start a new selenium server" );
61
58
if (command != null ) {
62
59
log .info ("Server already started" );
63
60
throw new RuntimeException ("Server already started" );
64
61
}
65
62
66
- String classPath = buildServerAndClasspath ();
63
+ String serverJar = buildServerAndClasspath ();
67
64
68
65
int port = PortProber .findFreePort ();
69
66
String localAddress = new NetworkUtils ().getPrivateLocalAddress ();
70
67
baseUrl = String .format ("http://%s:%d" , localAddress , port );
71
68
72
69
List <String > cmdLine = new LinkedList <>();
73
70
cmdLine .add ("java" );
74
- cmdLine .add ("-cp" );
75
- cmdLine .add (classPath );
76
- cmdLine .add ("org.openqa.grid.selenium.GridLauncher" );
71
+ cmdLine .add ("-jar" );
72
+ cmdLine .add (serverJar );
77
73
cmdLine .add ("-port" );
78
74
cmdLine .add (String .valueOf (port ));
79
- cmdLine .add ("-browserSideLog" );
80
- if (captureLogs ) {
81
- cmdLine .add ("-captureLogsOnQuit" );
82
- }
83
75
command = new CommandLine (cmdLine .toArray (new String [cmdLine .size ()]));
84
76
85
77
if (Boolean .getBoolean ("webdriver.development" )) {
@@ -92,10 +84,13 @@ public OutOfProcessSeleniumServer start() {
92
84
try {
93
85
URL url = new URL (baseUrl + "/wd/hub/status" );
94
86
log .info ("Waiting for server status on URL " + url );
95
- new UrlChecker ().waitUntilAvailable (60 , SECONDS , url );
87
+ new UrlChecker ().waitUntilAvailable (30 , SECONDS , url );
96
88
log .info ("Server is ready" );
97
89
} catch (UrlChecker .TimeoutException e ) {
98
90
log .severe ("Server failed to start: " + e .getMessage ());
91
+ command .destroy ();
92
+ log .severe (command .getStdOut ());
93
+ command = null ;
99
94
throw new RuntimeException (e );
100
95
} catch (MalformedURLException e ) {
101
96
throw new RuntimeException (e );
@@ -122,18 +117,9 @@ public void stop() {
122
117
command = null ;
123
118
}
124
119
125
- private String buildServerAndClasspath () {
126
- new Build ().of ("//java/server/src/org/openqa/grid/selenium:selenium" )
127
- .of ("//java/server/src/org/openqa/grid/selenium:selenium:classpath" )
128
- .go ();
129
-
130
- String classpathFile = InProject .locate (
131
- "build/java/server/src/org/openqa/grid/selenium/selenium.classpath" ).getAbsolutePath ();
132
- try {
133
- return Files .readFirstLine (new File (classpathFile ), Charset .defaultCharset ());
134
- } catch (IOException e ) {
135
- throw new RuntimeException (e );
136
- }
120
+ private String buildServerAndClasspath () throws IOException {
121
+ Path serverJar = new BuckBuild ().of ("//java/server/src/org/openqa/grid/selenium:selenium" ).go ();
122
+ return serverJar .toAbsolutePath ().toString ();
137
123
}
138
124
139
125
public URL getWebDriverUrl () {
0 commit comments