appium/java-client

Client ignoring Capabilities and Bad Parameter Errors

FelixHahn opened this issue · 11 comments

Description

The Java client seems to send the w3c desired capabilities in a wrong format so that the server throws an error. And the client is not sending some capabilities such as forceMjsonwp capability

Environment

  • java client: 6.0.0
  • Appium server: 1.8.2-beta
  • Desktop OS/version: Windows 7
  • Node.js version: 8.11.1
  • Mobile platform/version under test: Android
  • Real device: Google Pixel 2 (Androui 8.1) ans Samsung Galaxy S6 (Android 7.0)

Details

I always get a w3c bad parameter error if I want to set the implicit wait time outs.

[HTTP] --> POST /wd/hub/session/45e323c1-1248-4207-95b3-22a21ec5600f/timeouts
[HTTP] {"type":"implicit","ms":30000}
[debug] [W3C] Bad parameters: BadParametersError: Parameters were incorrect. We wanted "W3C prot
ad or implicit to be set" and you sent {"type":"implicit","ms":30000}
[HTTP] <-- POST /wd/hub/session/45e323c1-1248-4207-95b3-22a21ec5600f/timeouts 400 5 ms - 5372

Therefore I treid to force MJSONWP Protocol with forceMjsonwp capability. But forceMjsonwp capability is not send from java client to appium server. Seems like client is ignoring this capability.
If I try to add the forceMjsonwp capability manually into a session I created by hand with a rest client everything works fine.

I tried to set forceMjsonwp capability in both ways

capabilities.setCapability(MobileCapabilityType.FORCE_MJSONWP, true);

capabilities.setCapability("forceMjsonwp ", true);

Neither is send from client to server.

Code To Reproduce Issue

public AppiumDriver<?> setupAndroidDriver(String deviceID, String androidVersion, String appPackage, String activity, String appiumServer) throws MalformedURLException{

		DesiredCapabilities capabilities = new DesiredCapabilities(); 
		capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceID); 
		capabilities.setCapability("udid", deviceID); 
		capabilities.setCapability(MobileCapabilityType.FORCE_MJSONWP, true);
		capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, androidVersion); 
		capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); 
		capabilities.setCapability("appWaitDuration", 20000); 
		capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
		capabilities.setCapability(MobileCapabilityType.FULL_RESET, false);
		capabilities.setCapability("appPackage", appPackage); 
		capabilities.setCapability("appActivity", activity); 
		capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
		driver = new AppiumDriver<MobileElement>(new URL(appiumServer), capabilities);
		driver.manage().timeouts().implicitlyWait(30000, TimeUnit.MILLISECONDS);

		return driver;
	}

Link to Appium logs

https://gist.github.com/FelixHahn/93faef358769bebdd34f931303b5a1ba

Any meanings to this?

@FelixHahn I will have a look at it soon

I couldn't reproduce it in 1.8.1 or in latest appium source in W3C mode but it does fails if we forceMJSWP.

Can one of you assign this to me

@SrinivasanTarget The forceMjsonwp was introduced in the Ruby client as way for the client to force usage of MJSONWP over W3C. When it's set to true it's supposed to exclude the capabilities: {alwaysMatch: {...}, firstMatch: [{...}, ...}] object from being sent

Does the Java client do that?

@dpgraham if we set forceMjsonwp to true, payload will look as below from java client...

[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"app":"/Users/ssekar/workspace/java-client/src/test/java/io/appium/java_client/ApiDemos-debug.apk","automationName":"UIAutomator2","platformName":"Android","deviceName":"Android Emulator"},"capabilities":{"alwaysMatch":{"platformName":"android"},"firstMatch":[{}]}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"app":"/Users/ssekar/workspace/java-client/src/test/java/io/appium/java_client/ApiDemos-debug.apk","automationName":"UIAutomator2","platformName":"Android","deviceName":"Android Emulator"},null,{"alwaysMatch":{"platformName":"android"},"firstMatch":[{}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1528310015357 (00:03:35 GMT+0530 (IST))
[Appium] Could not parse W3C capabilities: 'deviceName' can't be blank. Falling back to JSONWP protocol.
[Appium] The following capabilities were provided in the JSONWP desired capabilities that are missing in W3C capabilities: ["app","automationName","platformName","deviceName"]. Falling back to JSONWP protocol.
[Appium] Creating new AndroidUiautomator2Driver (v1.12.0) session
[Appium] Capabilities:
[Appium]   app: /Users/ssekar/workspace/java-client/src/test/java/io/appium/java_client/ApiDemos-debug.apk
[Appium]   automationName: UIAutomator2
[Appium]   platformName: Android
[Appium]   deviceName: Android Emulator
[debug] [BaseDriver] Creating session with MJSONWP desired capabilities: {"app":"/Users/ssekar/works...
[BaseDriver] Session created with session id: 5b2fa500-f32d-4be9-906a-95e58b2a5ffd

Do you expect the payload constructed by java client shouldn't contain Capabilities object at all if forceMjsonwp is set to true?

Also can you confirm the behavior in ruby client?

@KazuCocoa How does the ruby_lib use forceMjsonwp? It omits the capabilities object, right?

@dpgraham
Yes. in Ruby and Python client, I delete forceMjsonwp from desired capability. And if the property exists, { desiredCapabilities: desired_capabilities } will send instead of {alwaysMatch: {...}, firstMatch: [{...}, ...}

@SrinivasanTarget just so you know, it's a non-standard capability, it's just there so that users can fall back to MJSONWP.