Reputation: 25
I have a table with 7 cells (could increase in future). Only 4 cells are visible and are hittable from UI on screen1. I want to tap 7th cell go to screen2 and I am successfully able to scroll down (checking if cell is hittable and scrolling one cell at a time) and tap 7th cell but once I come back to screen1, I want to swipe all the to top at once (not scrolling one cell at a time). I tried using "swipeup" but when doing so it is tapping on the cell and I am navigated to screen2 (and test fails) which I don't want to happen. How can I achieve this? Thanks in advance. code for scroll down:
int elementIndex = 0;
NSArray *cells = tableView.cells.allElementsBoundByIndex;
for(XCUIElement *cell in cells){
NSString *name = transactionCell.staticTexts[@"Name"].label;
if (!cell.hittable) {
[Testfunc scrollDown:tableView withApp:app index:elementIndex-1];
}
[cell tap];
elementIndex++;
//do stuff if this is the correct cell else go to next cell
}
+ (void) scrollDown:(XCUIElement*)tableView withApp:(XCUIApplication*)app index:(int)elemntIndex {
XCUIElementQuery* tableCells = tableView.cells;
int tableCount = (int)tableCells.count;
if(index > 0 && elemntIndex < tableCells.count-1){
XCUIElement* startElement = [tableCells elementBoundByIndex:elemntIndex];
XCUIElement* endElement = [tableCells elementBoundByIndex:elemntIndex-1];
[startElement pressForDuration:0.1 thenDragToElement:endElement];
}
}
I tried scroll all the way up by doing:
XCUIElement *elementSwipe = transactionCell.staticTexts[name];
[elementSwipe swipeUp];
But then it taps on the cell before scrolling up and I am navigated to screen2. Then test fails.
Upvotes: 0
Views: 697
Reputation: 702
You can try to tap on your status bar like:
XCUIApplication().coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.02)).tap()
It would scroll all the way to top.
Upvotes: 4
Reputation: 7649
Tap on the status bar, that should scroll you to the top.
let app = XCUIApplication()
app.statusBars.element(boundBy: 0).tap()
Upvotes: 3