簡體   English   中英

如何通過UI測試執行“向左滑動”操作

[英]How can I perform a “swipe left” action via UI tests

如何通過Xcode中的UI測試執行“向左滑動”操作以觸發segue並更改視圖控制器?

錄制的代碼是

[[[[[[[XCUIApplication alloc] init].otherElements containingType:XCUIElementTypeNavigationBar identifier:@"UIView"] childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element tap];

但似乎它不起作用 - 據我所知,視圖控制器不會更改為新的。

很難准確判斷您要嘗試滑動的視圖。 以下代碼將在標題為“Swipe Me”的標簽上執行“向左滑動”手勢。 定位視圖后,應該很容易遵循相同的技術。

XCUIApplication *app = [XCUIApplication alloc] init];
[app.labels[@"Swipe Me"] swipeLeft];

閱讀有關swipeLeft以及您可以對元素執行的伴隨手勢的更多信息 如果您正在尋找更通用的“備忘單”,我也能為您提供幫助

如果你不能在app swipeLeft

app.swipeLeft()

嘗試在scrollView上調用它,就像

app.scrollViews.element(boundBy: 0).swipeLeft()

無需知道UI堆棧上當前可用的UI元素,這對我app.windows.element(boundBy:0).swipeLeft()app.windows.element(boundBy:0).swipeLeft()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM