Skip to content

Commit 86419e9

Browse files
krmahadevanshs96c
authored andcommitted
Propagate altered DC to Node
Currently the grid logic is such that if a particular test’s capabilities are altered via an overloaded version of * DefaultRemoteProxy#getNewSession * DefaultRemoteProxy#beforeSession the expectation is that the altered capabilities are what gets forwarded to the actual node prior to an actual session creation on the node. But this doesn’t happen because the altered desired capabilities are not being considered. Fixed this. Signed-off-by: Simon Stewart <simon.m.stewart@gmail.com>
1 parent 392311e commit 86419e9

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

java/server/src/org/openqa/grid/web/servlet/handler/SeleniumBasedRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public RequestType getRequestType() {
136136

137137
@Override
138138
public ServletInputStream getInputStream() throws IOException {
139+
setBody(getBody());
139140
return new ServletInputStreamImpl(new ByteArrayInputStream(body));
140141
}
141142

java/server/src/org/openqa/grid/web/servlet/handler/WebDriverRequest.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818

1919
package org.openqa.grid.web.servlet.handler;
2020

21+
import com.google.gson.Gson;
22+
import com.google.gson.JsonElement;
2123
import com.google.gson.JsonObject;
2224
import com.google.gson.JsonParser;
2325

2426
import org.openqa.grid.common.exception.GridException;
2527
import org.openqa.grid.internal.ExternalSessionKey;
2628
import org.openqa.grid.internal.Registry;
29+
import org.openqa.selenium.remote.BeanToJsonConverter;
2730
import org.openqa.selenium.remote.JsonToBeanConverter;
2831

2932
import java.util.Map;
@@ -32,6 +35,9 @@
3235

3336
public class WebDriverRequest extends SeleniumBasedRequest {
3437

38+
private static final String CAPABILITIES = "capabilities";
39+
private static final String DESIRED_CAPABILITIES = "desiredCapabilities";
40+
3541
public WebDriverRequest(HttpServletRequest httpServletRequest, Registry registry) {
3642
super(httpServletRequest, registry);
3743
}
@@ -65,17 +71,41 @@ public Map<String, Object> extractDesiredCapability() {
6571
JsonObject map = new JsonParser().parse(json).getAsJsonObject();
6672
// Current W3C has required / desired capabilities wrapped in a 'capabilities' object.
6773
// This will need to be updated if/when https://github.com/w3c/webdriver/pull/327 gets merged
68-
if (map.has("capabilities")) {
69-
JsonObject outerCapabilities = map.getAsJsonObject("capabilities");
70-
if (outerCapabilities.has("desiredCapabilities")) {
71-
JsonObject desiredCapabilities = outerCapabilities.getAsJsonObject("desiredCapabilities");
74+
if (map.has(CAPABILITIES)) {
75+
JsonObject outerCapabilities = map.getAsJsonObject(CAPABILITIES);
76+
if (outerCapabilities.has(DESIRED_CAPABILITIES)) {
77+
JsonObject desiredCapabilities = outerCapabilities.getAsJsonObject(DESIRED_CAPABILITIES);
7278
return new JsonToBeanConverter().convert(Map.class, desiredCapabilities);
7379
}
7480
}
75-
JsonObject dc = map.get("desiredCapabilities").getAsJsonObject();
81+
JsonObject dc = map.get(DESIRED_CAPABILITIES).getAsJsonObject();
7682
return new JsonToBeanConverter().convert(Map.class, dc);
83+
7784
} catch (Exception e) {
7885
throw new GridException("Cannot extract a capabilities from the request: " + json, e);
7986
}
8087
}
88+
89+
@Override
90+
public String getBody() {
91+
String json = super.getBody();
92+
try {
93+
Map<String, Object> capsMap = getDesiredCapabilities();
94+
if (capsMap == null) {
95+
return json;
96+
}
97+
JsonObject map = new JsonParser().parse(json).getAsJsonObject();
98+
JsonElement dc = new BeanToJsonConverter().convertObject(capsMap);
99+
if (map.has(CAPABILITIES)) {
100+
map.getAsJsonObject(CAPABILITIES)
101+
.add(DESIRED_CAPABILITIES, new BeanToJsonConverter().convertObject(dc));
102+
} else {
103+
map.add(DESIRED_CAPABILITIES, dc);
104+
}
105+
return new Gson().toJson(map);
106+
} catch (Exception e) {
107+
return json;
108+
}
109+
}
110+
81111
}

0 commit comments

Comments
 (0)