UiAutomator2—By、BySelector
By和BySelector所实现的功能相同,API也基本上相同,By是对BySelector的简化,官网是这样解释的:
By is a utility class which enables the creation of BySelectors in a concise manner.
Its primary function is to provide static factory methods for constructing BySelectors using a shortened syntax. For example, you would use findObject(By.text(“foo”)) rather than findObject(new BySelector().text(“foo”)) to select UI elements with the text value “foo”.
大意为:By是BySelector的一个实用类,By的主要功能是提供静态方法并使用简单的语法去构建BySelector进而进行控件的筛选。例如:
当你寻找一个text为foo
的控件时,BySelector的写法为:
findObject(new BySelector().text(“foo”))
而By则可以对之进行简化,可以写为: