This is an old revision of the document!


Integration with External Tools

There are several ways to integrate TestOptimal with other systems and tools, allowing you to leverage your investment in the existing test automation tools. These interfaces are:


Cloud Services

You can run your testing on Selenium-based cloud service for cross browser testing and load testing with hundreds or even thousands of virtual users:

Please refer to their website for instruction on how to set up the connection to their service.


Azure DevOps

Add a step to Azure DevOps to run models remotely using REST APIs.


REST APIs

TestOptimal provides a suite of REST APIs to allow 3rd party tools and applications to communicate with TestOptimal server.

You can use these REST APIs as documented at http://localhost:8888/swagger to access start and stop model execution, access model artifacts/files as well as perform system functions remotely.

Organization of REST APIs

REST APIs are grouped and organized in these categories (to match Swagger-UI):

  • Dashboard - Dashboard data: KPI and model execution statistics
  • Demo - REST API used by demo models
  • File - access to model and system files
  • Graph - generate / download graphs for model executions: model graph, coverage graph, traversal graph and test case graph (MSC)
  • Model - access to model artifacts/files
  • Stats - model execution statistics
  • System - perform system functions

Security and Authorization

Most of the REST APIs are access controlled.

Basic Auth is used to authenticate users. It is highly recommended that you enable SSL if you access TestOptimal server from the internet to prevent your user id/password from being intercepted.

Swagger UI

Swagger UI is provided for your convenience. You can access Swagger UI with the following URL:

 http://localhost:8888/swagger
 

If you are prompted to Login screen, go ahead and login and re-launch the above URL in the same browser session again.


Integrate TestOptimal in your java project (Java /IDE Connector)

TestOptimal can be used in your testing project as a maven dependency.

 <dependency>
   <groupId>com.github.testoptimal</groupId>
   <artifactId>JavaConnector</artifactId>
   <version>1.0.4</version>
 </dependency>

You can build your model using POJO java classes and submit it to TestOptimal server to generate test cases from the model. The test cases are returned back to your java code for your further test case execution.

You can generate test cases for state model and data set (combinatorial testing).

See JavaConnector README for more details.


Integrate TestOptimal in your web project (javascript/node.js)

You may integrate your web project with TestOptimal using javascript library: TOServer.js.

For web/javascript, just add one of the following <script> to HEAD tag in your html page:

  <script src="http://[TestOptimal host:port]/agent/TOServer.js"></script>
  <script src="https://testoptimal.com/v6/agent/TOServer.js"></script>

For Node.js project, use following npm command to install TOServer.js package:

 npm install @testoptimal/mbt
 

Connecting to TestOptimal Server

 TOSvr = new TOServer("http://localhost:8888");
 TOSvr.setDebugCB((msg)=> console.logMsg ("DEBUG: " + msg), 2);
 TOSvr.login("myUsername", "myPwd")
    .then(() => {
              console.logMsg("connected to TestOptimal server");
          }, (err) => {
              console.logMsg(err);
              alert("Connection error");
    });

State Model Sample Scripts

Creating State Model
var model = new Model ("VendingMachine");
var Welcome = model.addStateInitial("Welcome");
var Q1 = model.addState("25 cents");
var Q2 = model.addState("50 cents");
var Q3 = model.addState("75 cents");
var Q4 = model.addState("100 cents");
var ThankYou = model.addStateFinal("ThankYou");

Welcome.addTrans("add_quarter", Q1).addTrans("cancel", ThankYou);
Q1.addTrans("add_quarter", Q2).addTrans("cancel", ThankYou);
Q2.addTrans("add_quarter", Q3).addTrans("cancel", ThankYou);
Q3.addTrans("add_quarter", Q4).addTrans("cancel", ThankYou);
Q4.addTrans("select_drink", ThankYou).addTrans("cancel", ThankYou);

// TOSvr is the connection object created in Making Connection section above.
TOSvr.uploadModel(model).then (function(){alert("model uploaded");})
Generating Test Cases
TOSvr.genPaths("VendingMachine", "Optimal", 1000).then(printPaths);
function printPaths (sum) {
   console.logMsg(sum);
}
Opening Graphs
// graph types: model, sequence, msc and coverage
// except model graph, all other graphs are available for model execution.
var url = TOSvr.getGraphURL("VendingMachine", "model");
console.logMsg("model graph: " + url);
window.open(url, "ModelGraph");
Online MBT
 var execReq = {
	modelName: "DEMO_RemoteAgent",
	statDesc: "description",
	options: { "autoClose": false }
};
var agentID = "DEMO";
TOSvr.execModel(execReq).then((data) => {
	console.logMsg(data);
	console.logMsg("Registering agent " + agentID);	
	TOSvr.regAgent(execReq.modelName, agentID).then(getNextCmd, errHandler);
});

function getNextCmd() {
   TOSvr.nextCmd(agentID, 2000).then(function(rmtCmd) {
	  if (rmtCmd && rmtCmd.cmd) {
		  var result = {
			result: "I don't know",
			reqTag: "DEMO", 
			assertID: "DEMO-" + rmtCmd.cmd
		 }
		 console.logMsg("received cmd: " + rmtCmd.cmd);
		 console.logMsg("sending result: " + result.result);
		 TOSvr.setResult (agentID, result).then (function(ret) {
			setTimeout(getNextCmd, 1000);
		  }, errHandler);
	  }
	  else modelExecDone();
   }, errHandler);
}

function modelExecDone() {
   console.logMsg("Model execution completed");
}function errHandler (err) {
   console.log("errored");
   console.logMsg(err);
   TOSvr.stopModelExec(execReq.modelName);
}
Retrieve Execution Results
 TOSvr.getSummary("DEMO_RemoteAgent").then(function(ret) {console.logMsg(ret);})

Combinatorial Model Sample Scripts

Create DataSet
  var ds = new DataSet("DemoDataSet");
  ds.addField ("F1", "text", ["aa","bbb"], "", false);
  ds.addField ("F2", "int", [1,2,3], "", false);
  TOSvr.uploadDataSet (ds).then(console.logMsg, console.logMsg);
Generate Test Cases
 TOSvr.genDataTable("DemoDataSet", "pairWise").then(console.logMsg, console.logMsg);

Demo Web Client

You may try out above sample scripts with the web client bundled in TestOptimal installation:

http://localhost:8888/DemoApp/Demo_MBT.html