Thursday 22 September 2016

Helper methods Appium 1.6.0 Beta

  // iOS        // Find element in table cell         driver.findElementByXPath("//XCUIElementTypeCell/XCUIElementTypeStaticText[@name='some-id']"));


        //   Print source of screen visible        System.out.println(driver.getPageSource());

        //default timeout for all commands executed using this driver. can be overridden using explicit wait        driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

        //EXPLICIT wait for element for x seconds        //  If explicit wait > implicit wait , then greater driver will default to greater wait period        int seconds= 3;
        WebDriverWait wait = new WebDriverWait(driver, seconds);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("some-id")));

//        UIAutomation(IOS)//        Find visibility of element using XPath        xpath = "UIATableCell/UIAStaticText[@label='Family'][@visible='true']";
        driver.findElementByXPath(xpath);

        click on first table cell (xpath may change based on your application)
        xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]").click

2) Migration IOS Appium tests from UIAutomation to XCUITest

Most of the Elements have changed after Instruments have moved form UIAutomation to XCUITest
Hence all references using classnames and xpaths in Appium Automation must be updated to run from Appium 1.6.0 onwards
at the moment its in beta
Look at installation procedure here - http://mytechlifez.blogspot.co.uk/2016/09/appium-1.6.0-beta1-installation-xcode8-ios10.html

Table elements

Table / Row
UIATableview -> XCUIElementTypeTable
UItableviewcell -> XCUIElementTypeCell

Choose row 1 in a table using xpath- 
"///XCUIElementTypeTable[1]/XCUIElementTypeCell[1]/XCUIElementTypeStaticText[1]"
"//XCUIElementTypeCell[1]/XCUIElementTypeStaticText[1]"

XCUItest iOShttps://discuss.appium.io/t/appium-xcuitest-example-how-to-get-started-appium-using-xcuitest-for-real-device/12415/4//Migrating from UIAutomation to XCUItestUIAButton changes into  XCUIElementTypeButton
UIA***    --> XCUIElementType***
UIAStaticText -> XCUIElementTypeStaticText
UIATableView -> XCUIElementTypeTable
UIANavigationBar -> XCUIElementTypeNavigationBar

Buttons


"UIABUtton" is replaced by "XCUIElementTypeButton"

1) Appium 1.6.0 beta1 Installation

I have managed to run my IOS tests on XCUItest using below changes.
Elements have to migrated from UIA to XCUI elements

Inorder to run appium on 1.6.0 beta 1 for ios 10 and xcode 8
use below settings

[caps]
platformName = "iOS"
orientation = "PORTRAIT"
platformVersion = "10.0"
deviceName ="iPhone Simulator"
noReset = "false"
automationName = "xcuitest"
appiumVersion = "1.6.0-beta1"
app="<app_path>/<app_name>.app"
[appium_lib]

Installation

npm uninstall appium
npm install appium@1.6.0-beta1

npm install -g appium-xcuitest-driver
brew install carthage

Install carthage dependency manager

Error : Fetching dependencies\nPlease make sure that you have Carthage installed (https://github.com/Carthage/Carthage)\nNote: We are expecting that carthage installed in /usr/local/bin/\n',
Solution : brew install carthage








Xcode 8 Installation : 
download xcode
unzip the xcode file 
Rename old /Applications/Xcode.app to /Applications/Xcode7.app(incase you still want to keep it)
Drag new Xcode app to /Applications/Xcode.app
Open Xcode and install it 







Other fixes: 

If you encounter issues  check here - https://github.com/appium/appium/issues/6853
I had to manually run bootstrap as mentioned in above link 
cd ~/.npm-global/lib/node_modules/appium-xcuitest-driver/WebDriverAgent
sh Scripts/bootstrap.sh 


To Properly install node check this link - https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md