提交 290d9dc8 编写于 作者: E ester.zhou

update doc

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 0481bc38
...@@ -16,13 +16,13 @@ import {UiDriver,BY,MatchPattern} from '@ohos.uitest' ...@@ -16,13 +16,13 @@ import {UiDriver,BY,MatchPattern} from '@ohos.uitest'
The UiTest framework provides a wide range of UI component feature description APIs in the **By** class to filter and match components. The UiTest framework provides a wide range of UI component feature description APIs in the **By** class to filter and match components.
The API capabilities provided by the **By** class exhibit the following features: The API capabilities provided by the **By** class exhibit the following features:
1.Allows one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component. - Allows one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component.
2.Provides multiple match patterns for component attributes. - Provides multiple match patterns for component attributes.
3.Supports absolute positioning and relative positioning for components. APIs such as **isBefore** and **isAfter** can be used to specify the features of adjacent components to assist positioning. - Supports absolute positioning and relative positioning for components. APIs such as **isBefore** and **isAfter** can be used to specify the features of adjacent components to assist positioning.
All APIs provided in the **By** class are synchronous. You are advised to use the static constructor **BY** to create a **By** object in chain mode, for example, **BY.text('123').type('button')**. All APIs provided in the **By** class are synchronous. You are advised to use the static constructor **BY** to create a **By** object in chain mode, for example, **BY.text('123').type('button')**.
### enum MatchPattern ### enum MatchPattern
...@@ -92,7 +92,8 @@ Specifies the key attribute of the target component. ...@@ -92,7 +92,8 @@ Specifies the key attribute of the target component.
**Example** **Example**
``` ```
let by = BY.key('123') // Use the static constructor BY to create a By object and specify the key attribute of the target component. let by = BY.key('123') // Use the static constructor BY to create a By object and specify the key attribute
of the target component.
``` ```
...@@ -121,7 +122,8 @@ Specifies the ID property of the target component. ...@@ -121,7 +122,8 @@ Specifies the ID property of the target component.
**Example** **Example**
``` ```
let by = BY.id(123) // Use the static constructor BY to create a By object and specify the ID attribute of the target component. let by = BY.id(123) // Use the static constructor BY to create a By object and specify the ID attribute
of the target component.
``` ```
...@@ -208,7 +210,8 @@ Specifies the scrollable attribute of the target component. ...@@ -208,7 +210,8 @@ Specifies the scrollable attribute of the target component.
**Example** **Example**
``` ```
let by = BY.scrollable(true) // Use the static constructor BY to create a By object and specify the scrollable attribute of the target component. let by = BY.scrollable(true) // Use the static constructor BY to create a By object and specify the scrollable attribute
of the target component.
``` ```
### By.enabled ### By.enabled
...@@ -236,7 +239,8 @@ Specifies the enable attribute of the target component. ...@@ -236,7 +239,8 @@ Specifies the enable attribute of the target component.
**Example** **Example**
``` ```
let by = BY.enabled(true) // Use the static constructor BY to create a By object and specify the enable attribute of the target component. let by = BY.enabled(true) // Use the static constructor BY to create a By object and specify the enable attribute
of the target component.
``` ```
### By.focused ### By.focused
...@@ -264,7 +268,8 @@ Specifies the focused attribute of the target component. ...@@ -264,7 +268,8 @@ Specifies the focused attribute of the target component.
**Example** **Example**
``` ```
let by = BY.enabled(true) // Use the static constructor BY to create a By object and specify the focused attribute of the target component. let by = BY.enabled(true) // Use the static constructor BY to create a By object and specify the focused attribute
of the target component.
``` ```
### By.selected ### By.selected
...@@ -292,7 +297,8 @@ Specifies the selected attribute of the target component. ...@@ -292,7 +297,8 @@ Specifies the selected attribute of the target component.
**Example** **Example**
``` ```
let by = BY.selected(true) // Use the static constructor BY to create a By object and specify the selected attribute of the target component. let by = BY.selected(true) // Use the static constructor BY to create a By object and specify the selected attribute
of the target component.
``` ```
### By.isBefore ### By.isBefore
...@@ -320,7 +326,8 @@ Specifies the attributes of the component before which the target component is l ...@@ -320,7 +326,8 @@ Specifies the attributes of the component before which the target component is l
**Example** **Example**
``` ```
let by = BY.isBefore(by.text('123')) // Use the static constructor BY to create a By object and specify the attributes of the component before which the target component is located. let by = BY.isBefore(BY.text('123')) // Use the static constructor BY to create a By object and specify the attributes
of the component before which the target component is located.
``` ```
### By.isAfter ### By.isAfter
...@@ -337,7 +344,7 @@ Specifies the attributes of the component after which the target component is lo ...@@ -337,7 +344,7 @@ Specifies the attributes of the component after which the target component is lo
| Name| Type| Mandatory| Description | | Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------- | | ------ | ---- | ---- | -------------- |
| by | By | Yes | Attributes of the component after which the target component is located.| | by | By | Yes | Attributes of the component before which the target component is located.|
**Return value** **Return value**
...@@ -348,7 +355,8 @@ Specifies the attributes of the component after which the target component is lo ...@@ -348,7 +355,8 @@ Specifies the attributes of the component after which the target component is lo
**Example** **Example**
``` ```
let by = BY.isAfter(by.text('123')) // Use the static constructor BY to create a By object and specify the attributes of the component after which the target component is located. let by = BY.isAfter(BY.text('123')) // Use the static constructor BY to create a By object and specify the attributes
of the component after which the target component is located.
``` ```
## UiComponent ## UiComponent
...@@ -369,7 +377,11 @@ Clicks this component. ...@@ -369,7 +377,11 @@ Clicks this component.
**Example** **Example**
``` ```
await button.click() async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
await button.click()
}
``` ```
### UiComponent.doubleClick ### UiComponent.doubleClick
...@@ -385,7 +397,11 @@ Double-clicks this component. ...@@ -385,7 +397,11 @@ Double-clicks this component.
**Example** **Example**
``` ```
await buttont.doubleClick() async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
await buttont.doubleClick()
}
``` ```
### UiComponent.longClick ### UiComponent.longClick
...@@ -401,7 +417,11 @@ Long-clicks this component. ...@@ -401,7 +417,11 @@ Long-clicks this component.
**Example** **Example**
``` ```
await button.longClick() async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
await button.longClick()
}
``` ```
### UiComponent.getId ### UiComponent.getId
...@@ -423,7 +443,11 @@ Obtains the ID of this component. ...@@ -423,7 +443,11 @@ Obtains the ID of this component.
**Example** **Example**
``` ```
let num = await button.getId() async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
let num = await button.getId()
}
``` ```
### UiComponent.getKey ### UiComponent.getKey
...@@ -445,7 +469,11 @@ Obtains the key of this component. ...@@ -445,7 +469,11 @@ Obtains the key of this component.
**Example** **Example**
``` ```
let str_key = await button.getKey() async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
let str_key = await button.getKey()
}
``` ```
### UiComponent.getText ### UiComponent.getText
...@@ -467,7 +495,11 @@ Obtains the text information of this component. ...@@ -467,7 +495,11 @@ Obtains the text information of this component.
**Example** **Example**
``` ```
let text = await button.getText() async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
let text = await button.getText()
}
``` ```
### UiComponent.getType ### UiComponent.getType
...@@ -489,7 +521,11 @@ Obtains the type of this component. ...@@ -489,7 +521,11 @@ Obtains the type of this component.
**Example** **Example**
``` ```
let type =await button.getType() async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
let type = await button.getType()
}
``` ```
### UiComponent.isClickable ### UiComponent.isClickable
...@@ -511,11 +547,16 @@ Obtains the clickable status of this component. ...@@ -511,11 +547,16 @@ Obtains the clickable status of this component.
**Example** **Example**
``` ```
if(await button.isClickable()) async function demo() {
console.info('This button can be Clicked') let driver = UiDriver.create()
else let button = await driver.findComponent(BY.type('button'))
console.info('This button can not be Clicked') if(await button.isClickable()) {
console.info('This button can be Clicked')
}
else{
console.info('This button can not be Clicked')
}
}
``` ```
### UiComponent.isScrollable ### UiComponent.isScrollable
...@@ -537,10 +578,16 @@ Obtains the scrollable status of this component. ...@@ -537,10 +578,16 @@ Obtains the scrollable status of this component.
**Example** **Example**
``` ```
if(await scrollBar.isScrollable()) async function demo() {
console.info('This scrollBar can be operated') let driver = UiDriver.create()
else let scrollBar = await driver.findComponent(BY.scrollable(true))
console.info('This scrollBar can not be operated') if(await scrollBar.isScrollable()) {
console.info('This scrollBar can be operated')
}
else{
console.info('This scrollBar can not be operated')
}
}
``` ```
...@@ -563,10 +610,17 @@ Obtains the enable status of this component. ...@@ -563,10 +610,17 @@ Obtains the enable status of this component.
**Example** **Example**
``` ```
if(await button.isEnabled()) async function demo() {
console.info('This button can be operated') let driver = UiDriver.create()
else let button = await driver.findComponent(BY.type('button'))
console.info('This button can not be operated') if(await button.isEnabled()) {
console.info('This button can be operated')
}
else{
console.info('This button can not be operated')
}
}
``` ```
### UiComponent.isFocused ### UiComponent.isFocused
...@@ -588,10 +642,16 @@ Obtains the focused status of this component. ...@@ -588,10 +642,16 @@ Obtains the focused status of this component.
**Example** **Example**
``` ```
if(await button.isFocused()) async function demo() {
console.info('This button is focused') let driver = UiDriver.create()
else let button = await driver.findComponent(BY.type('button'))
console.info('This button is not focused') if(await button.isFocused()) {
console.info('This button is focused')
}
else{
console.info('This button is not focused')
}
}
``` ```
### UiComponent.isSelected ### UiComponent.isSelected
...@@ -613,10 +673,16 @@ Obtains the selected status of this component. ...@@ -613,10 +673,16 @@ Obtains the selected status of this component.
**Example** **Example**
``` ```
if(await button.isSelected()) async function demo() {
console.info('This button is selected') let driver = UiDriver.create()
else let button = await driver.findComponent(BY.type('button'))
console.info('This button is not selected') if(await button.isSelected()) {
console.info('This button is selected')
}
else{
console.info('This button is not selected')
}
}
``` ```
### UiComponent.inputText ### UiComponent.inputText
...@@ -638,7 +704,11 @@ Enters text into this component (available for text boxes). ...@@ -638,7 +704,11 @@ Enters text into this component (available for text boxes).
**Example** **Example**
``` ```
await button.inputText('next page') async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
await button.inputText('next page')
}
``` ```
### UiComponent.scrollSearch ### UiComponent.scrollSearch
...@@ -666,7 +736,11 @@ Scrolls on this component to search for the target component (available for list ...@@ -666,7 +736,11 @@ Scrolls on this component to search for the target component (available for list
**Example** **Example**
``` ```
let button = await scrollBar.scrollSearch(By.text('next page')) async function demo() {
let driver = UiDriver.create()
let scrollBar = await driver.findComponent(BY.scrollable(true))
let button = await scrollBar.scrollSearch(BY.text('next page'))
}
``` ```
## UiDriver ## UiDriver
...@@ -693,7 +767,9 @@ Creates a **UiDriver** object and returns the object created. This API is a stat ...@@ -693,7 +767,9 @@ Creates a **UiDriver** object and returns the object created. This API is a stat
**Example** **Example**
``` ```
let driver = UiDriver.create() async function demo() {
let driver = UiDriver.create()
}
``` ```
### UiDriver.delayMs ### UiDriver.delayMs
...@@ -715,7 +791,10 @@ Delays this **UiDriver** object within the specified duration. ...@@ -715,7 +791,10 @@ Delays this **UiDriver** object within the specified duration.
**Example** **Example**
``` ```
await UiDriver.delayMs(1000) async function demo() {
let driver = UiDriver.create()
await driver.delayMs(1000)
}
``` ```
### UiDriver.findComponent ### UiDriver.findComponent
...@@ -743,7 +822,10 @@ Searches this **UiDriver** object for the target component that has the given at ...@@ -743,7 +822,10 @@ Searches this **UiDriver** object for the target component that has the given at
**Example** **Example**
``` ```
let button = await UiDriver.findComponent(By.text('next page')) async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.text('next page'))
}
``` ```
### UiDriver.findComponents ### UiDriver.findComponents
...@@ -760,7 +842,7 @@ Searches this **UiDriver** object for all components that match the given attrib ...@@ -760,7 +842,7 @@ Searches this **UiDriver** object for all components that match the given attrib
| Name| Type| Mandatory| Description | | Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ------------------ | | ------ | ---- | ---- | ------------------ |
| by | By | Yes | Attributes of the target components.| | by | By | Yes | Attributes of the target component.|
**Return value** **Return value**
...@@ -771,7 +853,10 @@ Searches this **UiDriver** object for all components that match the given attrib ...@@ -771,7 +853,10 @@ Searches this **UiDriver** object for all components that match the given attrib
**Example** **Example**
``` ```
let <Array<button>> = await UiDriver.findComponents(By.text('next page')) async function demo() {
let driver = UiDriver.create()
let buttonList = await driver.findComponents(BY.text('next page'))
}
``` ```
### UiDriver.assertComponentExist ### UiDriver.assertComponentExist
...@@ -793,7 +878,10 @@ Asserts that a component that matches the given attributes exists on the current ...@@ -793,7 +878,10 @@ Asserts that a component that matches the given attributes exists on the current
**Example** **Example**
``` ```
await assertComponentExist(By.text('next page')) async function demo() {
let driver = UiDriver.create()
await driver.assertComponentExist(BY.text('next page'))
}
``` ```
### UiDriver.pressBack ### UiDriver.pressBack
...@@ -809,7 +897,10 @@ Presses the Back button on this **UiDriver** object. ...@@ -809,7 +897,10 @@ Presses the Back button on this **UiDriver** object.
**Example** **Example**
``` ```
UiDriver.pressBack() async function demo() {
let driver = UiDriver.create()
await driver.pressBack()
}
``` ```
### UiDriver.triggerKey ### UiDriver.triggerKey
...@@ -831,7 +922,10 @@ Triggers the key of this **UiDriver** object that matches the given key code. ...@@ -831,7 +922,10 @@ Triggers the key of this **UiDriver** object that matches the given key code.
**Example** **Example**
``` ```
await UiDriver.triggerKey(123) async function demo() {
let driver = UiDriver.create()
await driver.triggerKey(123)
}
``` ```
### UiDriver.click ### UiDriver.click
...@@ -853,7 +947,10 @@ Clicks a specific point of this **UiDriver** object based on the given coordinat ...@@ -853,7 +947,10 @@ Clicks a specific point of this **UiDriver** object based on the given coordinat
**Example** **Example**
``` ```
await UiDriver.click(100,100) async function demo() {
let driver = UiDriver.create()
await driver.click(100,100)
}
``` ```
### UiDriver.doubleClick ### UiDriver.doubleClick
...@@ -875,7 +972,10 @@ Double-clicks a specific point of this **UiDriver** object based on the given co ...@@ -875,7 +972,10 @@ Double-clicks a specific point of this **UiDriver** object based on the given co
**Example** **Example**
``` ```
await UiDriver.doubleClick(100,100) async function demo() {
let driver = UiDriver.create()
await driver.doubleClick(100,100)
}
``` ```
### UiDriver.longClick ### UiDriver.longClick
...@@ -897,7 +997,10 @@ Long-clicks a specific point of this **UiDriver** object based on the given coor ...@@ -897,7 +997,10 @@ Long-clicks a specific point of this **UiDriver** object based on the given coor
**Example** **Example**
``` ```
await UiDriver.longClick(100,100) async function demo() {
let driver = UiDriver.create()
await driver.longClick(100,100)
}
``` ```
### UiDriver.swipe ### UiDriver.swipe
...@@ -920,7 +1023,10 @@ Swipes from the start point to the end point of this **UiDriver** object based o ...@@ -920,7 +1023,10 @@ Swipes from the start point to the end point of this **UiDriver** object based o
**Example** **Example**
``` ```
await UiDriver.swipe(100,100,200,200) async function demo() {
let driver = UiDriver.create()
await driver.swipe(100,100,200,200)
}
``` ```
### UiDriver.screenCap ### UiDriver.screenCap
...@@ -942,5 +1048,8 @@ Captures the current screen of this **UiDriver** object and saves it as a PNG im ...@@ -942,5 +1048,8 @@ Captures the current screen of this **UiDriver** object and saves it as a PNG im
**Example** **Example**
``` ```
await UiDriver.screenCap('/local/tmp/') async function demo() {
let driver = UiDriver.create()
await driver.screenCap('/local/tmp/')
}
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册