I. Introduction and Purpose
II. Create Test Project Folder
III. Install Mocha or Jasmine
The instructions to install Mocha can be found at https://mochajs.org/. If you choose to use Jasmine, you can find instructions for it here https://www.npmjs.com/package/jasmine. You do not need to follow the instructions on these sites, as I have included required steps below.
Now, to make things even more confusing, both the Mocha and Jasmine instructions are written with Linux file systems in mind. You can finish the procedure using MS DOS commands, but if you want to, you can install Cygwin.
A. Try Using Cygwin
Cygwin, in a nutshell, enables you to run commands as if on a Linux system. You can download and install it from here: http://cygwin.com/install.html. Detailed setup instructions can be found here (https://cygwin.com/cygwin-ug-net/setup-net.html).
I recommend the following steps:
- Choose Install from Internet
- Choose c:\cygwin for the Root Directory
- Choose whatever you want for the Local Package Directory. I used c:\cygwin as well.
- When choosing a download site, any will do. Choose one close to you for best speeds.
- Be sure expand the ‘Devel’ category and enter ‘make’ in the Search field. Choose to install ‘make’ at a minimum. You can leave everything else as default.
- Allow it to install any dependencies.
- After install is complete, launch Cygwin so it will create the user folder.
In Cygwin, you need to alias the make command to Cygwin’s make.exe file. To do this, open a Windows File Explorer and navigate to the location you installed Cygwin (I put mine in c:\cygwin, and for simplicity’s sake I suggest you do as well) and drill down to the user’s home folder. Mine is C:\cygwin\home\Administrator. In this folder you will find a .bashrc file. Open this file in your favorite text editor and scroll all the way to the bottom. Add the following code:
Note that if you installed Cygwin in a different location than c:\cygwin, you will have to adjust the path to point to the correct location. Shut down and restart Cygwin to put this change into effect.
C. Installing Mocha
For the purpose of this example I will give you step by step instructions for the MINIMUM steps needed to install Mocha. For detailed instructions regarding installing and using Mocha, please see https://mochajs.org/#installation. There you will find links to additional information and help for Mocha.
To install Mocha, launch a Windows, Cygwin or Node.js command window (I recommend Cygwin), navigate to the folder you created earlier (c:\LeanFT_JS_SDK) and run the command:
Next, create a test directory:
Back in Cygwin, in your c:\LeanFT_JS_SDK directory, run the command:
The result should look like this:
Depending on what editor you use (I use Atom), you may encounter an error about “missing separators”. This is due to the text editor not formatting white space in a compatible way with the make file. To fix this you can use an editor like Atom that formats text for specific languages. Notepad ++ is also a good one, but you have to change some settings to get it to work correctly. You can see those instructions here (http://altamodatech.com/blogs/?p=452).
D. Installing Jasmine
As noted, you can use Mocha or Jasmine. If you choose Jasmine, for the purpose of this example I will give you step by step instructions for the MINIMUM steps needed to install Jasmine. For detailed instructions regarding installing and using Jasmine, please see https://www.npmjs.com/package/jasmine
In Cygwin, from the c:\LeanFT_JS_SDK directory, run the following code:
Open a Windows command window in the c:\LeanFT_JS_SDK folder and run the below command (including the quotes “, the space and the period . at the end):
Note that a LeanFT Standalone install location will be different from a UFT/LeanFT Install Location, so adjust as necessary. Also note that in the event you installed on a 32 bit machine, the path will begin C:\Program Files\ instead of C:\Program Files (x86)\. If you did not install in the default location, then edit for your custom location.
V. Running Tests
Manually launch LeanFT Runtime prior to running tests.
I’ve included a sample test below that you can copy and put in your test folder. Name it template.js.
Now, to run tests, simply ensure you are in your project folder (c:\LeanFT_JS_SDK) and enter the command
(You can use either Cygwin or Windows command window).
Using the below template test, the results will look like this:
B. Template test
Note that this test (from http://leanft-help.saas.hpe.com/en/14.00/HelpCenter/Content/HowTo/JS-Basic.htm) launches the Chrome browser. If you do not have Chrome, alter the line
accordingly. Also note that depending on if you are using mocha or jasmine, some of the lines need to be edited for that framework. See the comments in the code