Enosh Joel Justin
Enosh Joel Justin

Reputation: 21

How to implement appium's new feature of mobile:getContexts for android hybrid automation

Appium introduced a feature to collect details of webview using mobile command mobile:getContexts. Using this feature i want to rule out the detached window from the webview so i can switch to the actual needed window. How do i do that in java? how do i filter the response of driver.executeScript("mobile:getContexts") and validate the value of key attached. Thank you.

Upvotes: 1

Views: 388

Answers (1)

Venkatesh Kallepalli
Venkatesh Kallepalli

Reputation: 11

Please use the below approach for the latest appium v1.22+,

//getContext
String currentContext = (String) appiumDriver.execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue();
System.out.println("getContext:"+currentContext);

//SwithToContext (NATIVE_APP)
appiumDriver.execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", "NATIVE_APP"));

//SwithToContext (WEBVIEW)
appiumDriver.execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", "WEBVIEW"));

Upvotes: 1

Related Questions