Backdoor Invoke() Error

CherubyxCherubyx CAUniversity ✭✭
edited August 2015 in Xamarin.Forms

I'm calling my backdoor method via my tests. Somehow in my AppDelegate.cs it causes the Xamarin test to crash and have an exception error:

System.Exception: Error while performing Invoke("nameMethod", null)
--> System.Net.WebException : Error getting response stream (ReadDone 2): ReceiveFailure
--> System.Exception: at System.Net.WebConnection.HandleError(WebExceptionStatus st, System.Exception e, System.String where)
at System.Net.WebConnection.ReadDone(IAsyncResult result)

My AppDelegate backdoor method is:

[Export ("getPageTitle:")]
public NSString GetPageTitle (NSString s)
        Page page = App.Current.MainPage; //somehow I narrowed down to this line, this crashes the whole thing
        if (page != null)
          return new NSString(page.Title);
        return new NSString("No page found");

My call:

public void SomeMethod()

Is it not possible to get the App context here? What am I doing wrong?

Best Answer


  • JohnHardmanJohnHardman GBUniversity mod

    @Cherubyx - Not actually answering your question, but asking one... Is that just an example piece of code, or are you actually getting title text using Invoke in your UITest? If this is something you actually intend to do in a UITest, I would suggest this is an anti-pattern.

    Tests should have an expected value. Rather than fetch the actual value and then compare the two in an Assert, I would be using WaitForElement etc. to wait until the expected value appears on the screen. If it doesn't appear within the timeout period, then an exception will be thrown and the test marked as failed. Doing this consistently results in more resilient tests, whether using UITest or other test automation tools.

  • HugoLogmans_HugoLogmans_ NLMember ✭✭✭

    For the ones looking up the exception:
    1. If your backdoor (app side) crashes when called, this is the resulting error.
    2. It seems to me that the Invoke call is missing a double colon at the end.

Sign In or Register to comment.