Automated Testing Challenges for SharePoint Apps – Trusting the app!

Many architects are trying to establish a fully automated continuous deployment process for their SharePoint apps. While automating the build, packaging & deployment is fairly simple (check this), there is a big challenge that is preventing architects and developers from reaching the full automation stage. That’s is “Trusting the App“!

Following the deployment of the application components (to pre-prod environments), it is important to note that before anyone accessing the application, including automated tests that may be part of the build, a tenant (or site collection) administrator will have to trust the application on the app information page in SharePoint. This is usually a manual process and there is no way to trust your app through PowerShell or .NET CSOM but there is a trick that I use for achieving a full automation! PowerShell IE Automation!

Here is the script that I use from within my deployment script:

$url = “$($web.Url.TrimEnd(‘/’))/_layouts/15/appinv.aspx?AppInstanceId={$($appInstance.Id)}”
     $ie = New-Object -com internetexplorer.application
     try
     {
         $ie.visible=$true
         $ie.navigate2($url)
        while ($ie.busy)
         {
             sleep -milliseconds 60
         }
         $trustButton = $ie.Document.getElementById(“ctl00_PlaceHolderMain_BtnAllow”)         
         $trustButton.click() 
         sleep -Seconds 1
         Write-Host “App was trusted successfully!”
     }
   catch
   {
   throw (“Error Trusting App”);
   }
   finally
   {
        $ie.Quit()
  }

You just need to add the code above to your deployment script and VOILA. You no longer need to suspend the testing process until the application is trusted. Now a completely “Build-Deploy-Test workflow” is possible!

Finally, I would like to give some credit to Alexander Brassington, his blog post about automated publishing for content types using PowerShell IE Automation inspired me. Although, the post is completely unrelated to Build Automation, it helped a lot on coming up with the workaround!

Advertisements

4 thoughts on “Automated Testing Challenges for SharePoint Apps – Trusting the app!”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s