事前定義ステップにないアクションや検証を行いたい場合に、Appium を用いたスクリプトを実行できる「カスタムアクション(モバイル)」ステップを使用します。複数のモバイルコマンドをバッチ実行でき、JS パラメーターも利用可能です。カスタムアクション(モバイル)は TMA でのみ完全にサポートされます。サードパーティのグリッドでは未サポートです(例):
- Browserstack では、サーバーが
--allow-insecureオプション付きで起動していない旨のエラーメッセージが返ります。 - Headspin では次が返ります:
An unknown server-side error occurred while processing the command. Original error: The software keyboard cannot be hidden
VMG でサポートされる Appium メソッド
次の Appium メソッドがサポートされています:
performActionsfindElementfindElementssendKeyshideKeyboardgetWindowRect
findElement(s) は strategy に "text" を使用できません。一般的には "label" や "value" での検索が有効です。
カスタムアクション(モバイル)ステップを追加する
- 追加したい位置の矢印()または + にカーソルを合わせます。
- “M”(Testim 定義済みステップ)をクリックし、メニューを開きます。

- Actions を展開し、Add custom action を選択します。

- Name にわかりやすい名前を入力します。
- 共有ステップとして再利用したい場合は、デフォルトのチェックを保持し、Select shared step folder から保存先フォルダーを選びます。共有不要ならチェックを外します。共有ステップの詳細は グループ を参照してください。
- Create Step をクリックします。関数エディターと右側の Properties パネルが開きます。

-
Properties の Description を必要に応じて編集します(既定: Run shared action / Run action)。
-
必要なパラメーターを定義します。
-
+ PARAMS をクリックします。
-
JS を選択して JavaScript パラメーターを追加します。
-
任意のプロパティを設定します。
-
When this step fails – 失敗時の動作を指定します。
-
When to run step – 実行条件を指定します(Conditions 参照)。
-
Override timeout – タイムアウトの上書き(ミリ秒)を指定します。
-
function テキストボックスに JS コードを記述します。定義したパラメーターを参照できます。
-
戻る矢印でエディターに戻ります。

ステップが作成されます。

例
デバイスのナビゲーションバーを引き下げる
performActions の使用例です。画面左上から 100ms 待機後、100 ピクセル下方向へドラッグして指を離します。
const start_x = 50;const start_y = 1;const end_x = 50;const end_y = 2000;
await DRIVER.performActions([ { type: 'pointer', id: 'finger1', parameters: { pointerType: 'touch' }, actions: [ { type: 'pointerMove', duration: 0, x: start_x, y: start_y }, { type: 'pointerDown', button: 0 }, { type: 'pause', duration: 100 }, { type: 'pointerMove', duration: 500, x: end_x, y: end_y }, { type: 'pointerUp', button: 0 }, ], },]);xpath でボタン要素を探す
findElement の使用例です。
const el = await DRIVER.findElement( 'xpath', '//XCUIElementTypeApplication/XCUIElementTypeWindow/XCUIElementTypeOther/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeCollectionView');/*const e2 = await DRIVER.findElement('class name', "XCUIElementTypeButton");*/キーボード入力
sendKeys と hideKeyboard の使用例です。キーボード表示中に文字列を入力し、その後キーボードを隠します。
await DRIVER.sendKeys('abcdef');await DRIVER.hideKeyboard();