Select to view content in your preferred language

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

1730
8
Jump to solution
12-07-2021 09:38 AM
greg_eam
Occasional Contributor

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
greg_eam
Occasional Contributor

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
MVP Regular Contributor

What type of license configuration do you have?

Amanda Bishop, GISP
0 Kudos
greg_eam
Occasional Contributor

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

0 Kudos
ABishop
MVP Regular Contributor

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

Amanda Bishop, GISP
0 Kudos
ABishop
MVP Regular Contributor

Also maybe check out this thread:

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

Amanda Bishop, GISP
0 Kudos
greg_eam
Occasional Contributor

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
MVP Regular Contributor

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
greg_eam
Occasional Contributor

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
greg_eam
Occasional Contributor

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