# puppeteer-salesforce-library

> Puppeteer automation tests functions

Latest version **0.1.0-149** (published 2021-08-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install puppeteer-salesforce-library
pnpm add puppeteer-salesforce-library
yarn add puppeteer-salesforce-library
bun add puppeteer-salesforce-library
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0-149 |
| Published | 2021-08-26 |
| First published | 2019-01-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 25 |
| Unpacked size | 40.8 MB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | spot-npm-deploy |

## Links

- npm: https://www.npmjs.com/package/puppeteer-salesforce-library
- Repository: git@git.realestate.com.au:the-money/puppeteer-salesforce-library
- Homepage: https://git.realestate.com.au/the-money/puppeteer-salesforce-library
- npm.io page: https://npm.io/package/puppeteer-salesforce-library

## Dependencies (25)

- [chai](https://npm.io/package/chai.md) ^4.3.4
- [jest](https://npm.io/package/jest.md) ^26.6.3
- [node](https://npm.io/package/node.md) ^14.15.2
- [acorn](https://npm.io/package/acorn.md) ^8.2.4
- [faker](https://npm.io/package/faker.md) ^5.5.3
- [canvas](https://npm.io/package/canvas.md) ^2.7.0
- [dotenv](https://npm.io/package/dotenv.md) ^8.2.0
- [moment](https://npm.io/package/moment.md) ^2.29.1
- [hashmap](https://npm.io/package/hashmap.md) ^2.4.0
- [jsforce](https://npm.io/package/jsforce.md) ^1.10.1
- [request](https://npm.io/package/request.md) ^2.88.2
- [puppeteer](https://npm.io/package/puppeteer.md) ^7.1.0
- [react-app](https://npm.io/package/react-app.md) ^1.1.2
- [bufferutil](https://npm.io/package/bufferutil.md) ^4.0.3
- [find-config](https://npm.io/package/find-config.md) ^1.0.0
- [json-parser](https://npm.io/package/json-parser.md) ^3.1.2
- [lite-server](https://npm.io/package/lite-server.md) ^2.6.1
- [utf-8-validate](https://npm.io/package/utf-8-validate.md) ^5.0.5
- [@babel/polyfill](https://npm.io/package/@babel/polyfill.md) ^7.12.1
- [request-promise](https://npm.io/package/request-promise.md) ^4.2.6
- [node-rest-client](https://npm.io/package/node-rest-client.md) ^3.1.0
- [properties-reader](https://npm.io/package/properties-reader.md) ^2.2.0
- [allure-commandline](https://npm.io/package/allure-commandline.md) ^2.13.8
- [jest-allure-reporter](https://npm.io/package/jest-allure-reporter.md) ^1.2.3
- [mocha-allure-reporter](https://npm.io/package/mocha-allure-reporter.md) ^1.4.0

## Recent versions

- 0.1.0-149 (latest) — 2021-08-26
- 0.1.0-145 — 2021-05-10
- 0.1.0-143 — 2021-02-17
- 0.1.0-140 — 2021-01-12
- 0.1.0-138 — 2021-01-12
- 0.1.0-136 — 2020-12-02
- 0.1.0-134 — 2020-10-13
- 0.1.0-132 — 2020-10-06
- 0.1.0-130 — 2020-09-22
- 0.1.0-128 — 2020-09-10
- 0.1.0-125 — 2020-09-02
- 0.1.0-123 — 2020-07-13
- 0.1.0-121 — 2020-07-02
- 0.1.0-119 — 2020-05-14
- 0.1.0-117 — 2020-03-24
- … 62 more at https://npm.io/package/puppeteer-salesforce-library/versions

## README

[![Build status](https://badge.buildkite.com/ead7a24f74896160638731c80e2139a1ccbe9b56d33c8107b7.svg)](https://buildkite.com/rea/puppeteer-salesforce-library)

# puppeteer-salesforce-library


### What is PSL(puppeteer-salesforce-library)?

> PSL is a collection of functions to help with Salesforce E2E tests based on [Puppeteer](https://github.com/GoogleChrome/puppeteer#readme).   


### Installation
> PSL is available on [npm](http://npmjs.org/). To install it, type:

 ```
 $ npm install puppeteer-salesforce-library
 ```
 
### Usage
> Import the library in your code, and then pick up the one you want to use: `login`, `logout`, `cpqFunctions` and `genericFunctions`.

```js
const psl = require('puppeteer-salesforce-library');
const login = psl.login;
const logout = psl.logout;
const cpq = psl.cpqFunctions;
const gf = psl.genericFunctions;
```

#### Login
Login package provides the capability to start a real/headless chrome and login as user.

##### launchChrome(headless, executablePath)
- Open up a chrome real/headless browser 
- `headless` <[boolean]> Launch chrome by using headless driver or not
- `executablePath` <[String]> Path to a Chromium or Chrome executable to run instead of the bundled Chromium. Default: null
- `return` <[Object]> Browser object by puppeteer
- Example:
```js
await login.launchChrome(false);
```

##### loginToSalesforce(browser, url, userName, password)
- Login to Salesforce
- `browser` <[Object]> Puppeteer browser object
- `url` <[String]> Salesforce url you want to navigate to
- `userName` <[String]> Username for Salesforce to login 
- `password` <[String]> Password for username
- `return` <[Object]> Puppeteer page object
- Example:
```js
const browser = await login.launchChrome(false);
const page = await login.loginToSalesforce(browser, 'salesforce-url', 'username', 'password');
```

##### loginToJSForce(url, userName, password)
- Login to JSForce
- `url` <[String]> Salesforce url you want to navigate to
- `userName` <[String]> Username for Salesforce to login 
- `password` <[String]> Password for username
- `return` <[Object]> jsforce api Connection 
```js
const Connection = await login.loginToJSForce('salesforce-url', 'username', 'password');
```

#### Logout
Logout package provides the capability to close up the browser.

##### logoutSalesforce()
- Disconnect and close the browser
- Example:
```js
await logout.logoutSalesforce()
```

#### cpqFunctions
This package provides some generic functions to help interact with page elements.

##### switchToIframe(page)
- Load and get the page frame
- `page` <[Object]> Puppeteer page object
-`return` Puppeteer frame object
- Example:
```js
const frame = await switchToIframe(page);
```

##### waitForSpinner(page)
- Wait page spinner disappears
- `page` <[Object]> Puppeteer page object
- Example:
```js
await cpq.waitForSpinner(frame);
```

##### doubleClick(page, property)
- Double click on property
- `page` <[Object]> Puppeteer page object
- `property` <[String]> Property xpath
- Example:
```js
await cpq.doubelClick(frame, '//xpath');
```

##### enter(page, property, textValue)
- Enter text
- `page` <[Object]> Puppeteer page object
- `property` <[String]> Property xpath
- `textValue` <[String]> Text wants to enter
- Example:
```js
await cpq.enter(frame, '//xpath', 'Text wants to enter');
```

##### click(page, property)
- Click on property
- `page` <[Object]> Puppeteer page object
- `property` <[String]> Property xpath
- Example:
```js
await cpq.click(frame, '//xpath');
```

##### enterDate(page, frame, property, fieldName, date)
- Enter a date
- `page` <[Object]> Puppeteer page object
- `frame` <[Object]> Puppeteer frame object
- `property` <[String]> Property xpath
- `fieldName` <[String]> Date field name
- `date` <[String]> Date wants to enter
- Example:
```js
await cpq.enterDate(page, frame, '//xpath', 'Start Date', '2018-08-12');
```

##### dropdown(page, fieldName, value)
- Select value from dropdown
- `page` <[Object]> Puppeteer page object
- `fieldName` <[String]> Dropdown field name
- `value` <[String]> Dropdown value wants to select
- Example:
```js
await cpq.dropdown(page, 'Payment Type', 'Cash');
```

##### priceBook(page)
- Open the price book and click save button
- `page` <[Object]> Puppeteer page object
- `return` <[Object]> Puppeteer frame object: frame for price book
- Example:
```js
const frame = await cpq.priceBook(page);
```

##### quoteDocumentVisible(page)
- Show quote document frame
- `page` <[Object]> Puppeteer page object
- `return` <[Object]> Puppeteer frame object: frame for quote document
- Example:
```js
const frame = await cpq.quoteDocumentVisible(page);
```

##### calender(page, fieldName, dt, today = '')
- Enter calendar date
- `page` <[Object]> Puppeteer page object
- `fieldName` <[String]> Calendar field name
- `dt` <[String]> Date value, format: 'DD/MM/YYYY'
- `today` <[String]> Is today: any string means today, empty string means not today. Default: ''
- Example:
```js
await cpq.calender(frame, 'Start Date', '19/11/2018', 'yes');
```

#### genericFunctions
This package provides some generic functions for Salesforce components

##### xpathClick(page, xpath)
- Click element by xpath
- `page` <[Object]> Puppeteer page object
- `xpath` <[String]> xpath for clickable element
- Example:
```js
await gf.xpathClick(page, '//xpath');
```

##### click(page, tabTitle)
- Click on tab title button
- `page` <[Object]> Puppeteer page object
- `tabTitle` <[String]> Tab title text
- Example:
```js
await gf.click(page, 'Accounts');
```

##### selectRecordType(page, rectype)
- Select record type
- `page` <[Object]> Puppeteer page object
- `rectype` <[String]> Record type text value
- Example:
```js
await gf.selectRecordType(page, 'Business');
```

##### footerButton(page, buttonName)
- Click on footer button of a frame
- `page` <[Object]> Puppeteer page object
- `buttonName` <[String]> Clickable button text value on the bottom of a frame
- Example:
```js
await gf.footerButton(page, 'Next');
```

##### textInput(page, label, value)
- Fill in text input
- `page` <[Object]> Puppeteer page object
- `label` <[String]> Label name for field filled in
- `value` <[String]> Filled in value
- Example:
```js
await nav.textInput(page, 'Reference Number', '738475');
```

##### checkBoxInput(page, label)
- Check a checkbox 
- `page` <[Object]> Puppeteer page object
- `label` <[String]> Label name for checkbox
- Example:
```js
await gf.checkBoxInput(page, 'Primary');
```

##### fillForm(page, record)
- Fill in a form
- `page` <[Object]> Puppeteer page object
- `record` <[Json]> Key: field name; Value: value filled in
- Example:
```js
const product = {
  productName: 'Gold Agent Subscription',
  discount: '20',
};
await gf.fillForm(page, product);
```

##### textArea(page, label, value)
- Fill in a text area
- `page` <[Object]> Puppeteer page object
- `label` <[String]> Label name for textarea
- `value` <[String]> Text filled in textarea
- Example:
```js
await gf.textArea(page, 'Comments', 'Approved');
```

##### emailInput(page, label, value)
- Fill in an email input
- `page` <[Object]> Puppeteer page object
- `label` <[String]> Label name for email input
- `value` <[String]> Text filled in email input
- Example:
```js
await gf.emailInput(page, 'Email', 'a@b.com');
```

##### dropdown(page, fieldName, value)
- Select dropdown value
- `page` <[Object]> Puppeteer page object
- `fieldName` <[String]> Field name for dropdown
- `value` <[String]> Text filled in email input
- Example:
```js
await gf.dropdown(page, 'Payment Type', 'Cash');
```

##### relatedTab(page, relate)
- Click on sub related tab
- `page` <[Object]> Puppeteer page object
- `relate` <[String]> Related tab name
- Example:
```js
await gf.relatedTab(page, 'Related');
```

##### relatedNewContact(page, newContact)
- Click on new contact tag
- `page` <[Object]> Puppeteer page object
- `newContact` <[String]> New contact tab name
- Example:
```js
await gf.relatedNewContact(page, 'New Contact');
```

##### relatedNewButton(page, labelName)
- Click on new button
- `page` <[Object]> Puppeteer page object
- `labelName` <[String]> New button text
- Example:
```js
await gf.relatedNewButton(page, 'Alternative Billing Contacts');
```

##### search(page, label, value)
- Search text in search box
- `page` <[Object]> Puppeteer page object
- `label` <[String]> Searched text input label
- `value` <[String]> Searched text
- Example:
```js
await gf.search(page, 'Billing Information', 'SGD - Singapore Dollar');
```

##### waitForVisualForceMessage(page)
- Wait the visual toast message
- `page` <[Object]> Puppeteer page object
- `return` <[String]> Visual message text
- Example:
```js
const message = await gf.waitForVisualForceMessage(page);
```

##### globalSearch(page, searchValue, searchType)
- Search by types: on the top search bar, select type and fill in text value then click on the result
- `page` <[Object]> Puppeteer page object
- `searchValue` <[String]> Text value for search
- `searchType` <[String]> Type for search
- Example:
```js
await gf.globalSearch(page, 'Q-20123', 'Quotes');
```

##### captureHeading(page, searchType)
- Check if header exists
- `page` <[Object]> Puppeteer page object
- `searchType` <[String]> Type for header
- `return` <[boolean]>
- Example:
```js
await gf.captureHeading(page, 'Opportunity')
```

##### getInnerText(page, xpath)
- Get the text content by xpath
- `page` <[Object]> Puppeteer page object
- `xpath` <[String]> xpath for the text
- `return` <[String]> Text content
- Example:
```js
const text = await gf.getInnerText(page, '//xpath');
```

##### lookUpLink(page, labelName, value)
- Look up the link by label name and value
- `page` <[Object]> Puppeteer page object
- `labelName` <[String]> Label title
- `value` <[String]> Link text under label
- Example:
```js
await gf.lookUpLink(page, 'Account', 'link text');
```

##### screenShot(page, filename = '')
- Screen shot the page, mainly used when having error or test fails
- `page` <[Object]> Puppeteer page object
- `filename` <[String]> Screenshot name
- Example:
```js
await gf.screenShot(page, 'Failed to login');
```

##### modalButton(page)
- Close modal
- `page` <[Object]> Puppeteer page object
- Example:
```js
await gf.modalButton(page);
```

##### reload(page)
- Reload page
- `page` <[Object]> Puppeteer page object
- Example:
```js
await gf.reload(page);
```

##### isVisible(page, selector)
- Check dom visible
- `page` <[Object]> Puppeteer page object
- `selector` <[String]> Dom selector
- Example:
```js
await gf.isVisible(page, 'div.slds-truncate[title=New]');
```

##### getDetailsPageFieldValues(page, fieldName, property)
- Get details page filed value by name and xpath
- `page` <[Object]> Puppeteer page object
- `fieldName` <[String]> Field name
- `property` <[String]> Property xpath
- `return` <[String]> Field text value
- Example:
```js
const startDate = await gf.getDetailsPageFieldValues(page, 'Start Date', '//xpath');
```

##### switchToNewPage(browser)
- Go to a new browser tab
- `browser` <[Object]> Puppeteer browser object
- `return` <[Object]> Puppeteer page object
- Example:
```js
const newPage = await gf.switchToNewPage(browser);
```

##### switchToMainPage(browser)
- Go to the first browser page
- `browser` <[Object]> Puppeteer browser object
- `return` <[Object]> Puppeteer page object
- Example:
```js
const mainPage = await gf.switchToMainPage(browser);
```

##### replaceXpath(elementProperty, valueToBeReplaced)
- Replace the value in xpath
- `elementProperty` <[String]> Text needs to replace
- `valueToBeReplaced` <[String]> Text wants to be replaced to
- `return` <[String]> xpath after replace
- Example:
```js
const checkboxXpath = gf.replaceXpath("//span[text()='propertyToBeReplaced']", 'HERO + Billboard 1');
```

##### scrollDown(page)
- Scroll down the page
- `page` <[Object]> Puppeteer page object
- Example:
```js
await gf.scrollDown(pageXOffset);
```

##### formatAmount(amount)
- Format the text to trim and get the number before '('
- `amount` <[String]> Text to be formatted
- `return` <[String]> Text after formatted
- Example:
```js
const amount = gf.formatAmount('100.3 (HK Dollar)'); // 100.3
```

##### keyBoardPress(page)
- Press tab button on keyboard on page
- `page` <[Object]> Puppeteer page object
- Example:
```js
await gf.keyBoardPress(page);
```

##### submitForApproval(page, buttonName)
- Click on the submit for approval button
- `page` <[Object]> Puppeteer page object
- `buttonName` <[String]> Submit for approval button text
- Example:
```js
await gf.submitForApproval(page, 'Submit');
```

##### buttonClick(page, property, textValue)
- Click on the button found by property xpath and text
- `page` <[Object]> Puppeteer page object
- `property` <[String]> xpath for the normal button selector
- `textValue` <[String]> button text to be replaced
- Example:
```js
await gf.buttonClick(page, '//xpath', 'Convert');
```

##### globalSearchResultsClick(page, searchValue, searchType, retryCounter = 0)
- Click result after global search
- `page` <[Object]> Puppeteer page object
- `searchValue` <[String]> searched value
- `searchType` <[String]> searched type
- `retryCounter` <[String]> retied times. Default: 0
- Example:
```js
await gf.globalSearchResultsClick(page, 'account name', 'Accounts');
```

---
_Source: https://npm.io/package/puppeteer-salesforce-library · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
