CumulusCI Robot Framework Keywords

filter:

CumulusCI

cumulusci.robotframework.CumulusCI

Library for accessing CumulusCI for the local git project

This library allows Robot Framework tests to access credentials to a Salesforce org created by CumulusCI, including Scratch Orgs. It also exposes the core logic of CumulusCI including interactions with the Salesforce API's and project specific configuration including custom and customized tasks and flows.

Initialization requires a single argument, the org name for the target CumulusCI org. If running your tests via cci's robot task (recommended), you can initialize the library in your tests taking advantage of the variable set by the robot task:

*** Settings ***

Library  cumulusci.robotframework.CumulusCI  ${ORG}
Keyword Arguments Documentation
Debug

Pauses execution and enters the Python debugger.

Get Community Info community_name, key=None, force_refresh=False

This keyword uses the Salesforce API to get information about a community.

This keyword requires the exact community name as its first argumment.

  • If no key is given, all of the information returned by the API will be returned by this keyword in the form of a dictionary
  • If a key is given, only the value for that key will be returned.

Some of the supported keys include name, siteUrl, and loginUrl. For a comprehensive list see the API documentation, or call this keyword without the key argument and examine the results.

An API call will be made the first time this keyword is used, and the return values will be cached. Subsequent calls will not call the API unless the requested community name is not in the cached results, or unless the force_refresh parameter is set to True.

Get Namespace Prefix package=None

Returns the namespace prefix (including __) for the specified package name. (Defaults to project__package__name_managed from the current project config.)

Returns an empty string if the package is not installed as a managed package.

Get Org Info

Returns a dictionary of the org information for the current target Salesforce org

Login Url org=None, **userfields

Returns the login url which will automatically log into the target Salesforce org. By default, the org_name passed to the library constructor is used but this can be overridden with the org option to log into a different org.

If userfields are provided, the username and access token for the given user will be used. If not provided, the access token for the org's default user will be used.

The userfields argument is largely useful for scratch orgs, but can also work with connected persistent orgs if you've connected the org with the given username.

Example:

${login url}=  Login URL  alias=dadvisor
Run Task task_name, **options

Runs a named CumulusCI task for the current project with optional support for overriding task options via kwargs.

Note: task_name can be prefixed with the name of another project, just the same as when running the task from the command line. The other project needs to have been defined in the 'sources' section of cumulusci.yml.

The task output will appear in the robot log.

Examples:

Keyword task_name task_options comment
Run Task deploy Run deploy with standard options
Run Task deploy path=path/to/some/metadata Run deploy with custom path
Run task npsp:deploy_rd2_config Run the deploy_rd2_config task from the NPSP project
Run Task Class class_path, **options

Runs a CumulusCI task class with task options via kwargs.

Use this keyword to run logic from CumulusCI tasks which have not been configured in the project's cumulusci.yml file. This is most useful in cases where a test needs to use task logic for logic unique to the test and thus not worth making into a named task for the project

The task output will appear in the robot log.

Examples:

Keyword task_class task_options
Run Task Class cumulusci.task.utils.DownloadZip url=http://test.com/test.zip dir=test_zip
Set Login Url

Sets the LOGIN_URL variable in the suite scope which will automatically log into the target Salesforce org.

Typically, this is run during Suite Setup

Set Project Config project_config

PageObjects

cumulusci.robotframework.PageObjects

Keyword library for importing and using page objects

When importing, you can include one or more paths to python files that define page objects. For example, if you have a set of classes in robot/HEDA/resources/PageObjects.py, you can import this library into a test case like this:

Library  cumulusci.robotframework.PageObjects
...  robot/HEDA/resources/PageObjects.py

Page object classes need to use the @pageobject decorator from cumulusci.robotframework.pageobjects. The decorator takes two parameters: page_type and object_name. Both are arbitrary strings, but together should uniquely identify a collection of keywords for a page or objects on a page.

Examples of page_type are Listing, Home, Detail, etc. Object types can be actual object types (Contact), custom object (Custom_object__c) or a logical name for a type of page (eg: AppointmentManager).

Example:

from cumulusci.robotframework.pageobjects import BasePage
from cumulusci.robotframework.pageobjects import pageobject
...
@pageobject(page_type="Detail", object_name="Custom__c")
class CustomDetailPage(BasePage):
    ...
Keyword Arguments Documentation
Current Page Should Be page_type, object_name, **kwargs

Verifies that the page appears to be the requested page

If the page matches the given page object or contains the given page object, the keyword will pass.a

When this keyword is called, it will try to get the page object for the given page_tyope and object_name, and call the method `_is_current_page`.

Custom page objects may define this function in whatever manner is necessary to determine that the current page is or contains the given page object. The only requirement is that this function raise an exception if it determines the current page either doesn't represent the page object or doesn't contain the page object.

The default implementation of the function uses the page URL and compares it to a pattern based off of the page_type and object_name.

Get Page Object page_type, object_name

Return an instance of a page object

This is useful if you want to call a single page object method from some other keyword without having to go to another page or load the page object into a page.

This works a lot like robot's built-in "get library instance" keyword, but you can specify the page object by page type and object name rather than the library name, and it will autoload the appropriate library (assuming its module has been imported).

Go To Page page_type, object_name, *args, **kwargs

Go to the page of the given page object.

The URL will be computed from the page_type and object_name associated with the object, plus possibly additional arguments.

Different pages support different additional arguments. For example, a Listing page supports the keyword argument `filter_name`, and a Detail page can be given an object id, or parameters for looking up the object id.

If this keyword is able to navigate to a page, the keyword `load page object` will automatically be called to load the keywords for the page.

Custom page objects may define the function `_go_to_page`, which will be passed in all of the keyword arguments from this keyword. This allows each page object to define its own URL mapping using whatever algorithm it chooses. The only requirement of the function is that it should compute an appropriate url and then call `self.selenium.go_to` with the URL.

It is also recommended that the keyword wait until it knows that the page has finished rendering before returning (eg: by calling `self.salesforce.wait_until_loading_is_complete()`)

Load Page Object page_type, object_name=None

Load the keywords for the page object identified by the type and object name

The page type / object name pair must have been registered using the cumulusci.robotframework.pageobject decorator.

Log Page Object Keywords

Logs page objects and their keywords for all page objects which have been imported into the current suite.

Wait For Modal page_type, object_name, expected_heading=None, **kwargs

Wait for the given page object modal to appear.

This will wait for modal to appear. If an expected heading is provided, it will also validate that the modal has the expected heading.

Example:

Wait for modal to appear    New    Contact   expected_heading=New Contact
Wait For Page Object page_type, object_name, **kwargs

Wait for an element represented by a page object to appear on the page.

The associated page object will be loaded after the element appears.

page_type represents the page type (Home, Details, etc)) and object_name represents the name of an object (Contact, Organization, etc)

Performance

cumulusci.robotframework.Performance

Keywords for performance testing.

For more information on how to use these keywords, see the "Performance Testing" section of the CumulusCI documentation.

Keyword Arguments Documentation
Elapsed Time For Last Record obj_name, start_field, end_field, order_by, **kwargs

For records representing jobs or processes, compare the record's start-time to its end-time to see how long a process took.

Arguments: obj_name: SObject to look for last record start_field: Name of the datetime field that represents the process start end_field: Name of the datetime field that represents the process end order_by: Field name to order by. Should be a datetime field, and usually is just the same as end_field. where: Optional Where-clause to use for filtering Other keywords are used for filtering as in the Salesforce Query keywordf

The last matching record queried and summarized.

Example:

${time_in_seconds} =    Elapsed Time For Last Record
...             obj_name=AsyncApexJob
...             where=ApexClass.Name='BlahBlah'
...             start_field=CreatedDate
...             end_field=CompletedDate
...             order_by=CompletedDate
Set Test Elapsed Time elapsedtime

This keyword captures a computed rather than measured elapsed time for performance tests.

For example, if you were performance testing a Salesforce batch process, you might want to store the Salesforce-measured elapsed time of the batch process instead of the time measured in the CCI client process.

The keyword takes a single argument which is either a number of seconds or a Robot time string (https://robotframework.org/robotframework/latest/libraries/DateTime.html#Time%20formats).

Using this keyword will automatically add the tag cci_metric_elapsed_time to the test case and ${cci_metric_elapsed_time} to the test's variables. cci_metric_elapsed_time is not included in Robot's html statistical roll-ups.

Example:

Set Test Elapsed Time       11655.9

Performance test times are output in the CCI logs and are captured in MetaCI instead of the "total elapsed time" measured by Robot Framework. The Robot "test message" is also updated.

Set Test Metric metric: str, value=None

This keyword captures any metric for performance monitoring.

For example: number of queries, rows processed, CPU usage, etc.

The keyword takes a metric name, which can be any string, and a value, which can be any number.

Using this keyword will automatically add the tag cci_metric to the test case and ${cci_metric_<metric_name>} to the test's variables. These permit downstream processing in tools like CCI and MetaCI.

cci_metric is not included in Robot's html statistical roll-ups.

Example:

Set Test Metric    Max_CPU_Percent    30

Performance test metrics are output in the CCI logs, log.html and output.xml. MetaCI captures them but does not currently have a user interface for displaying them.

Start Performance Timer

Start an elapsed time stopwatch for performance tests.

See the docummentation for *Stop Performance Timer* for more information.

Example:

Start Performance Timer
Do Something
Stop Performance Timer
Stop Performance Timer

Record the results of a stopwatch. For perf testing.

This keyword uses Set Test Elapsed Time internally and therefore outputs in all of the ways described there.

Example:

Start Performance Timer
Do Something
Stop Performance Timer

Salesforce

cumulusci.robotframework.Salesforce

A keyword library for working with Salesforce Lightning pages

While you can import this directly into any suite, the recommended way to include this in a test suite is to import the Salesforce.robot resource file.

Keyword Arguments Documentation
Breakpoint

Serves as a breakpoint for the robot debugger

Note: this keyword is a no-op unless the robot_debug option for the task has been set to true. Unless the option has been set, this keyword will have no effect on a running test.

Click Modal Button title

Clicks a button in a Lightning modal.

Click Object Button title

Clicks a button in an object's actions.

Close Modal

Closes the open modal

Create Webdriver With Retry *args, **kwargs

Call the Create Webdriver keyword.

Retry on connection resets which can happen if custom domain propagation is slow.

Current App Should Be app_name

Validates the currently selected Salesforce App

Field Value Should Be label, expected_value

Verify that the form field for the given label is the expected value

Example:

Field value should be    Account Name    ACME Labs
Get Active Browser Ids

Return the id of all open browser ids

Get Current Record Id

Parses the current url to get the object id of the current record. Expects url format like: [a-zA-Z0-9]{15,18}

Get Fake Data fake, *args, **kwargs

Return fake data

This uses the Faker library to provide fake data in a variety of formats (names, addresses, credit card numbers, dates, phone numbers, etc) and locales (en_US, fr_FR, etc).

The fake argument is the name of a faker property such as first_name, address, lorem, etc. Additional arguments depend on type of data requested. For a comprehensive list of the types of fake data that can be generated see Faker providers in the Faker documentation.

The return value is typically a string, though in some cases some other type of object will be returned. For example, the date_between fake returns a datetime.date object. Each time a piece of fake data is requested it will be regenerated, so that multiple calls will usually return different data.

This keyword can also be called using robot's extended variable syntax using the variable ${faker}. In such a case, the data being asked for is a method call and arguments must be enclosed in parentheses and be quoted. Arguments should not be quoted when using the keyword.

To generate fake data for a locale other than en_US, use the keyword Set Faker Locale prior to calling this keyword.

Examples

# Generate a fake first name
${first_name}=  Get fake data  first_name
# Generate a fake date in the default format
${date}=  Get fake data  date
# Generate a fake date with an explicit format
${date}=  Get fake data  date  pattern=%Y-%m-%d
# Generate a fake date using extended variable syntax
Input text  //input  ${faker.date(pattern='%Y-%m-%d')}
Get Field Value label

Return the current value of a form field based on the field label

Get Locator path, *args, **kwargs

Returns a rendered locator string from the Salesforce lex_locators dictionary. This can be useful if you want to use an element in a different way than the built in keywords allow.

Go To Object Home obj_name

Navigates to the Home view of a Salesforce Object

Go To Object List obj_name, filter_name=None

Navigates to the Home view of a Salesforce Object

Go To Record Home obj_id

Navigates to the Home view of a Salesforce Object

Go To Setup Home

Navigates to the Home tab of Salesforce Setup

Go To Setup Object Manager

Navigates to the Object Manager tab of Salesforce Setup

Header Field Should Be Checked label

Validates that a checkbox field in the record header is checked

Header Field Should Be Unchecked label

Validates that a checkbox field in the record header is unchecked

Header Field Should Have Value label

Validates that a field in the record header has a text value. NOTE: Use other keywords for non-string value types

Header Field Should Not Have Value label

Validates that a field in the record header does not have a value. NOTE: Use other keywords for non-string value types

Initialize Location Strategies

Initialize the Salesforce custom location strategies

Note: This keyword is called automatically from Open Test Browser

Input Form Data *args

Fill in one or more labeled input fields fields with data

Arguments should be pairs of field labels and values. Labels for required fields should not include the asterisk. Labels must be exact, including case.

This keyword uses the keyword Locate Element by Label to locate elements. More details about how elements are found are in the documentation for that keyword.

For most input form fields the actual value string will be used. For a checkbox, passing the value "checked" will check the checkbox and any other value will uncheck it. Using "unchecked" is recommended for clarity. For radiobuttons, you must pass the string "selected" for the value.

Example:

Input form data
...  Opportunity Name         The big one       # required text field
...  Amount                   1b                # currency field
...  Close Date               4/01/2022         # date field
...  Private                  checked           # checkbox
...  Type                     New Customer      # combobox
...  Primary Campaign Source  The Big Campaign  # picklist

Example setting a radio button:

In this example, the radiobutton group has the label "Who sees this list view?", and one of the radiobuttons has the label "All users can see this list view"

Input form data
...  Who sees this list view?::All users can see this list view    selected

This keyword will eventually replace the "populate form" keyword once it has been more thoroughly tested in production.

Log Browser Capabilities loglevel=INFO

Logs all of the browser capabilities as reported by selenium

Open App Launcher retry=True

Opens the Saleforce App Launcher Modal

Note: starting with Spring '20 the app launcher button opens a menu rather than a modal. To maintain backwards compatibility, this keyword will continue to open the modal rather than the menu. If you need to interact with the app launcher menu, you will need to create a custom keyword.

If the retry parameter is true, the keyword will close and then re-open the app launcher if it times out while waiting for the dialog to open.

Populate Field name, value

Enters a value into an input or textarea field.

'name' represents the label on the page (eg: "First Name"), and 'value' is the new value.

Any existing value will be replaced.

Populate Form **kwargs

Enters multiple values from a mapping into form fields.

Populate Lookup Field name, value

Enters a value into a lookup field.

Scroll Element Into View locator

Scroll the element identified by 'locator'

This is a replacement for the keyword of the same name in SeleniumLibrary. The SeleniumLibrary implementation uses an unreliable method on Firefox. This keyword uses a more reliable technique.

For more info see https://stackoverflow.com/a/52045231/7432

Select App Launcher App app_name

Navigates to a Salesforce App via the App Launcher

Select App Launcher Tab tab_name

Navigates to a tab via the App Launcher

Select Record Type label

Selects a record type while adding an object.

Select Window locator=MAIN, timeout=None

Alias for SeleniuimLibrary 'Switch Window'

This keyword was removed from SeleniumLibrary 5.x, but some of our tests still use this keyword. You can continue to use this, but should replace any calls to this keyword with calls to 'Switch Window' instead.

Selenium Execute With Retry execute, command, params

Run a single selenium command and retry once.

The retry happens for certain errors that are likely to be resolved by retrying.

Set Faker Locale locale

Set the locale for fake data

This sets the locale for all calls to the Faker keyword and ${faker} variable. The default is en_US

For a list of supported locales see Localized Providers in the Faker documentation.

Example

Set Faker Locale    fr_FR
${french_address}=  Faker  address
Wait For Aura

Run the WAIT_FOR_AURA_SCRIPT.

This script polls Aura via $A in Javascript to determine when all in-flight XHTTP requests have completed before continuing.

Wait Until Loading Is Complete locator=None

Wait for LEX page to load.

(We're actually waiting for the actions ribbon to appear.)

Wait Until Modal Is Closed

Wait for modal to close

Wait Until Modal Is Open

Wait for modal to open

Wait Until Salesforce Is Ready locator=None, timeout=None, interval=5

Waits until we are able to render the initial salesforce landing page

It will continue to refresh the page until we land on a lightning page or until a timeout has been reached. The timeout can be specified in any time string supported by robot (eg: number of seconds, "3 minutes", etc.). If not specified, the default selenium timeout will be used.

This keyword will wait a few seconds between each refresh, as well as wait after each refresh for the page to fully render (ie: it calls wait_for_aura())

Salesforce.robot

cumulusci/robotframework/Salesforce.robot

This resource file imports the Salesforce and CumulusCI keyword libraries, along with several other commonly used libraries (Collections, OperatingSystem, String, XML). In addition, it defines several other keywords.

This resource file also defines several global variables, including ${BROWSER}, ${ORG}, and ${DEFAULT_BROWSER_SIZE}

This resource file should be included in every test suite, like in the following example (note: there should be two or more spaces after Resource):

*** Settings ***
Resource cumulusci/robotframework/Salesforce.robot
Keyword Arguments Documentation
Chrome Set Binary options

Sets the 'options.binary_location' value in the chrome options dictionary to the value of the environment variable CHROME_BINARY, if set.

This keyword is not intended to be used by test scripts

Chrome Set Headless options

This keyword is used to set the chrome options dictionary values required to run headless chrome.

This keyword is not intended to be used by test scripts

Delete Records and Close Browser

This will close all open browser windows and then delete all records that were created with the Salesforce API during this testing session.

Get Chrome Options

Returns a dictionary of chrome options, for use by the keyword `Open Test Browser`.

This keyword is not intended to be used by test scripts.

Locate Element By Text browser, locator, tag, constraints

This is registered as a custom locator strategy named text. It is shorthand for the locator //*[text()=...]

Example:

Wait until page contains element text:Mobile Publisher
Locate Element By Title browser, locator, tag, constraints

This is registered as a custom locator strategy named title. It is shorthand for the locator //*[@title=...]

Example:

Wait until page contains element title:Object Manager
Open Test Browser size=${DEFAULT BROWSER SIZE}, alias=${NONE}, wait=True, useralias=${NONE}

Opens a test browser to the org.

The variable ${BROWSER} determines which browser should open. The following four browsers are explicitly supported: chrome, firefox, headlesschrome, and headlessfirefox. Any other value will be passed directly to the SeleniumLibrary 'Open Browser' keyword.

Once the browser has been opened, it will be set to the given size (default=${DEFAULT BROWSER SIZE})

If you open multiple browsers you can use the optional argument `alias` to give each browser a name. This name can be used when calling the `Switch Browser` keyword from SeleniumLibrary

The optional argument 'useralias' may be used to specify a specific user by their alias; if not specified then the org's default user will be used.

The keyword `Log Browser Capabilities` will automatically be called. The keyword will also call `Wait Until Salesforce is Ready` unless the `wait` parameter is set to False.

Open Test Browser Chrome login_url, alias=${NONE}

Opens a Chrome browser window and navigates to the org This keyword isn't normally called directly by a test. It is used by the `Open Test Browser` keyword.

Open Test Browser Firefox login_url, alias=${NONE}

Opens a Firefox browser window and navigates to the org This keyword isn't normally called directly by a test. It is used by the `Open Test Browser` keyword.

The firefox profile is set to accept all cookies.

Open Test Browser Headless Firefox login_url, alias=${NONE}

Opens the firefox browser in headless mode This keyword isn't normally called directly by a test. It is used by the `Open Test Browser` keyword.

The firefox profile is set to accept all cookies.

SalesforceAPI

cumulusci.robotframework.SalesforceAPI

Keywords for interacting with Salesforce API

Keyword Arguments Documentation
Delete Session Records

Deletes records that were created while running this test case.

(Only records specifically recorded using the Store Session Record keyword are deleted.)

Generate Test Data obj_name, number_to_create, **fields

Generate bulk test data

This returns an array of dictionaries with template-formatted arguments which can be passed to the Salesforce Collection Insert keyword.

You can use {{number}} to represent the unique index of the row in the list of rows. If the entire string consists of a number, Salesforce API will treat the value as a number.

Example:

The following example creates three new Contacts:

@{objects} =  Generate Test Data  Contact  3
...  Name=User {{number}}
...  Age={{number}}

The example code will generate Contact objects with these fields:

[{'Name': 'User 0', 'Age': '0'},
 {'Name': 'User 1', 'Age': '1'},
 {'Name': 'User 2', 'Age': '2'}]

Python Expression Syntax is allowed so computed templates like this are also allowed: {{1000 + number}}

Python operators can be used, but no functions or variables are provided, so mostly you just have access to mathematical and logical operators. The Python operators are described here:

https://www.digitalocean.com/community/tutorials/how-to-do-math-in-python-3-with-operators

Contact the CCI team if you have a use-case that could benefit from more expression language power.

Templates can also be based on faker patterns like those described here:

https://faker.readthedocs.io/en/master/providers.html

Most examples can be pasted into templates verbatim:

@{objects}=  Generate Test Data  Contact  200
...  Name={{fake.first_name}} {{fake.last_name}}
...  MailingStreet={{fake.street_address}}
...  MailingCity=New York
...  MailingState=NY
...  MailingPostalCode=12345
...  Email={{fake.email(domain="salesforce.com")}}
Get Latest Api Version

Return the API version used by the current org

Get Record Type Id obj_type, developer_name

Returns the Record Type Id for a record type name

Remove Session Record obj_type, obj_id

Remove a record from the list of records that should be automatically removed.

Salesforce Collection Insert objects

Inserts records that were created with Generate Test Data.

objects is a list of data, typically generated by the Generate Test Data keyword.

A 200 record limit is enforced by the Salesforce APIs.

The object name and Id is passed to the Store Session Record keyword, and will be deleted when the keyword Delete Session Records is called.

As a best practice, either Delete Session Records or *Delete Records and Close Browser from Salesforce.robot should be called as a suite teardown.

Example:

@{objects}=  Generate Test Data  Contact  200
...  FirstName=User {{number}}
...  LastName={{fake.last_name}}
Salesforce Collection Insert  ${objects}
Salesforce Collection Update objects

Updates records described as Robot/Python dictionaries.

objects is a dictionary of data in the format returned by the Salesforce Collection Insert keyword.

A 200 record limit is enforced by the Salesforce APIs.

Example:

The following example creates ten accounts and then updates the Rating from "Cold" to "Hot"

${data}=  Generate Test Data  Account  10
...  Name=Account #{{number}}
...  Rating=Cold
${accounts}=  Salesforce Collection Insert  ${data}

FOR  ${account}  IN  @{accounts}
    Set to dictionary  ${account}  Rating  Hot
END
Salesforce Collection Update  ${accounts}
Salesforce Delete obj_name, obj_id

Deletes a Salesforce object by object name and Id.

Example:

The following example assumes that ${contact id} has been previously set. The example deletes the Contact with that Id.

Salesforce Delete  Contact  ${contact id}
Salesforce Get obj_name, obj_id

Gets a Salesforce object by Id and returns the result as a dict.

Example:

The following example assumes that ${contact id} has been previously set. The example retrieves the Contact object with that Id and then logs the Name field.

&{contact}=  Salesforce Get  Contact  ${contact id}
log  Contact name:  ${contact['Name']}
Salesforce Insert obj_name, **kwargs

Creates a new Salesforce object and returns the Id.

The fields of the object may be defined with keyword arguments where the keyword name is the same as the field name.

The object name and Id is passed to the Store Session Record keyword, and will be deleted when the keyword Delete Session Records is called.

As a best practice, either Delete Session Records or Delete Records and Close Browser from Salesforce.robot should be called as a suite teardown.

Example:

The following example creates a new Contact with the first name of "Eleanor" and the last name of "Rigby".

${contact id}=  Salesforce Insert  Contact
...  FirstName=Eleanor
...  LastName=Rigby
Salesforce Query obj_name, **kwargs

Constructs and runs a simple SOQL query and returns a list of dictionaries.

By default the results will only contain object Ids. You can specify a SOQL SELECT clause via keyword arguments by passing a comma-separated list of fields with the select keyword argument.

You can supply keys and values to match against in keyword arguments, or a full SOQL where-clause in a keyword argument named where. If you supply both, they will be combined with a SOQL "AND".

order_by and limit keyword arguments are also supported as shown below.

Examples:

The following example searches for all Contacts where the first name is "Eleanor". It returns the "Name" and "Id" fields and logs them to the robot report:

@{records}=  Salesforce Query  Contact  select=Id,Name
...          FirstName=Eleanor
FOR  ${record}  IN  @{records}
    log  Name: ${record['Name']} Id: ${record['Id']}
END

Or with a WHERE-clause, we can look for the last contact where the first name is NOT Eleanor.

@{records}=  Salesforce Query  Contact  select=Id,Name
...          where=FirstName!='Eleanor'
...              order_by=LastName desc
...              limit=1
Salesforce Update obj_name, obj_id, **kwargs

Updates a Salesforce object by Id.

The keyword returns the result from the underlying simple_salesforce insert method, which is an HTTP status code. As with `Salesforce Insert`, field values are specified as keyword arguments.

The following example assumes that ${contact id} has been previously set, and adds a Description to the given contact.

&{contact}=  Salesforce Update  Contact  ${contact id}
...  Description=This Contact created during a test
Should be equal as numbers ${result}  204
Soql Query query, *args

Runs a SOQL query and returns the result as a dictionary.

The query parameter must be a properly quoted SOQL query statement or statement fragment. Additional arguments will be joined to the query with spaces, allowing for a query to span multiple lines.

This keyword will return a dictionary. The dictionary contains the keys as documented for the raw API call. The most useful keys are records and totalSize, which contains a list of records that were matched by the query and the number of records that were returned.

Example:

The following example searches for all Contacts with a first name of "Eleanor" and a last name of "Rigby", and then logs the Id of the first record found.

${result}=  SOQL Query
...  SELECT Name, Id
...  FROM   Contact
...  WHERE  FirstName='Eleanor' AND LastName='Rigby'

${contact}=  Get from list  ${result['records']}  0
log  Contact Id: ${contact['Id']}
Store Session Record obj_type, obj_id

Stores a Salesforce record's Id for use in the Delete Session Records keyword.

This keyword is automatically called by Salesforce Insert.

SalesforcePlaywright.robot

cumulusci/robotframework/SalesforcePlaywright.robot

This resource file contains no keywords, but can be used to import the most common libraries used for writing browser tests that use the robotframework Browser library, based upon Playwright.

Note: when using this library, you cannot also use Salesforce.robot or Salesforce.py since those are based on Selenium rather than Playwright.

Libraries imported by this resource file:

  • Browser
  • Collections
  • OperatingSystem
  • String
  • cumulusci.robotframework.CumulusCI
  • cumulusci.robotframework.SalesforcePlaywright
  • cumulusci.robotframework.SalesforceAPI
  • cumulusci.robotframework.Performance

This resource file also defines the following variables, which can all be overridden on the command line with the --vars option

Variable Name Default Value
${DEFAULT BROWSER SIZE} 1280x1024
${BROWSER} chrome
Keyword Arguments Documentation

SalesforcePlaywright

cumulusci.robotframework.SalesforcePlaywright

Documentation for library cumulusci.robotframework.SalesforcePlaywright.

Keyword Arguments Documentation
Delete Records And Close Browser

This will close all open browser windows and then delete all records that were created with the Salesforce API during this testing session.

Get Current Record Id

Parses the current url to get the object id of the current record. This expects the url to contain an id that matches [a-zA-Z0-9]{15,18}

Get Fake Data fake, *args, **kwargs

Return fake data

This uses the Faker library to provide fake data in a variety of formats (names, addresses, credit card numbers, dates, phone numbers, etc) and locales (en_US, fr_FR, etc).

The fake argument is the name of a faker property such as first_name, address, lorem, etc. Additional arguments depend on type of data requested. For a comprehensive list of the types of fake data that can be generated see Faker providers in the Faker documentation.

The return value is typically a string, though in some cases some other type of object will be returned. For example, the date_between fake returns a datetime.date object. Each time a piece of fake data is requested it will be regenerated, so that multiple calls will usually return different data.

This keyword can also be called using robot's extended variable syntax using the variable ${faker}. In such a case, the data being asked for is a method call and arguments must be enclosed in parentheses and be quoted. Arguments should not be quoted when using the keyword.

To generate fake data for a locale other than en_US, use the keyword Set Faker Locale prior to calling this keyword.

Examples

# Generate a fake first name
${first_name}=  Get fake data  first_name
# Generate a fake date in the default format
${date}=  Get fake data  date
# Generate a fake date with an explicit format
${date}=  Get fake data  date  pattern=%Y-%m-%d
# Generate a fake date using extended variable syntax
Input text  //input  ${faker.date(pattern='%Y-%m-%d')}
Go To Record Home obj_id

Navigates to the Home view of a Salesforce Object

After navigating, this will wait until the slds-page-header_record-home div can be found on the page.

Open Test Browser size=None, useralias=None, wait=True, record_video=None

Open a new Playwright browser, context, and page to the default org.

The return value is a tuple of the browser id, context id, and page details returned by the Playwright keywords New Browser, New Context, and New Page.

This provides the most common environment for testing. For more control, you can create your own browser environment with the Browser library keywords `Create Browser`, `Create Context`, and `Create Page`.

To record a video of the session, set `record_video` to True. The video (*.webm) will be viewable in the log.html file at the point where this keyword is logged.

This keyword automatically calls the browser keyword `Wait until network is idle`.

Set Faker Locale locale

Set the locale for fake data

This sets the locale for all calls to the Faker keyword and ${faker} variable. The default is en_US

For a list of supported locales see Localized Providers in the Faker documentation.

Example

Set Faker Locale    fr_FR
${french_address}=  Faker  address
Wait Until Loading Is Complete locator=None, timeout=15 seconds

Wait for a lightning page to load.

By default this keyword will wait for any element with the class 'slds-template__container', but a different locator can be provided.

In addition to waiting for the element, it will also wait for any pending aura events, and it also calls the Browser keyword `Wait until network is idle`.

Wait Until Salesforce Is Ready login_url, locator=None, timeout=30 seconds

Attempt to wait until we land on a lightning page

In addition to waiting for a lightning page, this keyword will also attempt to wait until there are no more pending ajax requests.

The timeout parameter is taken as a rough guideline. This keyword will actually wait for half of the timeout before starting checks for edge cases.

Base Page Objects

cumulusci/robotframework/pageobjects/BasePageObjects.py

The following page objects are automatically included when importing the PageObject library. You should not directly import this file.

Detail
Page Type

A page object representing the standard Detail page.

When going to this page via the standard `Go to page` keyword, you can specify either an object id, or a set of keyword arguments which will be used to look up the object id. When using keyword arguments, they need to represent a unique user.

Example

${contact_id} =       Salesforce Insert  Contact
...                   FirstName=${first_name}
...                   LastName=${last_name}

# Using the id:
Go to page  Detail  Contact  ${contact_id}

# Using lookup parameters
Go to page  Detail  Contact  FirstName=${first_name}  LastName=${last_name}
Keyword Arguments Documentation
Log Current Page Object

Logs the name of the current page object

The current page object is also returned as an object

Edit
Page Type

A page object representing the Edit Object modal

Note: You should not use this page object with 'Go to page'. Instead, you can use 'Wait for modal to appear' after performing an action that causes the new object modal to appear (eg: clicking the "Edit" button). Once the modal appears, the keywords for that modal will be available for use in the test.

Example:

Click object button        Edit
Wait for modal to appear   Edit  Contact
Keyword Arguments Documentation
Click Modal Button button_label

Click the named modal button (Save, Save & New, Cancel, etc)

Close The Modal

Closes the open modal

Log Current Page Object

Logs the name of the current page object

The current page object is also returned as an object

Modal Should Contain Errors *messages

Verify that the modal contains the following errors

This will look for the given message in the standard SLDS component (<ul class='errorsList'>)

Modal Should Show Edit Error For Fields *field_names

Verify that a dialog is showing requiring a review of the given fields

This works by looking for a the "we hit a snag" popup, and then looking for an anchor tag with the attribute force-recordediterror_recordediterror, along with the given text.

Populate Field name, value

Populate a field on the modal form

Name must the the label of a field as it appears on the modal form.

Example

Populate field  First Name  Connor
Populate field  Last Name   MacLeod
Populate Form *args, **kwargs

Populate the modal form

Arguments are of the form key=value, where 'key' represents a field name as it appears on the form (specifically, the text of a label with the class 'uiLabel').

Example:

Populate form
...  First Name=Connor
...  Last Name=MacLeod
Select Dropdown Value label, value

Sets the value of a dropdown form field from one of the values in the dropdown

label represents the label on the form field (eg: Lead Source)

If a modal is present, the modal will be searched for the dropdown. Otherwise the first matching dropdown on the entire web page will be used.

Wait Until Modal Is Closed timeout=None

Waits until the modal is no longer visible

If the modal isn't open, this will not throw an error.

Home
Page Type

A page object representing the home page of an object.

When going to the Home page, you need to specify the object name.

Note: The home page of an object may automatically redirect you to some other page, such as a Listing page. If you are working with such a page, you might need to use `page should be` to load the keywords for the page you expect to be redirected to.

Example

Go to page  Home  Contact
Keyword Arguments Documentation
Log Current Page Object

Logs the name of the current page object

The current page object is also returned as an object

Listing
Page Type

Page object representing a Listing page

When going to the Listing page, you need to specify the object name. You may also specify the name of a filter.

Example

Go to page  Listing  Contact  filterName=Recent
Keyword Arguments Documentation
Deselect Rows *items

Uncheck the checkbutton for one or more rows

Arguments are one or more strings. Each row that contains one of the strings in any column will be delselected. Rows that are unchecked will remain unchecked.

If no elements are found to match, this keyword will raise an error.

Example

The following example deselects all rows that contain either John Doe or Jane Doe in any column.

Select Rows   John Doe  Jane Doe
Log Current Page Object

Logs the name of the current page object

The current page object is also returned as an object

Select Rows *items

Check the checkbutton for one or more rows

Arguments are one or more strings. Each row that contains one of the strings in any column will be clicked. Rows that have already been checked will remain checked.

If no elements are found to match, this keyword will raise an error.

Example

The following example selects all rows that contain either John Doe or Jane Doe in any column.

Select Rows   John Doe  Jane Doe
New
Page Type

A page object representing the New Object modal

Note: You should not use this page object with 'Go to page'. Instead, you can use 'Wait for modal to appear' after performing an action that causes the new object modal to appear (eg: clicking the "New" button). Once the modal appears, the keywords for that modal will be available for use in the test.

Example:

Go to page                 Home  Contact
Click object button        New
Wait for modal to appear   New  Contact
Keyword Arguments Documentation
Click Modal Button button_label

Click the named modal button (Save, Save & New, Cancel, etc)

Close The Modal

Closes the open modal

Log Current Page Object

Logs the name of the current page object

The current page object is also returned as an object

Modal Should Contain Errors *messages

Verify that the modal contains the following errors

This will look for the given message in the standard SLDS component (<ul class='errorsList'>)

Modal Should Show Edit Error For Fields *field_names

Verify that a dialog is showing requiring a review of the given fields

This works by looking for a the "we hit a snag" popup, and then looking for an anchor tag with the attribute force-recordediterror_recordediterror, along with the given text.

Populate Field name, value

Populate a field on the modal form

Name must the the label of a field as it appears on the modal form.

Example

Populate field  First Name  Connor
Populate field  Last Name   MacLeod
Populate Form *args, **kwargs

Populate the modal form

Arguments are of the form key=value, where 'key' represents a field name as it appears on the form (specifically, the text of a label with the class 'uiLabel').

Example:

Populate form
...  First Name=Connor
...  Last Name=MacLeod
Select Dropdown Value label, value

Sets the value of a dropdown form field from one of the values in the dropdown

label represents the label on the form field (eg: Lead Source)

If a modal is present, the modal will be searched for the dropdown. Otherwise the first matching dropdown on the entire web page will be used.

Wait Until Modal Is Closed timeout=None

Waits until the modal is no longer visible

If the modal isn't open, this will not throw an error.