Skip to content

Instantly share code, notes, and snippets.

@tuyen-vuduc
Last active November 7, 2019 15:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuyen-vuduc/bf689732048d388bcbebffc1621eccad to your computer and use it in GitHub Desktop.
Save tuyen-vuduc/bf689732048d388bcbebffc1621eccad to your computer and use it in GitHub Desktop.
UITests - iOS - ScrollToBottom
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
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);
}
}
@bill2004158
Copy link

Can you show us the value of contentOffsetRegex in Xamarin.UITest.cs?

@bill2004158
Copy link

it seems there is contentOffset in description?

@bogdangm
Copy link

Yes, I don't see where the contentOffset is defined?

@vatbub
Copy link

vatbub commented Sep 6, 2017

The regex to use can actually be found in the ruby script in line 15, though I couldn't test it yet in C#

@tuyen-vuduc
Copy link
Author

@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