Skip to content
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

Merged
merged 8 commits into from
Mar 21, 2017
Merged

#594 FIX #597

merged 8 commits into from
Mar 21, 2017

Conversation

TikhomirovSergey
Copy link
Contributor

@TikhomirovSergey TikhomirovSergey commented Mar 10, 2017

Change list

#594 FIX:

  • update to selenium 3.3.1
  • AppiumCommandExecutor was reimplemented. Now it implements CommandExecutor and doesn't extends HttpCommandExecutor. However the most part of implementation was taken from Selenium.
  • constructor changes.

Types of changes

Put an x in the boxes that apply

  • No changes in production code.
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Details

Some changes may be considered as breaking changes.

shs96c and others added 5 commits March 10, 2017 00:01
AppiumProtocolHandShake was added.
As it 99.9% repeats the old working version so the real authorship is used for this commit.
UPDATE to Selenium 3.3.0
- AppiumCommandInfo was added.
- constructors of AndroidDriver were changed.
@jsf-clabot
Copy link

jsf-clabot commented Mar 10, 2017

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ TikhomirovSergey
❌ shs96c

@TikhomirovSergey
Copy link
Contributor Author

@mykola-mokhnach @saikrishna321 @KazuCocoa
You are invited too.

import org.openqa.selenium.remote.http.HttpMethod;

public class AppiumCommandInfo extends CommandInfo {
private final String url;
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppiumProtocolHandShake.Result result = handshake.createSession(client, command);
Dialect dialect = result.getDialect();
commandCodec = dialect.getCommandCodec();
for (Map.Entry<String, AppiumCommandInfo> entry : additionalCommands.entrySet()) {
Copy link
Contributor

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());
});

Copy link
Member

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) {
Copy link
Contributor

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()) {
Copy link
Contributor

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("{");
Copy link
Contributor

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.

@TikhomirovSergey
Copy link
Contributor Author

@mykola-mokhnach yes. Thank you. I will fix it asap.

@SrinivasanTarget
Copy link
Member

@TikhomirovSergey Works like a charm with all drivers 👍
Have a query, Our request looks like this now,

[
  {
    "app": "/Users/ssekar/workspace/java-client/src/test/java/io/appium/java_client/TestApp.app.zip",
    "platformVersion": "10.1",
    "automationName": "XCuiTest",
    "browserName": "",
    "platformName": "iOS",
    "deviceName": "iPhone 6",
    "launchTimeout": 500000
  },
  {
    
  },
  {
    "desiredCapabilities": {
      "app": "/Users/ssekar/workspace/java-client/src/test/java/io/appium/java_client/TestApp.app.zip",
      "platformVersion": "10.1",
      "automationName": "XCuiTest",
      "browserName": "",
      "platformName": "iOS",
      "deviceName": "iPhone 6",
      "launchTimeout": 500000
    },
    "requiredCapabilities": {
      
    }
  },
  null,
  null
]

But i didn't get the empty curly brackets in between comparing with #594 (comment).

@TikhomirovSergey
Copy link
Contributor Author

@SrinivasanTarget @mykola-mokhnach
Some issues were fixed. I will commit them when possible. I am very busy on this week. Sorry for the delaying.

throws IOException {

Capabilities desired = (Capabilities) command.getParameters().get("desiredCapabilities");
desired = desired == null ? new DesiredCapabilities() : desired;
Copy link
Contributor

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not java Optional?

Copy link
Contributor

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()) {
Copy link
Contributor

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) {
Copy link
Contributor

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@TikhomirovSergey
Copy link
Contributor Author

@mykola-mokhnach Ok. Thank you. Will try to work it out toaday.

@TikhomirovSergey
Copy link
Contributor Author

@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());
Copy link
Contributor

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).

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?

Copy link
Member

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.

@TikhomirovSergey
Copy link
Contributor Author

@SrinivasanTarget @mykola-mokhnach There is one more commit. I think it is finally completed

Copy link
Contributor

@mykola-mokhnach mykola-mokhnach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SrinivasanTarget
Copy link
Member

LGTM but request looks same with few null params and empty curly brackets. Any idea?

@TikhomirovSergey ping

Copy link
Member

@SrinivasanTarget SrinivasanTarget left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@szaluk
Copy link

szaluk commented Mar 28, 2017

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"]

@SrinivasanTarget
Copy link
Member

@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.

@szaluk
Copy link

szaluk commented Mar 28, 2017

@SrinivasanTarget - I just created appium/appium#8118

Thanks,
Steve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants