Jacobvu84 / Automated-Software-Testing

Nơi lữu trữ các vấn đề được trao đổi bởi cộng đồng Automated Software Testing
2 stars 4 forks source link

iOS Locator Strategies example #30

Open Jacobvu84 opened 5 years ago

Jacobvu84 commented 5 years ago

Locator Strategies example

Note: Nên đọc https://github.com/Jacobvu84/Automated-Software-Testing/issues/29 trước.

image

1. Tìm kiếm bằng xpath

MobileBy.xpath("//XCUIElementTypeTextField[@name='phone']"); (1)

Ví dụ trên element của iOS có type = XCUIElementTypeTextField và có thuộc tính name = phone

Nếu bạn muốn kết hợp nhiều thuộc tính với nhau có thể dùng

Trong trường hợp bạn muốn một selector tìm ra được hơn 2 ( hoặc hơn) loại type thuộc tính name có cùng giá trị phone

MobileBy.xpath("(//XCUIElementTypeTextField[@name='phone'] | //XCUIElementTypeButton[@name='phone'])"); (3)
Jacobvu84 commented 5 years ago

2. Tìm kiếm bằng iOS Predicate String Strategy

Một số ví dụ tương ứng với các kiểu tìm kiếm theo Xpath bên trên.

Ví dụ cả 3 biểu thức này đều có giá trị như nhau

MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeTextField' AND name BEGINSWITH 'phone'"); 

MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeTextField' AND name BEGINSWITH[c] 'phOnE'"); 

MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeTextField' AND name BEGINSWITH[cd] 'phÔnÊ'"); 

Tham khảo

Note: Sử dụng iOS Predicate String Strategy sẽ có tiềm năng là nhanh hơn Appium's XPath strategy vì nó được built sẵn trong XCUITest

Jacobvu84 commented 5 years ago

3. Tìm kiếm bằng iOS Class Chain Strategy

Strategy này là kiểu lai ghép giữa XPath and predicate strings strategy. Được phát triển bởi Appium Team. Tham khảo thêm ở đây

Jacobvu84 commented 5 years ago

Sắp xếp theo hiệu suất các location strategies

Tham khảo thêm ở đây