DEV Community

wave1008
wave1008

Posted on

How to select a screen element in Shirates

This article is an introduction of how to use Shirates, a mobile testing automation tool.

How to select a screen element

You can select by following methods.

  • text
  • accessibility(content-desc)
  • id(resource-id)
  • class
  • xpath

By text

You can select an element by simple code.

select("text")
Enter fullscreen mode Exit fullscreen mode

You can also select an element with scrolling as follows.

selectWithScrollDown("text")
Enter fullscreen mode Exit fullscreen mode

By accessibility(content-desc)

You can select an element by content-desc with putting prefix "@" before the content-desc value.

select("@Navigate up")
Enter fullscreen mode Exit fullscreen mode

By id(resource-id)

You can select an element by resource-id with putting prefix "#" before the id value.

select("#id1")
Enter fullscreen mode Exit fullscreen mode

By class

You can select an element by className with putting prefix "." before the class value.

select(".android.widget.TextView")
Enter fullscreen mode Exit fullscreen mode

By xpath

You can select an element by xpath.

select("xpath=//*[@resource-id='android:id/icon']")
Enter fullscreen mode Exit fullscreen mode

See select for detail.


Material

You can get complete sample project from [https://github.com/wave1008/shirates-samples-selectors].

SelectorTest

import org.junit.jupiter.api.Order
import org.junit.jupiter.api.Test
import shirates.core.driver.commandextension.*
import shirates.core.testcode.UITest

class SelectTest : UITest() {

    @Test
    @Order(10)
    fun selectByText() {

        scenario {
            case(1) {
                action {
                    it.select("Network & internet")
                }.expectation {
                    it.textIs("Network & internet")
                }
            }
            case(2) {
                action {
                    it.selectWithScrollDown("System")
                }.expectation {
                    it.textIs("System")
                }
            }
        }
    }

    @Test
    @Order(20)
    fun selectByAccessibility() {

        scenario {
            case(1) {
                condition {
                    it.tapWithScrollDown("System")
                }.action {
                    it.select("@Navigate up")
                }.expectation {
                    it.accessIs("Navigate up")
                }
            }
        }
    }

}
Enter fullscreen mode Exit fullscreen mode

Test Result

Test Result


Conclusion

In Shirates, you can select a screen element in simple description.

Top comments (0)