Last active
November 7, 2019 15:32
-
-
Save tuyen-vuduc/bf689732048d388bcbebffc1621eccad to your computer and use it in GitHub Desktop.
UITests - iOS - ScrollToBottom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def scroll_to_edge(uiquery, direction) | |
allowed_directions = [:up, :down] | |
dir_symbol = direction.to_sym | |
unless allowed_directions.include?(dir_symbol) | |
raise ArgumentError, "Expected '#{direction} to be one of #{allowed_directions}" | |
end | |
lastYOffset = 99999999.0 * (dir_symbol == :up ? 1 : -1) | |
while true | |
scrollView = scroll(uiquery, direction)[0] | |
if (scrollView == nil) then return end | |
currentOffset = scrollView["description"].match(/contentOffset: {(\d+), (\d+(?:\.\d+)?)}/)[2].to_i | |
if ((currentOffset - lastYOffset).abs < 0.001) then return end | |
lastYOffset = currentOffset; | |
sleep(1) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async Task ScrollToBottom(Func<AppQuery, AppQuery> query) | |
{ | |
var scrolls = app.Query(query); | |
for (int i = 0; i < scrolls.Length; i++) | |
{ | |
var lastYOffset = double.MinValue; | |
do | |
{ | |
var scroll = app.Query(query)[i]; | |
app.ScrollDown(query, ScrollStrategy.Gesture); | |
var description = scroll.Description; | |
var contentMatch = contentOffsetRegex.Match(description); | |
var yOffset = double.Parse(contentMatch.Groups[2].Value); | |
System.Diagnostics.Debug.WriteLine($"Scroll:{lastYOffset}->{yOffset}"); | |
if (yOffset - lastYOffset <= 0.001) | |
{ | |
break; | |
} | |
lastYOffset = yOffset; | |
await Task.Delay(100); | |
} while (true); | |
} | |
} |
it seems there is contentOffset in description?
Yes, I don't see where the contentOffset is defined?
The regex to use can actually be found in the ruby script in line 15, though I couldn't test it yet in C#
@bill2004158, @bogdangm, @vatbub Yeah, I missed the regex in this GIST. The main point is the idea to solve issue, however, you guys could run it and define it after debugging the code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you show us the value of contentOffsetRegex in Xamarin.UITest.cs?