puppeteer-salesforce-library v0.1.0-149
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-libraryUsage
Import the library in your code, and then pick up the one you want to use:
login,logout,cpqFunctionsandgenericFunctions.
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 notexecutablePath<String> Path to a Chromium or Chrome executable to run instead of the bundled Chromium. Default: nullreturn<Object> Browser object by puppeteer- Example:
await login.launchChrome(false);loginToSalesforce(browser, url, userName, password)
- Login to Salesforce
browser<Object> Puppeteer browser objecturl<String> Salesforce url you want to navigate touserName<String> Username for Salesforce to loginpassword<String> Password for usernamereturn<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 touserName<String> Username for Salesforce to loginpassword<String> Password for usernamereturn<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 -returnPuppeteer 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)
await cpq.doubelClick(frame, '//xpath');enter(page, property, textValue)
- Enter text
page<Object> Puppeteer page objectproperty<String> Property xpathtextValue<String> Text wants to enter- Example:
await cpq.enter(frame, '//xpath', 'Text wants to enter');click(page, property)
await cpq.click(frame, '//xpath');enterDate(page, frame, property, fieldName, date)
- Enter a date
page<Object> Puppeteer page objectframe<Object> Puppeteer frame objectproperty<String> Property xpathfieldName<String> Date field namedate<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 objectfieldName<String> Dropdown field namevalue<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 objectreturn<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 objectreturn<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 objectfieldName<String> Calendar field namedt<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 objectxpath<String> xpath for clickable element- Example:
await gf.xpathClick(page, '//xpath');click(page, tabTitle)
- Click on tab title button
page<Object> Puppeteer page objecttabTitle<String> Tab title text- Example:
await gf.click(page, 'Accounts');selectRecordType(page, rectype)
- Select record type
page<Object> Puppeteer page objectrectype<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 objectbuttonName<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 objectlabel<String> Label name for field filled invalue<String> Filled in value- Example:
await nav.textInput(page, 'Reference Number', '738475');checkBoxInput(page, label)
await gf.checkBoxInput(page, 'Primary');fillForm(page, record)
- Fill in a form
page<Object> Puppeteer page objectrecord<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 objectlabel<String> Label name for textareavalue<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 objectlabel<String> Label name for email inputvalue<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 objectfieldName<String> Field name for dropdownvalue<String> Text filled in email input- Example:
await gf.dropdown(page, 'Payment Type', 'Cash');relatedTab(page, relate)
await gf.relatedTab(page, 'Related');relatedNewContact(page, newContact)
- Click on new contact tag
page<Object> Puppeteer page objectnewContact<String> New contact tab name- Example:
await gf.relatedNewContact(page, 'New Contact');relatedNewButton(page, labelName)
await gf.relatedNewButton(page, 'Alternative Billing Contacts');search(page, label, value)
- Search text in search box
page<Object> Puppeteer page objectlabel<String> Searched text input labelvalue<String> Searched text- Example:
await gf.search(page, 'Billing Information', 'SGD - Singapore Dollar');waitForVisualForceMessage(page)
- Wait the visual toast message
page<Object> Puppeteer page objectreturn<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 objectsearchValue<String> Text value for searchsearchType<String> Type for search- Example:
await gf.globalSearch(page, 'Q-20123', 'Quotes');captureHeading(page, searchType)
- Check if header exists
page<Object> Puppeteer page objectsearchType<String> Type for headerreturn<boolean>- Example:
await gf.captureHeading(page, 'Opportunity')getInnerText(page, xpath)
- Get the text content by xpath
page<Object> Puppeteer page objectxpath<String> xpath for the textreturn<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 objectlabelName<String> Label titlevalue<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 objectfilename<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)
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 objectfieldName<String> Field nameproperty<String> Property xpathreturn<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 objectreturn<Object> Puppeteer page object- Example:
const newPage = await gf.switchToNewPage(browser);switchToMainPage(browser)
- Go to the first browser page
browser<Object> Puppeteer browser objectreturn<Object> Puppeteer page object- Example:
const mainPage = await gf.switchToMainPage(browser);replaceXpath(elementProperty, valueToBeReplaced)
- Replace the value in xpath
elementProperty<String> Text needs to replacevalueToBeReplaced<String> Text wants to be replaced toreturn<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 formattedreturn<String> Text after formatted- Example:
const amount = gf.formatAmount('100.3 (HK Dollar)'); // 100.3keyBoardPress(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 objectbuttonName<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 objectproperty<String> xpath for the normal button selectortextValue<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 objectsearchValue<String> searched valuesearchType<String> searched typeretryCounter<String> retied times. Default: 0- Example:
await gf.globalSearchResultsClick(page, 'account name', 'Accounts');4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago