Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Better message for creating session with W3C #331

Merged
merged 2 commits into from
Jun 17, 2019

Conversation

Siddh010
Copy link
Contributor

Create PR for [appium/appium/issues/12766]
Better message for creating session with W3C

@@ -4,6 +4,7 @@ import log from '../logger';
import { errors } from '../../protocol';
import UUID from 'uuid-js';
import { processCapabilities } from '../capabilities';
import prettyJson from 'prettyjson';
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the point in using third-party dependency? we can still add indentation parameters to JSON.stringify call

@Siddh010
Copy link
Contributor Author

Please find the few different ways I tried for making W3C capabilities more readable and showing in JSON format, let me know which look fine.

  1. Using JSON.stringify(w3cCapabilities)
    log.debug(Creating session with W3C capabilities: ${JSON.stringify(w3cCapabilities)});

    OutPut in Appium server:-
    [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":
    {"platformName":"android","appium:app":"/Users/siddartha/eclipse-workspace/AppiumSampleDemo/VodQA.apk","appium:automationName":"UIAutomator2","appium:deviceName":"android","appium:platformVersion":"8.1"},"firstMatch":[{}]}

  2. Using prettyJson lib

    log.debug(Creating session with W3C capabilities:);
    log.debug(prettyJson.render(w3cCapabilities, {noColor: true}));

    Output in the appium server log

[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities:
[debug] [BaseDriver] alwaysMatch:
[debug] [BaseDriver] platformName: android
[debug] [BaseDriver] appium:app: /Users/siddartha/eclipse-workspace/AppiumSampleDemo/VodQA.apk
[debug] [BaseDriver] appium:automationName: UIAutomator2
[debug] [BaseDriver] appium:deviceName: android
[debug] [BaseDriver] appium:platformVersion: 8.1
[debug] [BaseDriver] firstMatch:
[debug] [BaseDriver] -

  1. Before: we were using
    log.debug(Creating session with W3C capabilities: ${_.truncate(JSON.stringify(w3cCapabilities))});

OutPut in Appium Server log:-
[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa...

Also tried with inspectObject method from (https://github.com/appium/appium/blob/master/lib/utils.js)
but showing empty/null array object for firstMatch

[BaseDriver] firstMatch: {
[BaseDriver] 0: {
[BaseDriver] }
[BaseDriver] }

Output

[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities:
[BaseDriver] alwaysMatch: {
[BaseDriver] platformName: android
[BaseDriver] appium:app: /Users/siddartha/eclipse-workspace/AppiumSampleDemo/VodQA.apk
[BaseDriver] appium:automationName: UIAutomator2
[BaseDriver] appium:deviceName: android
[BaseDriver] appium:platformVersion: 8.1
[BaseDriver] }
[BaseDriver] firstMatch: {
[BaseDriver] 0: {
[BaseDriver] }
[BaseDriver] }

@mykola-mokhnach
Copy link
Contributor

Check the documentation on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

The function also has the second and the third (replacer, space) optional arguments, which can be of use.

@Siddh010
Copy link
Contributor Author

Siddh010 commented Jun 16, 2019

Thanks, Mykola, used below code, please let me know if this is fine
log.debug(Creating session with W3C capabilities: ${JSON.stringify(w3cCapabilities,null,'\t')});

Output:
[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {
[debug] [BaseDriver] "alwaysMatch": {
[debug] [BaseDriver] "platformName": "android",
[debug] [BaseDriver] "appium:app": "/Users/siddartha/eclipse-workspace/AppiumSampleDemo/VodQA.apk",
[debug] [BaseDriver] "appium:automationName": "UIAutomator2",
[debug] [BaseDriver] "appium:deviceName": "android",
[debug] [BaseDriver] "appium:platformVersion": "8.1"
[debug] [BaseDriver] },
[debug] [BaseDriver] "firstMatch": [
[debug] [BaseDriver] {}
[debug] [BaseDriver] ]
[debug] [BaseDriver] }

Screen Shot 2019-06-16 at 12 43 43 PM

@mykola-mokhnach
Copy link
Contributor

mykola-mokhnach commented Jun 16, 2019

what do you think about JSON.stringify(w3cCapabilities, null, 2) ?

@Siddh010
Copy link
Contributor Author

Added third argument with 2, I suppose this look now fine
log.debug(Creating session with W3C capabilities: ${JSON.stringify(w3cCapabilities,null,2)});

Screen Shot 2019-06-17 at 9 33 02 PM

@imurchie
Copy link
Contributor

That option looks good to me.

@dpgraham
Copy link
Contributor

Thank you @Siddh010 !

@dpgraham dpgraham self-requested a review June 17, 2019 17:49
@mykola-mokhnach mykola-mokhnach merged commit 69dde69 into appium:master Jun 17, 2019
@Siddh010
Copy link
Contributor Author

wow!! Thanks to every one for guidance and help. @dpgraham, @mykola-mokhnach, @imurchie

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

Successfully merging this pull request may close these issues.

4 participants