[iOS]memo for ios-device-control

Around 5 months ago, Google has opensourced ios-device-control to make iOS related work automate. The repository supports both real devices and simulators.


It provides some examples and [https://github.com/google/ios-device-control/blob/master/java/com/google/iosdevicecontrol/examples/ExampleSimulatorDeviceControl.java] is one example with Simulator. When we run the example, we can see the following outputs.

$ java -jar SimulatorDevice-jar-with-dependencies.jar
Jan 15, 2018 12:15:03 AM com.google.iosdevicecontrol.examples.ExampleSimulatorDeviceControl main
INFO: Screenshot written to: /var/folders/y6/524wp8fx0xj5q1rf6fktjrb00000gn/T/screenshot4392370072269065541.png

Google has EarlGrey for test automation against UI level and this repository doesn’t compete with it since this tool looks mainly for handle real devices, I guess. I know every one who hope to enhance test automation for iOS struggling with the difficulties.

Have a good automation 🙂


[NPM][Appium] Restrict installed module size

I found https://github.com/appium/appium/issues/9912 and I learned the npm‘s --production flag to reduce the module size.

Install without devDependencies

$ npm install --production


With the –production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.

Remove devDependencies resources


$ npm install
$ cd node_modules/appium
$ npm prune --production

[Appium][Ruby]Run tests in parallel

When we run Appium in parallel on one Machine and one Appium server with Ruby, we have two ways to implement it. (For Android, we don’t need to configure this kind of environment. We must cover this for iOS because of the platform’s limitations.)

One is thread programming and another is process-fork programming. I’ll put examples to run tests with each method in the below.

  • rake run_parallel_t
    • Run tests with thread programming. In this case, each thread shares their data on the memory, classes. It means once our scenario depends on class method, we can’t keep clean test environment.
  • rake run_parallel_p
    • Run tests with process-fork programming. In this case, each process is isolated each other. So, we can keep the hermetic environment in each process.

I think process fork model is good for this time since we don’t need to depend on thread programming when we’d like to run tests in parallel.

Tasting report portal again

Today, the reportportal pre-4.0 released.

I’ve posted try reportportal before and I thought the tool looks helpful for us. I know of Allure2 which is close to this tool but report portal is a more pluggable reporting tool.

The tool provides to analyze test results using ML technology. We can see the feature’s video from https://www.youtube.com/watch?v=d2ekWI2exZ4 and it looks interesting. I guess the feature will be a handly trial to analysis test resuts.

We can run the tool with docker-composer easily and also, we can add test data via demo data section. Read http://reportportal.io/docs/Project-configuration . Thus, we can see some dashboard to confirm the behaviour.

Also, we can handle data via API and the portal also provide LDAP authentication, but it’s beta yet.

Reporting and management bugs with scenarios help developers and the tool also considers automated test scenarios with some testing framework.

[Appium][Android]Scrolling to an element

Just for my memo

When we scroll views using Appium, then we have two ways to achieve it.

  1. Use UiScrollable

The below method is implemented in Ruby client.

  1. Use TouchAction or related actions.

The below is methods I used to implement as helper methods in my framework.

In my experience, 2 is almost stable than 1 since 1‘s behaviour depends on OS side and it also depends on devices,(and OSs).

[Appium]See the screenshots and source on offline after tests failing

Almost software engineers take a bunch of time to investigate the cause when automated tests fail.
And they try to make sure whether the error is test code itself or product code. In the case, helpful error messages and additional information help us so much and save time for the investigation.

In this article, I explain some tips to make such investigation comfortable and show you a helpful app for it.

The repository is: https://github.com/KazuCocoa/appium-source-viewer

What kind of data do you get when tests fail?

Almost case, guys, use GUI testing tools like Appium, get screenshots when tests fail. Also. Some guys get videos as an additional information as well. They’ve become common in the mobile testing world recently.

By the way, can you find the way to fix the fail only from the screenshots or videos?

If your automated test code uses displayed words to find elements or some actions, you probably fix the test code from them. But, using resource-id for Android and accessibility identifier for iOS are common recently, and they can’t find from screenshots or videos because they are embedded in code level. Not for humans. In this case, you must find elements in code level and you also must run again to make sure the test code fixed.

The time is sometimes dull and wast. Also, we must repeat launching the test app and go to the target view to see view hierarchy by uiautomatorviewer, for example. The activity takes a bunch of time.

Thus, if we can get the hierarchy and view at the same time and we can see them easily in the investigation, the time will be short.

Get the source

To achieve it, I strongly recommend you to get page_source as well as screenshots when tests fail.

The page_source looks like:

  <XCUIElementTypeApplication type="XCUIElementTypeApplication" name="UICatalog" label="UICatalog" enabled="true" visible="true" x="0" y="0" width="375" height="667">
    <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="0" width="375" height="667">

Espresso or EarlGrey get such results and show us as their results. So, we can understand why the tests failed and which elements should we get or something… (XCUITest can’t get such information, I think…)

Screenshot x Source

Only getting source is a bit difficult to image and understand the target view from it since it is just XML.

To reduce such difficulty, we can use visualisation tools like Appium-Desktop.

Offline x Screenshot x Source

Appium Desktop is so helpful to see elements mapping to the view. But the tool requires network connection between Appium server and test targets.

So, I developed a tool which can map a screenshot and its source, and visualise us like Appium Desktop. We can see some highlights in the screenshot and the source equivalent each other.


The repository again: https://github.com/KazuCocoa/appium-source-viewer

The tool will help us to find the cause and how we can fix it only for failed test data, the screenshot and its source information.

I’ve put the usage in the README, but you can use the app following:

  1. Download the binary from release
  2. Unzip and copy the app in Application
  3. Set a screenshot path and a source path
  4. Reload from reload icon

I’ve checked only on macOS, but it’s Electron-based application. So, I guess it can work on windows, too.


I put some tips to make fix failed test easy and the app to help it.

Have a good testing!


こんばんは。Selenium/Appium Advent Calendar 2017の15日目の記事です。




リポジトリはこちら => https://github.com/KazuCocoa/appium-source-viewer




表示されている文字だけを見ているのであれば修正できる可能性はあるでしょう。ただ、例えばAndroidだと resource-id 、iOSだと accessibility identifier を使うことが普通になっている場合は、スクリーンショットを取得したとしても該当しそうな箇所をその表示のみから追うのはキツいのではないでしょうか。ソースコードを確認し、再度繰り返し実行し、調整していくことも多いのではないでしょうか。

とても時間が勿体無いですね。 どこが失敗 し、 どう修正すべきか を教えてくれるテスト結果であれば、この時間は短縮でき、楽に問題を修正することができるでしょう。


どこが失敗 し、 どう修正すべきか を知る手段として、テスト失敗時の情報として page_source の情報は1つの役立ち情報でしょう。例えば以下な感じのXMLです。

  <XCUIElementTypeApplication type="XCUIElementTypeApplication" name="UICatalog" label="UICatalog" enabled="true" visible="true" x="0" y="0" width="375" height="667">
    <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="0" width="375" height="667">


スクリーンショット x source



そんな時、例えばAppium-Desktopのようなツールを利用できたらどうでしょう? 視覚的にスクリーンショットから該当するsourceの要素を確認できる ようになり、だいぶ問題を見つけることが楽になるのではないでしょうか。

オフライン x スクシーンショット x source

便利だろうということで作って見ました。Appium Desktopを参考に、オフラインで使える形にしてみました。



再度、リポジトリはこちら => https://github.com/KazuCocoa/appium-source-viewer


例えばAndroidだと resource-id 、iOSだと accessibility identifier を使うことが普通になっている場合は、スクリーンショットを取得したとしても該当しそうな箇所をその表示のみから追うのはキツいのではないでしょうか。ソースコードを確認し、再度繰り返し実行し、調整していくことも多いのではないでしょうか。


使い方はREADMEに書いているのですが、 releaseからバイナリを取得して、macOSの Application ディレクトリに .app を移動し、アプリを実行してください。そこに、スクリーンショットへのパスと、sourceへのパスを指定、画面をreloadすると使うことができます。




Tips for UI/Scenario Tests: Recording screens and getting view hierarchy

When we run UI related tests, debugging failing test is one of the most difficult and need a bunch of time task. To make it easier, we usually take screenshot, capture videos and make error report helpful.

Taking screenshot is very famous, and I skip it.



Android provide screenrecord command to record a video for Android 4.4+.
I’ve implemented a bit helpful library, named droid_adbs

In the library, you can record video like the following. record.start call the screenrecord command in forked process. So, you can also start recording in setup and finish it in teardown.

require 'test_helper'

class DroidAdbsCommonsRecordTest &lt; Minitest::Test
  def test_record
    record = ::DroidAdbs::ScreenRecord::Recording.new

    sleep 10


    # Should wait to finish exporting recorded file
    sleep 1

    assert File.exist? &quot;./droid_adbs_video.mp4&quot;

    File.delete &quot;./droid_adbs_video.mp4&quot;


For Simulator, we can capture video easily with the following method.

xcrun simctl io booted recordVideo capture.mov


More or less, recording video increases devices/machines load. So, I recommend recording screens only you need. For example, once run your test suite and retry failed tests with enable recording the screen then.

Capture view hierarchy when test failed

With ruby_lib and Appium x RSpec

RSpec.configure do |c|
  c.after(:example, type: :feature) do |example|
    if example.exception
      # capture screen
      view_hierarchy = source # source is getting view hierarchy command
      # Save view_hierarchy in particular files.


  • We can get hint to finding elements.


  • We can see view hierarchy by default.


  • I’m not sure we can get such information from error result.


Helpful error results decrease a bunch of time to debug and detect the cause.

try reportportal

I tried reportportal to research awesome extensible reporting system. The framework provided by Docker and it’s very easy to try demo app via docker-composer

I know of Allure2 and it also awesome.

The following is a capture image.

[Swift] Identify not XCTest against XCUITest and EarlGrey


XCTAssert(NSClassFromString("XCTest") != nil)
XCTAssert(NSClassFromString("XCTestCase") != nil)
XCTAssert(ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil)

などを使い、XCTestである場合はmockしたAppDelegateを使うなどの対策を行うことがあります。ただ、この場合だと、 XCUITestEarlGrey によるテストを行うときもこの判定に引っかかります。




XCTAssert(ProcessInfo.processInfo.environment["EarlGrey"] == "true")