CRM Test is a Node.js test framework which calls Salesforce Rest API and create simple node.js scripts to perform different actions in salesforce. Currently CrmTest has a support of running in Amazon ec2 cloud. In this ReadMe the focus is to run CrmTest in Amazon EC2 instance having Ubuntu version.
CRM Test has driven from the idea of Testing as a Service. The intent is to support development of E2E scenarios using simple Node.Js scripts.
- Mac - OSX 10.11.1,
- Follow the instructions at http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html to launch an Amazon instance with Ubuntu OS flavor.
- Connect to the headless node.
- Download Java using OpenJDK http://openjdk.java.net/install/
- After installing Java verify the version of JDK (CrmTest has been built with Java version 1.8.0_73)
- Install java node module npm install java
- After going through the pre-requisites, install the CrmTest npm npm install crmtest
- Installation will download the crmtest package which can be found under node_modules -> crmtest.
How to execute the node.js module from on-prem
- Setup your own developer organization in Salesforce by following this guide https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/quickstart_dev_org.htm
- After Sign up and on successful login to the developer org, not the following. The org url will show you which instance it is using to create your org. For ex: to create a developer org for myself it took na30 instance (https://na30.salesforce.com/). Also this will be our login url which we have to mention during the invocation of crmtest node modules
- Click on Setup link in your developer org
- From the Quick Find/Search Menu search of 'Apps'(without single quotes)
- Under Build section link -> Create -> Click on Apps link
- Scroll down and focus on the new button under Connected Apps Section.
- On clicking the New button fill all the required details
- Please Note: Click the Enable Oauth settings under API section. This authentication mechanism will be use to connect from node modules.
- Enter any callback address. We are not going to use the callback address
- In the Selected OAuth Scopes select Full access
- For further details , please refer to the help link at https://help.salesforce.com/apex/HTViewHelpDoc?id=connected_app_create.htm
- Once the connected app is created click on it and take a note of consumer key and consumer secret
- Open a terminal
- Execute npm install crmtest
- This will download the crmtest package which we will test to invoke different node module calls.
- Browse to the node where you have downloaded the package
- Go to node_modules -> CrmTest
- Execute the script by invoking node crmtestclient.js
- Browse to lib folder and unjar all the jar files at some destination folder. If you refer to ###crmtest.js I had my lib extracted to taget/classes.
- java.classpath.push('./CrmTest/target/classes'); is the reference to the location.
- In addition to this, your classpath should also have the references of class files for all the other projects.
- Similar to the following:
Note: All the above reference is already mentioned in crmtest.js. If you are changing the project hierarchy this is something you need to consider.
- Create the crmtest object
- var crmtest = require('./crmtest.js');
- Some sample scripts are at CrmTest/TestScripts/ which can be refered
- Start Invoking supported crmtest methods. Currently crmtest support following features
Get OAuth access Token : In order to get oAuth access token we should invoke the getoauth methodvar response = crmtest;var accessToken = crmtest;
Here baseUrl is the instance url for ex: https://na30.salesforce.com/
UserName is the username used to login to the org
Password in order to login to the org
Consumer Secret and Consumer Key can be fetched from the connected app home page.
Once response is received one can parse the access token by invoking the parseresponse method and querying for access_token
- Create an account record
response = crmtest;var fileId = crmtest;
- To create an account one need to invoke createaccount method with the Account Name and accessToken received from the previous oAuth method.
- Upload a File in Chatter feed
response = crmtest;var fileId = crmtest;
- In order to upload a file in chatter insertchatterfeedwithfile method is invoked
- First parameter is the file location
- Second parameter will be the file name
- Third will be the file title
- Fourth will be the oauth accesstoken
- Once the response is recieved it can be parsed through and corresponding file id of the uploaded file can be retrieved.
- Get the status of File rendition
response = crmtest.fileavailability(fileId,"thumbnail", accessToken); var staus = crmtest.parseresponse(response, "status")
- Once file preview are generated, in order to get more analytics out of that send the fileId to the analyzeimage call with the Microsoft's cognitive api and accessToken
- Raw Image is read from the chatter api and passed to the Microsoft's cognitive api. Note: Microsoft is not going to store the images as per its documentation
Run crmtest in Amazon ec2
1 Follow the tutorial and set up an instance http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html 2 CrmTest has been verified on the Ubuntu version of Amazon ec2 3 Install the required Java binaries
**JDK**sudo apt-get install openjdk-8-jdk
**JRE**sudo apt-get install openjdk-8-jre
4 Already Node and npm will be installed in the instance, if not follow the steps at here
5 Once Node is installed execute the following
npm install javanpm install crmtest
6 That's it your amazon ec2 should be ready to run Salesforce e2e tests. --In the FAQ section some common issues and troubleshoot approaches have been mentioned--
I am getting invalid_grant when I am executing the oAuth method call, How to resolve it? A. The status invalid_grant depicts that the client machine from where you are trying to invoke the script is getting ip restricted by the org. To resolve this
- Go to your org.
- Click Setup
- Under Security Controls Click Network access
- Alternate approach is to search for Network access in Quick find box
- Add a range of ip address which will have your public ip address included
- Save it and try again.
Which user should I be in order to execute this node module A. Ideally you should be the system admin of the org.
I am getting an error NoClassDefFoundError: .... How to resolve it? A. Ideally all the jar files supported with this package should be in extracted state, but if it is not then you will get this error. To Troubleshoot this
- Go to ScriptTestFramework.APIStore -> target -> classes.
- Extract the corresponding jar --jar -xvf httpclient-4.5.2.jar--
- This will extract the content into org/ folder.
- Required packages are httpclient-4.5.2.jar, httpcore-4.4.4.jar, json-20160212.jar, commons-logging-1.2.jar, org.apache.httpcomponents.httpclient_4.4.1.jar
- There are some additional jars which are getting shipped for ongoing work support, and might not be needed.
This is an open source initiative supported by ISC license https://opensource.org/licenses/ISC