[iOS][Appium]Process Arguments by Appium for XCUITest, iOS

Today, I’d like to leave a tip. I’ve implemented test cases using this article for over 3 years. It helped us to control test environment more stable and fast.

XCUITest can set process arguments for Instrumentation.

According to https://github.com/appium/appium-xcuitest-driver#desired-capabilities, you can set processArguments in capability and the test app can get the value via ProcessInfo.

You can set the value via below’s Environment Variables.

Screen Shot 2018-06-10 at 20.54.14


Next code is Ruby based.

  caps: {
    platformName: :ios,
    automationName: 'XCUITest',
    processArguments: {
      env: {
        "PROCESS_VALUE": "process value"
  appium_lib: {

By processArguments, you can set the environment variables.

Test app

The processArguments can get via ProcessInfo like below.

import Foundation

let env = ProcessInfo.processInfo.environment
env["PROCESS_VALUE"] // "process value"

Next image isn’t the above. But I believe it help you understand ProcessInfo.processInfo.environment.
Screen Shot 2018-06-10 at 20.15.50

You can control some behaviour using the argument. For example, URLs or interval for network.


[iOS]xccov and JSON format

Before Xcode 9.2, we can get formatted coverage data using https://github.com/SlatherOrg/slather, for example. The library formats llvm-cov.

But from Xcode 9.3, xccov is introduced officially. The command can run via xcrun.

xccov is a new command-line utility for inspecting the contents of Xcode coverage reports. It can be used to view coverage data in both human-readable and machine parseable format. To learn more, enter man xccov in Terminal. (37172926)

I tried the feature with https://github.com/KazuCocoa/test.examples and I put a simple Ruby gem script to get the target name and the line coverage.


$ git clone https://github.com/KazuCocoa/test.examples && cd test.examples
$ xcodebuild -workspace test.examples.xcworkspace -scheme test.examples -derivedDataPath Build/ -destination 'platform=iOS Simulator,OS=11.3,name=iPhone 7' -enableCodeCoverage YES clean build test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
$ xcrun xccov view --only-targets --json Build/Logs/Test/*.xccovreport > result.json


We can get some kind of format.

# Output: https://gist.github.com/KazuCocoa/40eaa3ac9de5e52c1a3795c49657dd4b
$ xcrun xccov view --json Build/Logs/Test/*.xccovreport | jq .

# Output: https://gist.github.com/KazuCocoa/879554e02934d368f976959d3f8cec4b
$ xcrun xccov view --only-targets --json Build/Logs/Test/*.xccovreport | jq .

Parse the JSON with Ruby

parsed = Xccov::Parse.new(file: './result.json')
parsed.targets_line_coverage["test.examples.app"] #=> 0.35


From Xcode 9.3, we can get formatted coverage data using xcrun command. I’ve seen some scripts use Slather and Nokogiri to handle XML format and collect them. But the script will be more simple. Does this make you happy?

iOS 11 Programmingを今更だけれど読んだ




iOS 11 Programming

iOS 11 Programming

  • 著者:堤 修一,吉田 悠一,池田 翔,坂田 晃一,加藤 尋樹,川邉 雄介,岸川 克己,所 友太,永野 哲久,加藤 寛人,
  • 製本版,電子版
  • PEAKSで購入する



[Appium]get performance for iOS

So long ago, I tried to monitor iOS performances using instrument commands. But I gave up once because of host machine’s load.

But https://github.com/appium/appium-xcuitest-driver/pull/637 is created and that is awesome…

I just remember seeing the PR and I’ve published this article in my memory…

[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 🙂

[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")



[iOS]Large Photo Libraries for Testing

from https://developer.apple.com/videos/play/wwdc2017/505/

If you’d like to test with a large number of photos, you can generate dummy photos by https://developer.apple.com/sample-code/wwdc/2017/Creating-Large-Photo-Libraries-for-Testing.zip . Download it and run on the target device.

The app is presented in https://developer.apple.com/videos/play/wwdc2017/505/ .


[Android][iOS]Awesome tips

Headless simulators

Appium(with WDA) can run headless simulators isHeadless against Xcode9+.
Awesome: https://github.com/appium/appium-xcuitest-driver/pull/472/files

composer, swarmer and mainframer

Replace Spoon for Espresso.

[iOS]What’s new Testingを見た

What’s new Testingを見た。



  • multiple appのテスト、URLを引数で与えることできるのね


  • Accessibility Dataのところで説明しているsnapshot、WebDriverAgentが使っているやつぽいな
  • おー。いちいちsnapshot取得する必要がなくなるのか。実行時間改善しそう



  • 要素の検索で全捜査でなくて最初にマッチしたものだけさっと返すようにした、という話だけれど、ようやくという感じ。


  • ここら辺は元からそうなのでそうよねという感じだ。
  • ここはどこまで厳密に書くかはどれだけ内部実装と結合を強くするかの問題ですね。Espressoでも同じ問題をもつ。


  • 地味に嬉しい

  • Activity styleの書き方、Cucmberとかイメージすると良さそう。stepsにいろんな処理を入れて、シナリオはstepsを並べて記述するような感じが使い方として近そうだ。

  • 非同期の奴も良さそう。XCTestなので、XCUITestでも使えるし。
  • snapshotのところはほんといろんな3rd partyも恩恵受けるだろうし、良いことづくしな気がする。けれど、これはXcode8でないと使えないOSテストするときは恩恵受けられないので、完全に恩恵を教授できるのは数年後かな…