|
27 | 27 | import static org.hamcrest.Matchers.is;
|
28 | 28 | import static org.hamcrest.Matchers.nullValue;
|
29 | 29 | import static org.hamcrest.Matchers.startsWith;
|
| 30 | +import static org.junit.Assert.assertEquals; |
30 | 31 | import static org.junit.Assert.assertThat;
|
31 | 32 | import static org.junit.Assert.fail;
|
| 33 | +import static org.openqa.selenium.remote.Dialect.OSS; |
32 | 34 | import static org.openqa.selenium.remote.http.HttpMethod.DELETE;
|
33 | 35 | import static org.openqa.selenium.remote.http.HttpMethod.GET;
|
34 | 36 | import static org.openqa.selenium.remote.http.HttpMethod.POST;
|
35 | 37 |
|
| 38 | +import com.google.common.collect.ImmutableList; |
36 | 39 | import com.google.common.collect.ImmutableMap;
|
37 | 40 | import com.google.gson.JsonNull;
|
38 | 41 | import com.google.gson.JsonObject;
|
|
42 | 45 | import org.junit.runners.JUnit4;
|
43 | 46 | import org.openqa.selenium.UnsupportedCommandException;
|
44 | 47 | import org.openqa.selenium.remote.Command;
|
| 48 | +import org.openqa.selenium.remote.DriverCommand; |
| 49 | +import org.openqa.selenium.remote.RemoteWebElement; |
45 | 50 | import org.openqa.selenium.remote.SessionId;
|
46 | 51 |
|
47 | 52 | import java.net.URISyntaxException;
|
| 53 | +import java.util.List; |
48 | 54 | import java.util.Map;
|
49 | 55 |
|
50 | 56 | /**
|
@@ -356,4 +362,24 @@ public void treatsNullPathAsRoot_unrecognizedCommand() {
|
356 | 362 | // Do nothing.
|
357 | 363 | }
|
358 | 364 | }
|
| 365 | + |
| 366 | + @Test |
| 367 | + public void whenDecodingAnHttpRequestRecreateWebElements() { |
| 368 | + Command command = new Command( |
| 369 | + new SessionId("1234567"), |
| 370 | + DriverCommand.EXECUTE_SCRIPT, |
| 371 | + ImmutableMap.of( |
| 372 | + "script", "", |
| 373 | + "args", ImmutableList.of(ImmutableMap.of(OSS.getEncodedElementKey(), "67890")))); |
| 374 | + |
| 375 | + HttpRequest request = codec.encode(command); |
| 376 | + |
| 377 | + Command decoded = codec.decode(request); |
| 378 | + |
| 379 | + List<?> args = (List<?>) decoded.getParameters().get("args"); |
| 380 | + assertEquals(RemoteWebElement.class, args.get(0).getClass()); |
| 381 | + |
| 382 | + RemoteWebElement element = (RemoteWebElement) args.get(0); |
| 383 | + assertEquals("67890", element.getId()); |
| 384 | + } |
359 | 385 | }
|
0 commit comments