Is there a way we can convert xpaths?

Appium 1.6.0

Is there a way to directly convert Xpaths in UIAAutomation framework to XCUITest framework?

Currently, it looks like Appium 1.6.x does a pretty decent job of converting them for you. But, there were a few occasions where it didn’t work for me, and I wanted to retain compatibility with older version of iOS xpaths in my code still. So luckily, my appium framework is defined with a common class at it’s base for all controls. So I added a method to do the conversion that uses an ugly replace() action for xpaths and classNames…

private By convertForXCUITest(By iosLocator) {
    String[] parts = iosLocator.toString().split(": ");

    if (parts.length > 1) {
        String newValue = parts[1].
                replace("UIAStaticText", "XCUIElementTypeStaticText").
                replace("UIAButton", "XCUIElementTypeButton").
                replace("UIATableCell", "XCUIElementTypeCell").
                replace("UIANavigationBar", "XCUIElementTypeNavigationBar").
                replace("UIATextField", "XCUIElementTypeTextField").
                replace("UIAActivityIndicator", "XCUIElementTypeActivityIndicator").
                replace("UIASecureTextField", "XCUIElementTypeSecureTextField").
                replace("UIACollectionView", "XCUIElementTypeCollection").
                replace("UIACollectionCell", "XCUIElementTypeCell").
                trim();

        switch (parts[0]) {
            case "By.xpath":
                return By.xpath(newValue);

            case "By.className":
                return By.className(newValue);

            default:
                return iosLocator;
        }
    } else {
        return iosLocator;
    }
}