-
Notifications
You must be signed in to change notification settings - Fork 231
Testing Against SharePoint
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.
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.
- Navigation to {site url}/_layouts/appregnew.aspx
- Click "Generate" for both the Client Id and Secret values
- Give you add-in a title, this can be anything but will let you locate it in the list of add-in permissions
- Provide a fake value for app domain and redirect uri, you can use the values shown in the examples
- Click "Create"
- 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.
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.
- Navigate to {admin site url}/_layouts/appinv.aspx
- Paste your client id from the above section into the Add Id box and click "Lookup"
- You should see the information populated into the form from the last section, if not ensure you have the correct id value
- Paste the below XML into the permissions request xml box and hit "Create"
- 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>
- If you have not already, make a copy of settings.example.js and name it settings.js
- 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
- 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
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.
Sharing is caring!