Hello Gurus;
I was working on our mobileweb automation since a considerable time. Even though the component software(s) give some issue now and then, but this time it is more like a black box, and I need the community help.
**case "Android":**
try {
UiAutomator2Options andyOptions = new UiAutomator2Options();
andyOptions.setDeviceName(deviceName);
andyOptions.setPlatformName(platform);
andyOptions.setAutomationName("UiAutomator2");
andyOptions.setUdid(udId);
andyOptions.setPlatformVersion(platformVersion);
andyOptions.setCapability("browserName", browser);
andyOptions.setCapability("fastReset", "true");// prerequisite for 'accept all alerts'
andyOptions.setCapability("autoGrantPermissions", "true");// accept all alerts
andyOptions.setCapability("webviewConnectTimeout", "50000");
andyOptions.setCapability("autoWebview", true);// automatically shift to web view, almost unnecessary for Android
return new AndroidDriver(url, andyOptions);
} catch (Exception e) {
System.out.println("Exception during returning AndroidDriver");
// TODO Auto-generated catch block
e.printStackTrace();
}
**case "iOS":**
try {
XCUITestOptions iOsOptions = new XCUITestOptions();
iOsOptions.setPlatformName(platform);
iOsOptions.setDeviceName(deviceName);
iOsOptions.setAutomationName("XCUITest");
iOsOptions.setUdid(udId);
iOsOptions.setPlatformVersion(platformVersion); // is it needed ?
iOsOptions.setCapability("browserName", browser);
iOsOptions.setCapability("autoAcceptAlerts", "true"); // accept all alerts
iOsOptions.setCapability("includeSafariInWebviews", true); // make WebView context to be visible
iOsOptions.setCapability("webviewConnectTimeout", "50000"); // make WebView context to be visible
iOsOptions.setCapability("autoWebview", true);// automatically shift to web view
return new IOSDriver(url, iOsOptions);
} catch (Exception e) {
System.out.println("Exception during returning the IOSDriver");
// TODO Auto-generated catch block
e.printStackTrace();
}
default:
throw new Exception("invalid platform");
}
}
I think main problem is iOsOptions.setCapability(“appium:autoWebview”, true); because that capability makes appium automatically start in WebContext and if the app you are testing doesn’t have web context by default then appium will throw an error. In this case since you are testing browser directly I guess WebContext is the default context?
Since Appium Java Client 9.2.3 all desired capabilities must have prefix:
“appium:” try to change those to:
andyOptions.setCapability("appium:browserName", browser);
andyOptions.setCapability("appium:fastReset", "true");// prerequisite for 'accept all alerts'
andyOptions.setCapability("appium:autoGrantPermissions", "true");// accept all alerts
andyOptions.setCapability("appium:webviewConnectTimeout", "50000");
andyOptions.setCapability("appium:autoWebview", true);
iOsOptions.setCapability("appium:browserName", browser);
iOsOptions.setCapability("appium:autoAcceptAlerts", "true"); // accept all alerts
iOsOptions.setCapability("appium:includeSafariInWebviews", true); // make WebView context to be visible
iOsOptions.setCapability("appium:webviewConnectTimeout", "50000"); // make WebView context to be visible
iOsOptions.setCapability("appium:autoWebview", true);
Can you try to run with code with iOsOptions.setCapability(“appium:autoWebview”, true);
If that doesn’t work try again to run the test with:
iOsOptions.setCapability(“appium:autoWebview”, false);
@derolk
Thanks for you kind input.
I did the change, the AppiumDriver for both Android and iOS are created and retrieved perfectly, without throwing an Exception.
During the previous 6 months this code worked just fine. It must be a change enforced newly with Selenium and Appium Java-Client software components.
I thought, for Android, WEB_VIEW is default and for iOS, it need be shifted from NATIVE. It is completely strange how new things get enforced with each release of software components !! If what I am thinking is true, what is the capability of WEB_VIEW is useful, anyways ??
Your suggestion saved me a ton of time.
Thanks again,