.setContext() 建議編輯
設定要自動化的上下文。在測試使用 Appium 的混合行動應用程式時使用。
更多資訊請參閱:https://appium.dev.org.tw/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 選填 |
函式 | 可選的回呼函式,在指令完成時呼叫。 |