Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Testing Against SharePoint

Patrick Rodgers edited this page Dec 26, 2016 · 7 revisions

This articles will walk you through getting setup to execute the tests against SharePoint locally. These tests create a sub web and then run against that sub web, containing all the changes to that location. Currently the sub web is not automatically deleted but left for you to examine.

In the below the token {site url} is understood to be the absolute URL to your site collection in which you would like to execute the tests. So if you have a site at https://mytenant.sharepoint.com/sites/pnptesting for example, substitute that anywhere you see the token {site url}. Likewise, {admin site url} is understood to be the tenant admin site, for example https://mytenant-admin.sharepoint.com. It is also expected you are a tenant admin for this site and can grant permissions to add-ins, please see the updated process for trusting tenant/add-in only permissions. If this is not the case you can always sign-up for a free developer account.

Register An Add-In

Before you can begin running tests you need to register a low-trust add-in with SharePoint. This is primarily designed for Office 365, but can work on-premises if you configure you farm accordingly.

  1. Navigation to {site url}/_layouts/appregnew.aspx
  2. Click "Generate" for both the Client Id and Secret values
  3. Give you add-in a title, this can be anything but will let you locate it in the list of add-in permissions
  4. Provide a fake value for app domain and redirect uri, you can use the values shown in the examples
  5. Click "Create"
  6. Copy the returned block of text containing the client id and secret as well as app name for your records and later in this article.

Grant Your Add-In Permissions

Now that we have created an add-in registration we need to tell SharePoint what permissions it can use. Due to an update in SharePoint Online you now have to register add-ins with certain permissions in the admin site.

  1. Navigate to {admin site url}/_layouts/appinv.aspx
  2. Paste your client id from the above section into the Add Id box and click "Lookup"
  3. You should see the information populated into the form from the last section, if not ensure you have the correct id value
  4. Paste the below XML into the permissions request xml box and hit "Create"
  5. You should get a confirmation message.
  <AppPermissionRequests AllowAppOnlyPolicy="true">
    <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
    <AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="FullControl" />
    <AppPermissionRequest Scope="http://sharepoint/search" Right="QueryAsUserIgnoreAppPrincipal" />
  </AppPermissionRequests>

Configure the project settings file

  1. If you have not already, make a copy of settings.example.js and name it settings.js
  2. Edit this file to set the values on the testing object to
  • clientId: "The client id you created"
  • clientSecret: "The client secret you created"
  • siteUrl: "{site url}"
  • enableWebTests: true
  1. You can disable web tests at any time by setting enableWebTests to false in settings.js, this can be helpful as they take a few minutes to run

Run the test

You only need to perform the configuration tasks once, you can then run the tests multiple times. To do so execute the below command with enableWebTests set to true.

gulp test

This should run all the tests and report back on the results. If you find any bugs please report them.