Mobile phone Automation test: Appium Code of Logger

Source: Internet
Author: User
Tags appium

Poptest is the only training institute for developing Test and development engineers in China, aiming at the ability of the trainees to be competent in automated testing, performance testing and testing tools development. Poptest launches the mobile phone automation Test course, explains the Appuim practical application, the training entire use commercial project, we may add QQ group to Exchange: 195983133Log Form

First, let's look at a log output:

Info:starting App

Info: [Debug] attempting to kill all ' uiautomator ' processes

Info: [Debug] Getting all processes with ' uiautomator '

Info: [Debug] executing cmd:/users/wuxian/documents/tools/sdk/platform-tools/adb-s emulator-5554 Shell "PS" Uiautomator ' "

Info: [Debug] No matching processes found

Info: [Debug] Running Bootstrap

Info: [Debug] Spawning:/users/wuxian/documents/tools/sdk/platform-tools/adb-s emulator-5554 shell Uiautomator Runtest appiumbootstrap.jar-c io.appium.android.bootstrap.bootstrap-e Pkg com.example.android.apis-e Disableandroidwatchers false

Info: [Debug] [Uiautomator STDOUT] Instrumentation_status:numtests=1

Info: [Debug] [Uiautomator STDOUT] instrumentation_status:stream=

Info: [Debug] [Uiautomator STDOUT] Io.appium.android.bootstrap.Bootstrap:

Info: [Debug] [Uiautomator STDOUT] Instrumentation_status:id=uiautomatortestrunner

Info: [Debug] [Uiautomator STDOUT] Instrumentation_status:test=testrunserver

Info: [Debug] [uiautomator STDOUT] instrumentation_status:class= "io". Appium.android.bootstrap.Bootstrap

Info: [Debug] [Uiautomator STDOUT] Instrumentation_status:current=1

Info: [Debug] [Uiautomator STDOUT] Instrumentation_status_code:1

Info: [Debug] [BOOTSTRAP] [debug] Socket opened on port 4724

Info: [Debug] [BOOTSTRAP] [debug] Appium Socket Server ready

I divide the above log into 4 types (message body)
1. Log level: Message
2. Log level: [Debug] Message
3. Log level: [Debug] [BOOTSTRAP] [debug] Message
4. Log level: [Debug] [uiautomator STDOUT] Message

1.log Rating: Message

This type of log is a simple log of the Appium server, with a log level of non-debug

2.log Rating: [Debug] Message

This type of log and the above is the same, is the log of the Appium server, the difference is that the log level is debug, in the Logger.js module we can see the following code, the following code to the debug level of log, changed to the info level, and then followed by [ DEBUG] flag.

if (levels[logger.transports.console.level] = = = Levels.debug) {

Logger.debug = function (msg) {logger.info (' [debug] ' + msg);};

}

3.[debug][bootstrap] [debug] Message

This type of log is the output returned by the socket server package in the phone (called Bootstrap on the Android phone's jar package)

4.log Rating: [Debug] [uiautomator STDOUT] Message

This type of log is the log that executes the case output, and we can understand the log that is accepted by ADB. When we typically execute Uiautomator case, the console outputs this type of log with the Uiautomator logo.

Custom Log SectionLog Level

The first step is to modify the log level. For example, if we want to change the info level to warn level, we just need to put the following code for the Logger.js 223 rows or so

if (levels[logger.transports.console.level] = = = Levels.debug) {

Logger.debug = function (msg) {logger.info (' [debug] ' + msg);};

}

Revision changed to

This will change the debug level to warn mode, info mode or info mode (as I said before, you should know why debug is not the info level?). )。 Let's take a look at the output:

Info:starting App

Warn: [Debug] attempting to kill all ' uiautomator ' processes

Warn: [Debug] Getting all processes with ' uiautomator '

Warn: [debug] executing cmd:/users/wuxian/documents/tools/sdk/platform-tools/adb-s emulator-5554 Shell "PS" Uiautomator ' "

Warn: [debug] No matching processes found

Warn: [Debug] Running Bootstrap

Warn: [Debug] Spawning:/users/wuxian/documents/tools/sdk/platform-tools/adb-s emulator-5554 shell Uiautomator Runtest appiumbootstrap.jar-c io.appium.android.bootstrap.bootstrap-e Pkg com.example.android.apis-e Disableandroidwatchers false

Warn: [Debug] [Uiautomator STDOUT] Instrumentation_status:numtests=1

Warn: [Debug] [Uiautomator STDOUT] instrumentation_status:stream=

Warn: [Debug] [Uiautomator STDOUT] Io.appium.android.bootstrap.Bootstrap:

Warn: [Debug] [Uiautomator STDOUT] Instrumentation_status:id=uiautomatortestrunner

Warn: [Debug] [Uiautomator STDOUT] Instrumentation_status:test=testrunserver

Warn: [Debug] [uiautomator STDOUT] instrumentation_status:class= "io". Appium.android.bootstrap.Bootstrap

Warn: [Debug] [Uiautomator STDOUT] Instrumentation_status:current=1

Warn: [Debug] [Uiautomator STDOUT] Instrumentation_status_code:1

Warn: [Debug] [BOOTSTRAP] [debug] Socket opened on port 4724

Warn: [Debug] [BOOTSTRAP] [debug] Appium Socket Server ready

We changed info to warn, but we still have the info flag, because the change in the code above is based on the logger.debug you called, because as we said before, Appium will change the debug level to info and add a [debug] flag later Now we change to warn, then debug will change to warn, then add a [debug] flag. Therefore, after all the warn will inevitably follow a [debug].

Debug ID

The above debug, will be added after the Info/warn/error logo [debug], is not very ugly, I feel very ugly, we will change it to [testerhome], or just the code:

Info:starting App

Warn: [Testerhome] attempting to kill all ' uiautomator ' processes

Warn: [Testerhome] Getting all processes with ' uiautomator '

Warn: [testerhome] executing cmd:/users/wuxian/documents/tools/sdk/platform-tools/adb-s emulator-5554 Shell "PS" Uiautomator ' "

Warn: [testerhome] No matching processes found

Warn: [Testerhome] Running Bootstrap

Warn: [Testerhome] Spawning:/users/wuxian/documents/tools/sdk/platform-tools/adb-s emulator-5554 shell Uiautomator Runtest appiumbootstrap.jar-c io.appium.android.bootstrap.bootstrap-e Pkg com.example.android.apis-e Disableandroidwatchers false

Warn: [Testerhome] [uiautomator STDOUT] Instrumentation_status:numtests=1

Warn: [Testerhome] [uiautomator STDOUT] instrumentation_status:stream=

Warn: [Testerhome] [Uiautomator STDOUT] Io.appium.android.bootstrap.Bootstrap:

Warn: [Testerhome] [uiautomator STDOUT] Instrumentation_status:id=uiautomatortestrunner

Warn: [Testerhome] [uiautomator STDOUT] Instrumentation_status:test=testrunserver

Warn: [Testerhome] [uiautomator STDOUT] instrumentation_status:class= "io". Appium.android.bootstrap.Bootstrap

Warn: [Testerhome] [uiautomator STDOUT] Instrumentation_status:current=1

Warn: [Testerhome] [uiautomator STDOUT] Instrumentation_status_code:1

Warn: [Testerhome] [BOOTSTRAP] [debug] Socket opened on port 4724

Warn: [Testerhome] [BOOTSTRAP] [debug] Appium Socket Server ready

It's OK.

think Uiautomator stdout and Bootstrap don't understand?

No matter, written in Chinese, in the Devices/android/uiautomator.js file, find 190 and 203 lines around the statement, the above two identifiers are modified to Chinese:
Before modification:

After modification:

The output is:

Info:starting App

Warn: [Testerhome] attempting to kill all ' uiautomator ' processes

Warn: [Testerhome] Getting all processes with ' uiautomator '

Warn: [testerhome] executing cmd:/users/wuxian/documents/tools/sdk/platform-tools/adb-s emulator-5554 Shell "PS" Uiautomator ' "

Warn: [testerhome] No matching processes found

Warn: [Testerhome] Running Bootstrap

Warn: [Testerhome] Spawning:/users/wuxian/documents/tools/sdk/platform-tools/adb-s emulator-5554 shell Uiautomator Runtest appiumbootstrap.jar-c io.appium.android.bootstrap.bootstrap-e Pkg com.example.android.apis-e Disableandroidwatchers false

Warn: [testerhome] [script output] Instrumentation_status:numtests=1

Warn: [testerhome] [script output] instrumentation_status:stream=

Warn: [testerhome] [script output] Io.appium.android.bootstrap.Bootstrap:

Warn: [testerhome] [script output] Instrumentation_status:id=uiautomatortestrunner

Warn: [testerhome] [script output] Instrumentation_status:test=testrunserver

Warn: [testerhome] [script output] Instrumentation_status:class=io.appium.android.bootstrap.bootstrap

Warn: [testerhome] [script output] Instrumentation_status:current=1

Warn: [testerhome] [script output] Instrumentation_status_code:1

Warn: [Testerhome] [device Socket server output] [debug] socket opened on port 4724

Warn: [testerhome] [device socket server output] [debug] Appium Socket server ready

Mobile phone Automation test: Appium Code of Logger

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.