NOTE! You are browsing legacy documentation. For latest visit docs.nativescript.org.

NativeScript Angular

Features

  1. Cross-platform locators

    Imagine that you want to select textfield on iOS and Android and provide an input. The element's native class is different on iOS and Android. For example, textfield class on both iOS is XCUIElementTypeTextField and android.widget.EditText on Android, so the locators define all common elements and corresponding classes per OS to ease the selection of particular element. Example:

    const usernameField = await driver.findElementByClassName(driver.locators.getElementByName("textfield"));
    await usernameField.click();
    
  2. Find strategies: findElementByText, findElementByClassName, findElementByAccessibilityId, findElementByXPath, etc.

    Examples:

    <!-- home-page.xml -->
    ...
    <Button automationText="customLogOut" tap="" text="Log out (Custom)"></Button>
    ...
    
    import { AppiumDriver, createDriver, SearchOptions, Direction } from "nativescript-dev-appium";
    
    const driver: AppiumDriver = await createDriver();
    
    // select an element by using the accessibility ID assigned by the automationText property in the .xml
    const button = await driver.findElementByAccessibilityId("customLogOut");
    
    // select an element using its native class 
    let listView;
    if (isAndroid) {
        listView = await driver.findElementByClassName("android.widget.FrameLayout");
    }
    else {
        listView = await driver.findElementByClassName("XCUIElementTypeCollectionView");
    }
    
    // select an element using XPath
    let userNameLabelElement;
    if (isAndroid) {
        userNameLabelElement = "[@text='Nativescript User']";
    } else {
        userNameLabelElement = "[@name='Nativescript User']";
    }
    const userNameLabel = await driver.findElementByXPath("//" + driver.locators.getElementByName("label") + userNameLabelElement);
    
  3. Actions: tap, click, doubleTap, hold, etc. Most of them are self described.

    Examples:

    const item = await driver.findElementByText("Special Item 111", SearchOptions.exact);
    await item.click();
    await item.doubleTap();
    await item.hold(2);
    
  4. Gestures: scroll, scrollTo, swipe, drag, etc.

    Examples:

    // Imagine that you have a listview with items that can be swiped
    const item = await driver.findElementByText("Special Item 111", SearchOptions.exact);
    await item.swipe(Direction.right);
    
  5. Cross-platform element abstraction with exists, waitForExist, waitForExistNot, location, isDisplayed, size, text properties

    Examples:

    const item = await driver.findElementByText("Special Item 111", SearchOptions.exact);
    const exist = await item.exists();
    const rectangle = await item.getRectangle();
    const width = rectangle.width;
    
  6. Ability to turn on/off “Don’t keep activities” setting in the Developer options for Android
  7. Direct access to driver

    Examples:

    if (driver.isAndroid) {
        const wd = driver.wd();
        const action = new wd.TouchAction(driver.driver);
        // Drag item on Android
        action.longPress({ x: 200, y: 200 })
            .wait(2000)
            .moveTo({ x: 200, y: 400 })
            .release();
        await action.perform();
    } else {
        // Drag item on iOS
        await driver.driver.execute('mobile: dragFromToForDuration', {
            duration: 2.0,
            fromX: 100,
            fromY: 105,
            toX: 100,
            toY: 242
        });
    }
    
    
  8. Typings - very useful when start writing test and you are not aware of nativescript-dev-appium methods' definitions and available parameters.
  9. Async/Await
  10. Open source cloud builds integration, i. e. Sauce Labs
  11. Image comparison of: screen, rectangle, element.

    Examples:

    // Compare a specific element
    const selected = await driver.findElementByText("Item 0", SearchOptions.exact);
    
    // The second parameter is the name of the image.
    // The location of the image is specified by '--imagesPath "someName/iPhone X"' flag.
    // Which provides relative path to e2e/resources/images folder.
    // Actual image location e2e/resources/images/someName/iPhone X/selectedState.png
    const selection = await driver.compareElement(selected, "selectedState");
    
    // Compare the current screen of the app
    const screen = await driver.compareScreen("screenImage");
    
  12. [WIP] Ability to verify animations/transitions through video/images; please refer to frame-comparer