Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Test API proposal #4

Open
Ashraf-Ali-aa opened this issue Mar 5, 2020 · 0 comments
Open

UI Test API proposal #4

Ashraf-Ali-aa opened this issue Mar 5, 2020 · 0 comments

Comments

@Ashraf-Ali-aa
Copy link

@michallaskowski Here is an API proposal for a standardised UI test framework which is heavily influenced by XCUITest, can I have your thoughts?

package com.laskowski.kuiks

import kotlin.time.Duration
import kotlin.time.ExperimentalTime

typealias TimeInterval = Double

interface UIElement: UIElementInteraction, UIElementWaitForElement {
    /**
     * Check if element exists
     */
    val exists: Boolean

    val isEnabled: Boolean

    /**
     * Check if element is hittable
     */
    val isHittable: Boolean

    val isSelected: Boolean

    val isVisible: Boolean

    /**
     * Print out view hierarchy
     */
    val debugDescription: String

    fun element(): UIElement

    val hasKeyboardFocus: Boolean

    fun isKeyboardKeyAvaliable(key: String): Boolean

    fun dismissKeyboard()

    val label: String

    val identifier: String

    val value: String
}

interface UIElementInteraction {
    fun tap()

    fun forceTap()

    fun doubleTap()

    fun press(forDuration: TimeInterval)

    fun press(forDuration: TimeInterval, thenDragTo: UIElement)

    fun swipeUp()

    fun swipeDown()

    fun swipeLeft()

    fun swipeRight()

    fun pinch(scale: Double, velocity: Double)

    fun rotate(rotation: Double, withVelocity: Double)
    
    /**
     * Scroll to Element
     */
    fun scrollTo(targetElement: UIElement, scrollView: UIElement, direction: ScrollDirection, maximumAttempts: Int, scrollDistance: Double)

    fun typeText(text: String)

    fun adjustSlider(position: Double)
}

interface  UIElementWaitForElement {
    fun waitForElementToExistence(timeout: TimeInterval): Boolean

    fun waitForElementToBecomeHittable(timeout: TimeInterval): Boolean

    fun waitForElementToBecomeSelected(timeout: TimeInterval): Boolean
}

interface UIElementWaitForMultipleElement {
    fun waitForMultipleElementsToBecomeInToExistence(timeout: TimeInterval): Boolean

    fun waitForMultipleElementsToBecomeUnavailable(timeout: TimeInterval): Boolean
}

enum class ScrollDirection {
    down,
    up,
    left,
    right
}

enum class Timeout (val rawValue: Double) {
    ExtraSmall(1.0),
    Small(3.0),
    Medium(5.0),
    Large(10.0),
    ExtraLarge(15.0),
    ExtraExtraLarge(30.0),
    ExtraSuperLarge(45.0),
    Mega(240.0);

    companion object {
        operator fun invoke(rawValue: TimeInterval) = Timeout.values().firstOrNull { it.rawValue == rawValue }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant