-
-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#594 FIX #597
#594 FIX #597
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be simplified as
additionalCommands.forEach((key, value) -> {
checkNotNull(key);
checkNotNull(value);
commandCodec.defineCommand(key, value.getMethod(), value.getUrl());
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
|
||
Response response = responseCodec.decode(httpResponse); | ||
if (response.getSessionId() == null) { | ||
if (httpResponse.getTargetHost() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not java Optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi please did you know when the new jar will be available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@swimoAmin It will be available soon in couple of days.
@SrinivasanTarget @mykola-mokhnach There is one more commit. I think it is finally completed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM but request looks same with few null params and empty curly brackets. Any idea? @TikhomirovSergey ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
x
in the boxes that applyDetails
Some changes may be considered as breaking changes.