Xamarin.UITest RecyclerView wait for items to load - xamarin

I am trying to write an Xamarin.UITest for my Android project. My app has a "download" UIButton, that when pressed, downloads data and then populates a RecyclerView. Then when a "clear" UIButton is pressed, the RecyclerView is cleared. This is what I tried so far:
app.Tap(c => c.Marked("download_btn"));
app.WaitForElement(x => x.Marked("recycler_item"), "Timed out waiting for items to load", TimeSpan.FromSeconds(5));
app.Tap(c => c.Marked("clear_btn"));
The app.WaitForElement part never finds the items in the RecyclerView, even when they are there. I want to test that there is at least 1 item in the RecyclerView after I tap the download button.

I figured out how to wait for the RecyclerView to load. You can wait for a view that is inside the layout of item itself, such as a TextView:
app.WaitForElement(x => x.Marked("name_textView"), "Timed out waiting for items to load", TimeSpan.FromSeconds(3));

Related

RecyclerView scroll to bottom

I want to write a Xamarin.UITest that scrolls my RecyclerView to the bottom and taps on the last item in the list. How can I do this?
I figured it out by setting a view in the last item in my RecyclerView ContentDescription="isLast". Then in my test:
app.ScrollDownTo("isLast", "rvId", ScrollStrategy.Gesture, 0.67, 5000, true, TimeSpan.FromSeconds(30));
app.Tap(c => c.Marked("isLast"));
Where rvId is the ID of the RecyclerView. For example, I have a TextView in each item of my RecyclerView, so I set the last one to MyTextView.ContentDescription="isLast" in my RecyclerView.Adapter

NSSavePanel get cancel button object

I want to show a popover relative to the "cancel" button of my NSSavePanel but this seem not possible. This is a sample code that explain what I need to do:
// the save panel is called when the _window3 get closed..
[panel beginSheetModalForWindow:_window3 completionHandler:^(NSInteger result)
{
if (result == NSFileHandlingPanelOKButton)
{
// ok, saving my file! (also the app get closed)
}
else
{
/* (the app get closed w/o saving anything ATM)
but... you are really sure????
Since you have done a long job with this app you can also push the button by mistake.. (OMG)
Nice should be to add a Popover relative to the cancel button rect, where the user can see and push
on a "go back" and the "Exit w/o saving" buttons
*/
// normally I call a popover this way:
[_goBackOrExitPopover showRelativeToRect:[cancelBtn bounds] ofView:cancelBtn preferredEdge:NSMinYEdge];
// ... but how to intercept the cancel button (cancelBtn)??
}
}];
How can I find the cancel button object?

Can we override NAVIGATION BACK BUTTON press in Xamarin.forms?

Can we override navigation back button pressed in Xamarin.forms?
I have one navigation back button and the one save button in navigation bar.Save button hits the web service and saves in asynchronous way. While saving although i used progressing bar, navigation back button can be pressed and hence the app crashes due to index out of range exception on navigation stack.I tried using OnDisappearing() , did not work. I wanna cancel the PopUpAsync(),if the save is not done completely, but failed to achieve that. Is there any solution for this scenario? Can we override the navigation back button press event using any custom renderer ?
For controlling the back button to do what I want, I used this method in Xamarin:
public override bool OnKeyDown(Keycode HWkeyCode, KeyEvent e)
{
if (HWkeyCode == Keycode.Back)
{
StartActivity(typeof(FrontPageActivity));
return true;
}
return false;
}

Why doesn't button state remain?

I have the following code:
#IBAction func mybuttonclick(sender: UIButton) {
if(sender.titleLabel?.text == "Start"){
sender.titleLabel?.text = "Change"
}
else {
sender.titleLabel?.text = "Start"
}
}
When I click the button, I see "Change" flash and then it goes back to "Start". This is a simple new test app. The above is the only code I have in the app. Why does the button text change back to "Start" instead of remaining on "Change"?
Its very hard to answer this question without more information, but I think it's possible you have the action bound twice in Interface Builder. Where the action is being fired twice each time you hit the button. Another possibility is you have the button inside a table or collection view cell where the cell is being reused and replacing your previously edited button.

List item unresponsive on second click event

In my Windows Phone 7 application I have a number of list views. Each listViewItem has a click event (By setting 'selectionChanged' attribute to the listBox in my xaml). Now a very peculiar thing happens:
When I click on an item in the listbox the first time everything goes well, in this case the user gets taken to another screen. When I go back from that screen to the listbox, I select the very same listboxitem but this time the event doesn't register, nothing happens...
I then first have to tap on another item, let that ones even fire, then only can I tap on the first item. So in other words, I can't fire a click event for a listItem twice in a row. I'm thinking it's because the event handler on the listbox says 'onSelectionChanged', if you select the same item the selection hasn't technically changed.
So what other eventHandling attribute can I use on my listbox to register selection events on it's items?
Thanks for any help!
AFAIK, Theres is no such event. So, the work around is,
In the OnNavigatedTo event handler of the first page, set the SelectedIndex to -1
YourListBox.SelectedIndex = -1;
And while doing so, make one small modification to your Selection_Changed handler
void Selection_Changed(...)
{
if(YourListBox.SelectedIndex == -1)
return;
//rest of your code
}
In your case, SelectedItem in the ListBox is set for the first time. The second time you tap on the same item, technically its not a SelectionChanged event, hence its not firing.
Clearing the SelectedItem at the end of SelectionChanged event would do the trick.
Below is a code snippet that could be helpful,
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//
// do your stuff here
//
//reset the selection of the sender (ListBox)
(sender as ListBox).SelectedItem = null;
}

Resources