puppeteer-salesforce-library
What is PSL(puppeteer-salesforce-library)?
PSL is a collection of functions to help with Salesforce E2E tests based on Puppeteer.
Installation
PSL is available on npm. 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
andgenericFunctions
.
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:
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:
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
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:
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:
const frame = await switchToIframe(page);
waitForSpinner(page)
- Wait page spinner disappears
-
page
<[Object]> Puppeteer page object - Example:
await cpq.waitForSpinner(frame);
doubleClick(page, property)
- Double click on property
-
page
<[Object]> Puppeteer page object -
property
<[String]> Property xpath - Example:
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:
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:
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:
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:
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:
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:
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:
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:
await gf.xpathClick(page, '//xpath');
click(page, tabTitle)
- Click on tab title button
-
page
<[Object]> Puppeteer page object -
tabTitle
<[String]> Tab title text - Example:
await gf.click(page, 'Accounts');
selectRecordType(page, rectype)
- Select record type
-
page
<[Object]> Puppeteer page object -
rectype
<[String]> Record type text value - Example:
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:
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:
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:
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:
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:
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:
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:
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:
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:
await gf.relatedNewContact(page, 'New Contact');
relatedNewButton(page, labelName)
- Click on new button
-
page
<[Object]> Puppeteer page object -
labelName
<[String]> New button text - Example:
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:
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:
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:
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:
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:
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:
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:
await gf.screenShot(page, 'Failed to login');
modalButton(page)
- Close modal
-
page
<[Object]> Puppeteer page object - Example:
await gf.modalButton(page);
reload(page)
- Reload page
-
page
<[Object]> Puppeteer page object - Example:
await gf.reload(page);
isVisible(page, selector)
- Check dom visible
-
page
<[Object]> Puppeteer page object -
selector
<[String]> Dom selector - Example:
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:
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:
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:
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:
const checkboxXpath = gf.replaceXpath("//span[text()='propertyToBeReplaced']", 'HERO + Billboard 1');
scrollDown(page)
- Scroll down the page
-
page
<[Object]> Puppeteer page object - Example:
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:
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:
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:
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:
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:
await gf.globalSearchResultsClick(page, 'account name', 'Accounts');