Automated unit testing ArcGIS Pro- is there a way to programmatically login?

336
8
Jump to solution
12-07-2021 09:38 AM
GregEAM
New Contributor III

Hello,

I have been trying to unit test my ArcGIS Pro add-in in an automated fashion on a build server.

I followed the steps in this guide to get unit testing working on my local machine (which works great): https://github.com/esri/arcgis-pro-sdk/wiki/ProGuide-Regression-Testing

However, I'm finding that because the user on the build server is not logged into an ArcGIS Portal, that this method in the above guide is failing:

 

    /// <summary>
    /// Starts an instance of ArcGIS Pro Application
    /// </summary>
    public static async void StartApplication()
    {
      var evt = new System.Threading.ManualResetEvent(false);
      System.Threading.Tasks.Task ready = null;

      var uiThread = new System.Threading.Thread(() =>
      {
        try
        {
          Application = new ProApp();
          ready = Application.TestModeInitializeAsync();
          evt.Set();
        }
        catch (XamlParseException)
        {
          throw new FatalArcGISException("Pro is not licensed");
        }
        catch (Exception ex)
        {
          throw ex;
        }
        finally
        {
          evt.Set();
        }

        System.Windows.Threading.Dispatcher.Run();
      });

      uiThread.TrySetApartmentState(System.Threading.ApartmentState.STA);
      uiThread.Name = "Test UI Thread";
      uiThread.IsBackground = true;
      uiThread.Start();

      evt.WaitOne(); // Task ready to wait on.

      if (ready != null)
      {
        try
        {
          await ready;
        }
        catch (Exception ex)
        {
          throw ex;
        }
      }
    }

 

 

The error message I see in the console from the test run says: The active test run was aborted. Reason: Test host process crashed

Is there a way to programmatically provide Portal credentials to the ArcGIS Pro application before it is initialized for unit testing?

0 Kudos
1 Solution

Accepted Solutions
GregEAM
New Contributor III

So I finally was able to get this working... it turns out that I was using the wrong Windows user on the build machine to license ArcGIS Pro. I needed to log into the machine with the automated build user's Windows credentials, instead of my own admin ones.

Additionally, for licensing ArcGIS Pro, I ended up using a Single Use License instead of a Named User License. Apparently a Named User License configuration does work for automated unit tests, but it requires being authorized to work offline, which renders it unavailable for usage anywhere else (until it is taken back online). Using a Single User License seems more straightforward and less problematic.

View solution in original post

0 Kudos
8 Replies
ABishop
Regular Contributor III

What type of license configuration do you have?

Amanda Bishop, GISP
0 Kudos
GregEAM
New Contributor III

I'm using a Named User License from my ArcGIS Online account.

0 Kudos
ABishop
Regular Contributor III

It should stay logged in if you are are authenticating with your named user license.

Amanda Bishop, GISP
0 Kudos
ABishop
Regular Contributor III

Also maybe check out this thread:

https://github.com/microsoft/vstest/issues/2261 

Amanda Bishop, GISP
0 Kudos
GregEAM
New Contributor III

Right, I did find it stays logged in on my local machine. Unfortunately though, I'm not able to log in as the build user on the build server, so I have no way to manually enter my credentials in the first place.

Thanks for the link, I will check that thread out.

0 Kudos
ABishop
Regular Contributor III

Have you checked your user permissions to the server?  If you are unable to log in sounds like a permissions issue.

Amanda Bishop, GISP
0 Kudos
GregEAM
New Contributor III

It's not a permissions issue. The problem is our automated build on the server recreates a clean environment each time it runs tests, which will break the ArcGIS Pro licensing. And since it is automated, I'm not able to manually enter my named user credentials each time it runs.

It's seeming like this setup might not be compatible with a named user license configuration... Would a different license configuration be more ideal for this scenario?

0 Kudos
GregEAM
New Contributor III

So I finally was able to get this working... it turns out that I was using the wrong Windows user on the build machine to license ArcGIS Pro. I needed to log into the machine with the automated build user's Windows credentials, instead of my own admin ones.

Additionally, for licensing ArcGIS Pro, I ended up using a Single Use License instead of a Named User License. Apparently a Named User License configuration does work for automated unit tests, but it requires being authorized to work offline, which renders it unavailable for usage anywhere else (until it is taken back online). Using a Single User License seems more straightforward and less problematic.

0 Kudos