自動化するコンテキストを設定します。Appium を使用してハイブリッドモバイルアプリをテストする場合に使用します。

詳細はこちら:https://appium.dokyumento.jp/docs/en/commands/context/set-context/

使用方法

                    .appium.setContext(context, [callback])
                

module.exports = {
  'switch to webview context': async function (app) {
    app
      .waitUntil(async function() {
        // wait for webview context to be available
        // initially, this.getContexts() only returns ['NATIVE_APP']
        const contexts = await this.appium.getContexts();

        return contexts.length > 1;
      })
      .perform(async function() {
        // switch to webview context
        const contexts = await this.appium.getContexts();  // contexts: ['NATIVE_APP', 'WEBVIEW_<id>']
        await this.appium.setContext(contexts[1]);
      });
  },

  'switch to native context': function (app) {
    app.appium.setContext('NATIVE_APP');
  }
};

パラメータ

名前 説明
context 文字列

切り替えるコンテキスト名 - 使用可能なコンテキストを表す文字列。

callback
オプション
関数

コマンドが完了したときに呼び出されるオプションのコールバック関数。

参照