Library scope: | GLOBAL |
---|
QForce is a Robot Framework testing library for Salesforce cloud.
This document contains all keywords that have been specifically added for Salesforce.
In addition the QForce library includes ALL keywords from our generic web testing library, QWeb
You DO NOT need to import QWeb separately.
QForce contains both Web/UI level keywords and REST API keywords. REST API keywords are listed under REST_API tag.
Adds products with ProductModels to a QuoteModel https://developer.salesforce.com/docs/atlas.en-us.cpq_dev_api.meta/cpq_dev_api/cpq_api_add_products.htm
NOTE: Authentication has to be done once before calling this keyword.
${cpq_quote_model}= Read CPQ Quote ${quote_id} ${cpq_product}= Read CPQ Product ${product_id}[records][0][Id] ${pricebook_id}[records][0][Id] USD ${quote_with_product}= Add CPQ Products ${cpq_quote_model} ${cpq_product}
Authenticates to Salesforce REST API and sets access token which will be used in all subsequent calls.
Note
Needs a consumer key and a consumer secret from OAuth Connected App.
Basic steps to enable REST API authentication:
Precondition(s): Make sure to enable "Allow OAuth Username-Password Flows" from Settings > Identity > OAuth and OpenID Connect Settings.
More information in Salesforce documentation: Defining Connected Apps
Authenticate ${client_id} ${client_secret} myusername@test.com ${password} # Authenticate to sandbox (can be accessed via https://test.salesforce.com) Authenticate ${client_id} ${client_secret} myusername@test.com ${password} sandbox=True # Authenticate with custom url Authenticate ${client_id} ${client_secret} jdoe@test.com ${password} custom_url=https://someurl.com # Authenticate and reuse access token in 3rd party library Import QForce Import RequestsLibrary # you can also get the token using GetAccessToken keyword ${token}= Authenticate ${client_id} ${client_secret} jdoe@test.com ${password} ${my_acc}= Create Record Account Name=My Account NumberOfEmployees=83 ${api_version_url}= Get API Version Url ${instance_url}= Get Instance Url # Call SF Rest API using RequestsLibrary keyword and token from QForce Authenticate &{headers}= Create Dictionary Authorization=Bearer ${token} ${resp}= GET url=${instance_url}${api_version_url}/sobjects/Account/${my_acc} ... headers=&{headers} timeout=10 Log ${resp.json()} console=true Should Be Equal ${resp.json()}[Name] My Account Should Be Equal ${resp.json()}[Id] ${my_acc}
Is the instance a sandbox instance? This flag will set login url accordingly, either login.salesforce.com or test.salesforce.com (sandbox). Default: False (-> login.salesforce.com)
You can find out if your environment is a sandbox by trying to login with your credentials through https://login.salesforce.com and https://test.salesforce.com. If you can login through https://login.salesforce.com then your environment is NOT a sandbox and if you can login through https://test.salesforce.com then your environment is a sandbox.
Calculates quote with the given QuoteModel and returns an updated QuoteModel https://developer.salesforce.com/docs/atlas.en-us.cpq_dev_api.meta/cpq_dev_api/cpq_quote_api_calculate_final.htm
NOTE: Authentication has to be done once before calling this keyword
${cpq_quote}= Read CPQ Quote a2w7Q000000LBGRQA4 ${calculated_quote}= Calculate CPQ Quote ${cpq_quote}
Check or uncheck a Salesforce checkbox.
ClickCheckbox I am not a robot on ClickCheckbox I am not a robot off
With table(Pick table with use table keyword first):
ClickCheckbox r1c1 on ClickCheckbox r-1c3 off #last row, third cell ClickCheckbox r?Robot/c-1 on #row that contains text Robot, last cell
With anchor
ClickCheckbox I am not a robot on anchor text ClickCheckbox r?Robot/c-1 on Test #row contains texts Robot and Test ClickCheckbox r?Robot/c-1 on 3 #third row which contains text Robot
Clicks a value from Aura/Lightning recordlayout field in Salesforce. Correct field is found using label.
ClickFieldValue Phone # clicks 12345
Clicks a cell in a sf_standard_table.
ClickTableCell Quantity 3 ClickTableCell List Unit Price 5 double=True # double clicks field
Click text on web page.
Keyword looks for an exact match and if not found uses xpath defined in Search Strategy. If the given text corresponds to multiple elements, it clicks the first element.
If you want to click other element than the first one found, you need to use anchor or index.
Keyword tries to click element until it succeeds or timeout has passed. If timeout is not specified, default timeout is used. DefaultTimeout can be adjusted with SetConfig DefaultTimeout keyword.".
You can also use computer vision engine to find texts from UI. This is useful for example in situations where text element is under shadow DOM.
ClickText Canis
In the above example the ClickText keyword will click the word Canis. If there are multiple instances of the word Canis on the page, first one will be clicked unless 'anchor' is given. You can specific which one should be clicked by either:
For example
ClickText Canis 3 # clicks the third "Canis" on the page ClickText Canis Dog # clicks the "Canis" near to the word "Dog" # handling numeric anchors as text, not index ClickText Canis 3 anchor_type=text # clicks the "Canis" next text "3"
If text can't be found with normal means, you can use computer vision engine instead:
# clicks the text "Canis" using computer vision engine ClickText Canis recognition_mode=vision
If you want to specify how long ClickText tries, you need to add both anchor and timeout.
ClickText Canis 1 20s # Tries to click the first "Canis" for 20s
If clickable element is child or parent of locator element use child/parent attribute + elements tagname to pick right element
ClickText Canis parent=span # Clicks Canis element's first parent with span -tag ClickText Canis child=a # First childnode with a -tag
ClickText Canis js=true #Use Javascript click instead of Selenium
To double-click text, use argument doubleclick=True
ClickText Canis doubleclick=True
Or use SetConfig
SetConfig DoubleClick On ClickText Canis
To extend normal text search to shadow DOM, use SetConfig ShadowDOM. Note that certain arguments like partial_match are ignored when searching from shadow DOM.
SetConfig ShadowDOM True ClickText Canis
Expands or closes parent element in Lightning Tree
ClickTree Western Sales Director # expands node, does nothing if already expanded ClickText CA Sales Rep # clicks subtree node ClickTree Western Sales Director False # collapses parent Tree node "User"
Searches and selects a value from a Salesforce combobox.
NOTE: only full matches are allowed for the item/value that will be selected.
NOTE: only works for comboboxes which do have the input field available. In some cases combobox is prefilled with values and there is no input. In these cases, please remove existing values first or make the input visible by clicking one of the selected values.
Combobox Search Accounts... Test Account # using label and selecting 3rd duplicated instance Combobox *Account Name Test Account index=3
Creates a new record to Salesforce instance.
NOTE: Authentication has to be done once before calling this keyword
${contact}= Create Record Contact FirstName=Jane LastName=Doe ${account}= Create Record Account Name=KindCorp BillingPostalCode=12345 # if duplicate check rule is on, you can give additional headers: # works with string header ${account2}= Create Record Account Name=KindCorp BillingPostalCode=12345 additional_headers={"Sforce-Duplicate-Rule-Header": "allowSave=true"} # works with dict header &{headers_dict} = Create Dictionary Sforce-Duplicate-Rule-Header=allowSave=true ${account3}= Create Record Account Name=KindCorp BillingPostalCode=12345 additional_headers=${headers_dict}
Deletes a record from Salesforce instance.
NOTE: Authentication has to be done once before calling this keyword
${contact}= Create Record Contact FirstName=Jane LastName=Doe ${account}= Create Record Account Name=KindCorp Delete Record Contact ${contact} Delete Record Account ${account} Delete Record Account 0015E000024YyV0QAK
Executes an anonymous Apex script. Script can be given as a file or as string. The action done by Apex script needs to be verified with other keywords. This keyword verifies that the API call is successful, Apex script is successfully compiled and run.
Returns the return value from API call in json format.
NOTE: Authentication has to be done once before calling this keyword
${results}= Execute Apex Account newAccount = new Account();\nnewAccount.Name = String.valueOf(Date.today());\ninsert newAccount; ${results}= Execute Apex my_script.apex is_file=True
Executes a SOQL Query and saves returned records as .json file. Returns the path of a saved file.
NOTE: Authentication has to be done once before calling this keyword
${results}= Export Records SELECT id,name from Contact ${OUTPUTDIR}/contacts.json
Gets the Access Token. This is useful when combining QForce API keywords with 3rd party library.
NOTE: Authentication has to be done once before calling this keyword
${token}= Get Access Token
Gets the API version used in instance. This is useful when combining QForce API keywords with 3rd party library.
NOTE: Authentication has to be done once before calling this keyword
${api_version_url}= Get API Version URL
Gets a value from Aura/Lightning recordlayout field in Salesforce. Correct field is found using label. By default text under lightning-formatted-/span tag is returned. Some salesforce texts are under non-formatted <a> tag and with these you need to use tag argument
${value}= GetFieldValue Phone # returns 12345 ${value}= GetFieldValue Notes # returns text from Notes field # returns non-formated text from a tag ${value}= GetFieldValue Quote Number tag=a
"Gets the instance url after authentication. This same url should be used in all subsequent API calls. This is useful when combining QForce API keywords with 3rd party library.
NOTE: Authentication has to be done once before calling this keyword
${instance_url}= Get Instance URL
Generates one-time password as an authentication app on your mobile would. See MFA Setup
${mfa_code}= GetOTP my_user@testsf.com ${MY_SECRET} TypeText Code ${mfa_code}
1.Enable OTP authentication app in your SF user settings:
2. Get the security code. You can hover on top of the QR code or right-click and open the image in another tab (code will be in url):
3. FInalize the setup with you mobile authentication app and provide first code from the app.
4. Provide the security token in variable ${secret}. This should be given as encrypted variable in Copado Robotic Testing.
Returns all or selected options available in picklist. Supports both Lightning and Aura pick lists.
${options}= GetPicklist Salutation # Returns ['--None--', 'Mr.', 'Ms.', 'Mrs.', 'Dr.', 'Prof.'] ${selected}= GetPicklist Salutation selected=True # Returns 'Mr.' if that one was selected.
Returns the count of options in a picklist identified by label. Supports both Lightning and Aura pick lists.
${count}= GetPickListCount Salutation # returns 5
Authenticates to Salesforce REST API and sets access token which will be used in all subsequent calls
NOTE: Authentication has to be done once before calling this keyword
Authenticate ${client_id} ${client_secret} myusername@test.com ${password} ${account}= Get Record Account 0015E00001TyR6mQAF Should Be Equal As Strings ${account}[Name] Corporation
Gets the Lightning record id from URL.
NOTE: You need to be in the record view in order to get the id. NOTE2: This keyword does not wait, so make sure the record view is loaded.
${id}= Get Record ID From Url # returns 5005E00000BMpypQAD or similar
None
Gets a value from a sf_standard_table using row and column. Works with sf_standard_table elements, for example Quotes/Edit Lines:
${value}= GetTableCell Quantity 3 ${value}= GetTableCell List Unit Price 5
Performs Salesforce Lightning "global search" operation for given seach term and record type and immediately opens search results page.
NOTE: Lightning only.
GlobalSearch ${login_url} John Doe # returns top results for "John Doe" GlobalSearch ${login_url} John Doe Contact # returns results for a Contact named "John Doe"
Navigates to given Lightning record id.
# Navigates to given Lightning record id Go To Record 001UD000002XlBuYAK
Creates multiple records defined in .json file.
Returns a json format response including id's of created objects.
NOTE: Authentication has to be done once before calling this keyword
{ "records" :[{ "attributes" : {"type" : "Account", "referenceId" : "ref1"}, "name" : "SampleAccount1", "phone" : "1111111111", "website" : "www.salesforce.com", "numberOfEmployees" : "100", "industry" : "Banking" },{ "attributes" : {"type" : "Account", "referenceId" : "ref2"}, "name" : "SampleAccount2", "phone" : "2222222222", "website" : "www.salesforce2.com", "numberOfEmployees" : "250", "industry" : "Banking" },{ "attributes" : {"type" : "Account", "referenceId" : "ref3"}, "name" : "SampleAccount3", "phone" : "3333333333", "website" : "www.salesforce3.com", "numberOfEmployees" : "52000", "industry" : "Banking" },{ "attributes" : {"type" : "Account", "referenceId" : "ref4"}, "name" : "SampleAccount4", "phone" : "4444444444", "website" : "www.salesforce4.com", "numberOfEmployees" : "2500", "industry" : "Banking" }] }
# using .json in test script ${json}= Import Records Account ${CURDIR}/resources/new_records.json # Get id's from response ${id1}= Set Variable ${json}[results][0][id] ${id2}= Set Variable ${json}[results][1][id] ${id3}= Set Variable ${json}[results][2][id] ${id4}= Set Variable ${json}[results][3][id] # can also get all id's to list at once like this @{created_ids}= Evaluate [x['id'] for x in $json['results']]
Authenticates to Salesforce using JWT Bearer Token flow and sets the access token, which can be used for API calls and to bootstrap UI sessions via frontdoor.jsp.
Note
Requires a consumer key from an OAuth Connected App and a generated RSA key pair. The private key is used to sign JWT tokens for authentication.
Basic steps to enable JWT Bearer Token authentication:
# Generate private key openssl genrsa -out server.key 2048 # Generate public certificate (valid for 10 years, adjust as needed) openssl req -new -x509 -key server.key -out server.crt -days 3650 -subj "/CN=SalesforceAutomation"
8. After creating the Connected App, go to Manage Consumer Details and copy the Consumer Key. This will be used as the client_id argument in the JWT Authenticate keyword.
More information in Salesforce documentation: Salesforce JWT Bearer Token Flow
JWTAuthenticate ${client_id} ${private_key} myusername@test.com
Is the instance a sandbox instance? This flag will set login url accordingly, either login.salesforce.com or test.salesforce.com (sandbox). Default: False (-> login.salesforce.com)
You can find out if your environment is a sandbox by trying to login with your credentials through https://login.salesforce.com and https://test.salesforce.com.
If you can login through https://login.salesforce.com then your environment is NOT a sandbox and if you can login through https://test.salesforce.com then your environment is a sandbox.
Login to Salesforce UI with JWT token, bypassing the login screen. This is useful when you want to use the same JWT token for both API calls and UI interactions. The token is set to the browser session and the user is redirected to the given ret_url, for example: /lightning/setup/SetupOneHome/home.
NOTE: Browser must be open and JWT Authentication has to be done once before calling this keyword!
OpenBrowser about:blank chrome JWTAuthenticate ${client_id} ${private_key} myusername@test.com JWTLogin /lightning/setup/SetupOneHome/home
Launches an app using Salesforce app menu / app launcher.
NOTE: If the requested app is already open, it will NOT be re-launched and a message explaining this will be logged.
LaunchApp Sales # Launch normal app LaunchApp Sales Opportunities # Launch app + check text after launch LaunchAPp Gmail connected_app=True # Launch connected app, skips checks LaunchApp E-Bikes index=2 # Launch second instance if there are duplicates
Lists all available sObjects.
ListObjects
Selects/unselects a value from a Salesforce Lightning multiselection pick list.
MultiPicklist Hide Tabs Auto Resolved Conflicts # Move from "selected" back to "available" MultiPicklist Hide Tabs Auto Resolved Conflicts action=Move to Available
Selects a value from a Salesforce pick list. Supports both Lightning and Aura pick lists. Pick list is found based on it's label. Both exact match and partial match are supported.
NOTE: Special characters need to be escaped with "\" in case included in search text. This is especially the case on mandatory pick lists, which do contain "*" in the label text and you search with exact match.
PickList Salutation Mr. # Finding with exact label when label includes special characters # ("*" needs to be escaped with "\") PickList \*Status Open partial_match=False
Executes a SOQL Query. See: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_query.htm
NOTE: Authentication has to be done once before calling this keyword
NOTE: If your query has special characters like "=", they need to be escaped with a backslash, i.e. "\="
${results}= QueryRecords SELECT id,name from Contact WHERE name LIKE 'John%' # add id from first result object to a variable ${ID}= Set Variable ${results}[records][0][Id]
Retrieves a ProductModel from Salesforce with product id and pricebook id https://developer.salesforce.com/docs/atlas.en-us.cpq_dev_api.meta/cpq_dev_api/cpq_api_read_product.htm
NOTE: Authentication has to be done once before calling this keyword.
${product_id}= Query Records query=Select Id FROM Product2 WHERE Name='SLA: Gold' ${pricebook_id}= Query Records query=Select Id FROM Pricebook2 WHERE IsStandard=True ${cpq_product}= Read CPQ Product ${product_id}[records][0][Id] ${pricebook_id}[records][0][Id] USD
Retrieves a QuoteModel from Salesforce with a quote id https://developer.salesforce.com/docs/atlas.en-us.cpq_dev_api.meta/cpq_dev_api/cpq_api_read_quote.htm
NOTE: Authentication has to be done once before calling this keyword
${cpq_quote}= Read CPQ Quote a2w7Q000000LBGRQA4
Revokes authentication token. You need to call Authenticate again to continue using the Salesforce REST API keywrods
More information in Salesforce documentation: Defining Connected Apps
Authenticate ${client_id} ${client_secret} myusername@test.com ${password} # do actions with API Revoke
Saves QuoteModel to Salesforce https://developer.salesforce.com/docs/atlas.en-us.cpq_dev_api.meta/cpq_dev_api/cpq_quote_api_save_final.htm
NOTE: Authentication has to be done once before calling this keyword.
NOTE: Save must be done before any changed are applied to CPQ quote.
${cpq_quote}= Read CPQ Quote a2w7Q000000LBGRQA4 ${calculated_quote}= Calculate CPQ Quote ${cpq_quote} ${saved_quote}= Save CPQ Quote ${calculated_quote}
Scrolls using keys in Salesforce's list views.
# Default action, page down in a list ScrollList # Scrolls list up by one page ScrollList direction=page_up # Scroll list right ScrollList uiScroller right # Scroll to the bottom of a list using different locator and tag ScrollList scrollable2 bottom tag=custom_tag # Scroll to the top of a list ScrollList direction=top # Scroll (page) down 3 times in a list Repeat Keyword 3 times ScrollList direction=down
Default value: page_down
Parses time strings like '1h 10s', '01:00:10' and '42' and returns seconds.
Time can also be given as an integer or float or, starting from RF 6.0.1, as a timedelta instance.
The result is rounded according to the round_to argument. Use round_to=None to disable rounding altogether.
Type a value to a field in a sf_standard_table at specific column/row.
TypeTable Quantity 3 2.00 TypeTable List Unit Price 5 9322
Updates a record in Salesforce instance.
NOTE: Authentication has to be done once before calling this keyword
${contact}= Create Record Contact FirstName=Jane LastName=Doe ${account}= Create Record Account Name=KindCorp Update Record Contact ${contact} FirstName=Jamie Email=jamie.doe@fake.com
Turns limiting text search to on/off. Note that once turned on all text searches are limited to modal dialog ONLY if it's open.
ClickText New UseModal On # limits all text based element searches to dialog, if open ... do something in modal dialog UseModal Off # Filter by non-default modal dialog UseModal On //div[@class='slds-modal__container']
Executes quotes validation rules for a QuoteModel https://developer.salesforce.com/docs/atlas.en-us.cpq_dev_api.meta/cpq_dev_api/cpq_api_validate_quote.htm
NOTE: Authentication has to be done once before calling this keyword
${cpq_quote}= Read CPQ Quote a2w7Q000000LBGRQA4 ${validation_errors}= Validate CPQ Quote ${cpq_quote}
Verifies a field value in Salesforce (Aura/Lightning) Record Layout. Correct field is found using label and value is compared to expected value given as argument. By default verifies all text under data-output-element-id="output-field" element. With clickable links (<a> tag) you can use tag argument.
VerifyField Phone 12345 VerifyField Phone 123 partial_match=True VerifyField Account Name Customer X VerifyField Notes This is the begi partial_match=True # verifies that field "Type" is empty VerifyField Type ${EMPTY} # Verifies only text under <a> tag VerifyField Lead Owner John Doe tag=a
Verifies the current page's header.
VerifyPageHeader Opportunities
Verifies that one or many option values exists in a specific picklist. Supports both Lightning and Aura pick lists.
# Verify specific option value exists VerifyPicklist Salutation Dr. # Verify multiple option values exist VerifyPicklist Salutation Mr. Ms. Dr. # Verify specific value exists and is selected VerifyPicklist Salutation Dr. selected=True
Verifies record's fields.
NOTE: Authentication has to be done once before calling this keyword
${contact}= Create Record Contact FirstName=Jane LastName=Doe Update Record Contact ${contact} FirstName=Jamie Email=jamie.doe@fake.com Verify Record Contact ${contact} FirstName=Jamie LastName=Doe Email=jamie.doe@fake.com
Verifies a value from a sf_standard_table at specific column/row.
VerifyTableCell Quantity 3 2.00 VerifyTableCell List Unit Price 5 7 632 partial_match=True
Verifies that a text appears on screen".
VerifyText Canis VerifyText Canis 20 # Waits max 20 seconds for text to appear VerifyText Canis recognition_mode=vision # Use Computer Vision engine
Conversion is done using Python's float built-in function.
Starting from RF 4.1, spaces and underscores can be used as visual separators for digit grouping purposes.
Examples: 3.14
, 2.9979e8
, 10 000.000 01
Conversion is done using Python's int built-in function. Floating point numbers are accepted only if they can be represented as integers exactly. For example, 1.0
is accepted and 1.1
is not.
Starting from RF 4.1, it is possible to use hexadecimal, octal and binary numbers by prefixing values with 0x
, 0o
and 0b
, respectively.
Starting from RF 4.1, spaces and underscores can be used as visual separators for digit grouping purposes.
Examples: 42
, -1
, 0b1010
, 10 000 000
, 0xBAD_C0FFEE
All arguments are converted to Unicode strings.