#594 FIX#597
#594 FIX#597TikhomirovSergey merged 8 commits intoappium:masterappium/java-client:masterfrom TikhomirovSergey:masterCopy head branch name to clipboard
Conversation
- AppiumCommandInfo was added. - constructors of AndroidDriver were changed.
|
|
|
@mykola-mokhnach @saikrishna321 @KazuCocoa |
| import org.openqa.selenium.remote.http.HttpMethod; | ||
|
|
||
| public class AppiumCommandInfo extends CommandInfo { | ||
| private final String url; |
There was a problem hiding this comment.
wouldn't it be more useful to keep url as an URL object instead of just a string?
There was a problem hiding this comment.
@mykola-mokhnach
No. Take a look at the
https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/MobileCommand.java#L127
and
I think that an URL like that can't be created by Java. It throws MalformedException at that case.
| AppiumProtocolHandShake.Result result = handshake.createSession(client, command); | ||
| Dialect dialect = result.getDialect(); | ||
| commandCodec = dialect.getCommandCodec(); | ||
| for (Map.Entry<String, AppiumCommandInfo> entry : additionalCommands.entrySet()) { |
There was a problem hiding this comment.
can be simplified as
additionalCommands.forEach((key, value) -> {
checkNotNull(key);
checkNotNull(value);
commandCodec.defineCommand(key, value.getMethod(), value.getUrl());
});|
|
||
| Response response = responseCodec.decode(httpResponse); | ||
| if (response.getSessionId() == null) { | ||
| if (httpResponse.getTargetHost() != null) { |
There was a problem hiding this comment.
do we assume, that httpResponse and response can never be equal to null?
| Optional<Result> result = createSession(client, parameters); | ||
|
|
||
| // Assume a fragile OSS webdriver implementation | ||
| if (!result.isPresent()) { |
There was a problem hiding this comment.
this all can be chained into orElseGet.orElseGet.orElseThrow
| String req = new BeanToJsonConverter().convert(required); | ||
|
|
||
| // Assume the remote end obeys the robustness principle. | ||
| StringBuilder parameters = new StringBuilder("{"); |
There was a problem hiding this comment.
I'm thinking about using JSONObject here and JSONObject.toString() instead of StringBuilder, which can be potentially not so secure and stable.
|
@mykola-mokhnach yes. Thank you. I will fix it asap. |
|
@TikhomirovSergey Works like a charm with all drivers 👍 But i didn't get the empty curly brackets in between comparing with #594 (comment). |
|
@SrinivasanTarget @mykola-mokhnach |
| throws IOException { | ||
|
|
||
| Capabilities desired = (Capabilities) command.getParameters().get("desiredCapabilities"); | ||
| desired = desired == null ? new DesiredCapabilities() : desired; |
There was a problem hiding this comment.
I'm not 100% sure, but it would be better to use if condition here rather than ternary operator, because of http://stackoverflow.com/questions/12643973/java-calling-a-method-using-a-ternary-operator
This means the code will anyway create an extra DesiredCapabilities instance even if desired != null
There was a problem hiding this comment.
Why not java Optional?
There was a problem hiding this comment.
with Optional this might look like
Capabilities desired = Optional.ofNullable((Capabilities) command.getParameters().get("desiredCapabilities"))
.orElseGet(DesiredCapabilities::new);| result = createSession(client, jsonObject); | ||
| } | ||
|
|
||
| if (result.isPresent()) { |
There was a problem hiding this comment.
return result.orElseThrow(() -> new SessionNotCreatedException(
String.format("Unable to create new remote session. desired capabilities = %s, required capabilities = %s", desired,required)
));| // Fine. Handle that below | ||
| } | ||
|
|
||
| if (jsonBlob == null) { |
There was a problem hiding this comment.
wouldn't be simpler to assign jsonBlob to HashMap upon definition?
| required = required == null ? new DesiredCapabilities() : required; | ||
|
|
||
| JsonParser parser = new JsonParser(); | ||
| JsonElement des = parser.parse(new BeanToJsonConverter().convert(desired)); |
|
@mykola-mokhnach Ok. Thank you. Will try to work it out toaday. |
...also browser test improvement
|
@mykola-mokhnach @SrinivasanTarget Could you take a look at new changes ane more time? |
| throws IOException, WebDriverException { | ||
|
|
||
| Capabilities desired = ofNullable((Capabilities) command.getParameters().get("desiredCapabilities")) | ||
| .orElse(new DesiredCapabilities()); |
There was a problem hiding this comment.
this will also create an extra instance of DesiredCapabilities. One must use orElseGet here to avoid this (orElse is good for constants only).
There was a problem hiding this comment.
hi please did you know when the new jar will be available?
There was a problem hiding this comment.
@swimoAmin It will be available soon in couple of days.
|
@SrinivasanTarget @mykola-mokhnach There is one more commit. I think it is finally completed |
|
LGTM but request looks same with few null params and empty curly brackets. Any idea? @TikhomirovSergey ping |
|
Is this fix included in 5.0.0-BETA6? I am still getting this error using that version of the Java Client with Appium 1.6.4-beta: [debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","capabilities","sessionId","id"]} and you sent ["desiredCapabilities","requiredCapabilities","capabilities","alwaysMatch","firstMatch"] |
|
@szaluk Yes changes are there and works fine for me. Can you please log an issue with detailed description, code snippet and logs so that we can investigate further. |
|
@SrinivasanTarget - I just created appium/appium#8118 Thanks, |
Change list
#594 FIX:
Types of changes
Put an
xin the boxes that applyDetails
Some changes may be considered as breaking changes.