Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koltyakov/sp-auth-puppeteer-sample
Puppeteer & node-sp-auth example
https://github.com/koltyakov/sp-auth-puppeteer-sample
authentication javascript puppeteer sharepoint sharepoint-online typescript
Last synced: about 1 month ago
JSON representation
Puppeteer & node-sp-auth example
- Host: GitHub
- URL: https://github.com/koltyakov/sp-auth-puppeteer-sample
- Owner: koltyakov
- Created: 2018-10-09T10:19:04.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T02:22:56.000Z (about 2 years ago)
- Last Synced: 2024-04-14T23:12:09.731Z (9 months ago)
- Topics: authentication, javascript, puppeteer, sharepoint, sharepoint-online, typescript
- Language: TypeScript
- Size: 183 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Puppeteer & node-sp-auth example
> Demonstrates a way of headless browser automation with SharePoint.
## About Puppeteer
[Puppeteer](https://github.com/GoogleChrome/puppeteer) is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.
## Dependencies
```bash
npm install
```## Build
```bash
npm run build
```## Auth
```bash
npm run auth
```Provide auth options for SPO or On-Prem SharePoint site.
Auth options are stored in `./config/private.json`
See more [here](https://github.com/koltyakov/node-sp-auth-config).
## Run: sp-auth mechanism
```bash
npm run start
```or
```bash
ts-node ./src/main.ts
```Should start the Puppeteer (in headless mode) authenticated to SharePoint with [node-sp-auth](https://github.com/s-KaiNet/node-sp-auth).
## Run: interactive auth and O365 automation
```bash
npm run start:interactive
```or
```bash
ts-node ./src/interactive.ts
```Interactive mode emulates user credentials input which let us navigate to any Office 365 section, e.g. Central Administration, etc., and run some UI automation or testing.
E.g., [./src/interactive](./src/interactive.ts) script outputs a list of surveys and a number of responses from MS Forms.
## Sample
```typescript
import * as puppeteer from 'puppeteer';
import { authPuppeteer } from './auth';(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const siteUrl = await authPuppeteer(page);
// Since this time page is authenticated in SharePointawait page.goto(siteUrl, { waitUntil: 'networkidle2' });
/* Here comes Puppeteer logic: UI tests, screenshots, etc. */
// Save a screenshot of SharePoint page as PDF
await page.pdf({ path: 'sp.pdf', format: 'A4' });// For other goodies check for Puppeteer API:
// https://github.com/GoogleChrome/puppeteer/blob/v1.9.0/docs/api.mdawait browser.close();
})()
.catch(console.warn);
```## CI Sample
In CI environment configure [SPAuth variables](https://github.com/koltyakov/node-sp-auth-config#environment-variables). E.g.:
- SPAUTH_SITEURL=https://contoso.sharepoint.com/sites/my-site
- [email protected]
- SPAUTH_PASSWORD=secretClone the sample:
```bash
git clone [email protected]:koltyakov/sp-auth-puppeteer-sample.git
```Install dependencies and build:
```bash
npm ci
npm run build
```Run automation. E.g.:
```bash
node ./build/main --ci "--scenarios" "workbench,screenshot"
```Embed approach into your favorite UI tests framework.