Cross-Browser Scripting (CBS)

by onezero
3 months ago
278 Views

Table of Contents


Voodoo RPA Cross-Browser Scripting (CBS)

What is CBS?

CBS or CBS Object is a communication model between Voodoo RPA and your web browsers installed on your OS. CBS is an abbreviation for “Cross-Browser Scripting”. When RPA Developers design a scenario using Voodoo Studio, they may want to directly send the script to the browser. This script can be any standard that the browser knows i.e. pure Javascript or jQuery. By the way, Voodoo Browser Extensions (Chrome or Firefox) automatically inject jQuery API to your target web application. So, whether your site using jQuery or not, RPA developers directly write jQuery in creating the CBS Object using CBS Object Creator on Voodoo Studio.

That technology is the Voodoo EDE Library. By default, it comes with Voodoo RPA 2.0 or higher versions. You can manually download this library from here and add it to your EDE file references.

Methods

Property Description
int send(string pureBrowserScript) Send the pure script to Browser. This method return processID.
Note: Voodoo Browser Extensions inject the last jQuery API into a web page. So you can directly write Jquery + Pure Javascript code together
int sendObj(string nameOfCBSObject, Dictionary < string, string > keyValues = null) Send CBS OBject to Browser. You can send a second parameter as a dictionary to replace dynamic Keys ({:mykey}) in your CBS Object. This method return processID.
Note: To create CBS Object, you can use the CBS Object Creator tool on Voodoo Studio
Dictionary < int, string > check (int processID, int ms = 10000) Check the process result and get a response from the browser if that is intended.
Note: This method return dictionary. First Key is the result code and the First Value is the response if that you designed in your script by using the “var response” key. Result Codes (First Key): [-1: task not found | 0: task waiting for | 1: task work in progress or script error occurred so the process gets stuck in at this state | 2: task completed]

Example #1 (Pure Script)

namespace VoodooImplementation {
    using System;  
    using VooDooCommonData.CommonInterface;
    using VooDooCommonData.InstanceData;
    
    using System.Collections.Generic;
    using System.Linq;
    using CBSLoader;
    
    public class ComputationEvaluator : System.MarshalByRefObject, IPlugInComputation {
        
        private bool result_;
        
        private VooDooCommonData.InstanceData.PlanDataInstanceManager planDataInstanceManager_;
        
        /// Default Constructor for class
        public ComputationEvaluator() {
        }
        
        public bool result {
            get {
                return result_;
            }
        }
        
        public virtual VooDooCommonData.InstanceData.PlanDataInstanceManager planDataInstanceManager {
            get {
                return planDataInstanceManager_;
            }
            set {
                planDataInstanceManager_ = value;
            }
        }
        
        /// Calculate
        public virtual void ExecuteComputation() {
            
            CBS CBSObj = new CBS();
            int id = CBSObj.send("var name = $(\".izquierda:eq(0)\").text(); var age = $(\".izquierda:eq(2)\").text(); result = name + '|' + age;");
            Dictionary<int, string> result = CBSObj.check(id, 5000);

            if(result.First().Key == 2) {
                string[] resultA = result.First().Value.Split('|');
                planDataInstanceManager_.SetDataTableValueFromCurrentDataRowIndex(5, "name", resultA[0]);
                planDataInstanceManager_.SetDataTableValueFromCurrentDataRowIndex(5, "age", resultA[1]);
                result_ = true;
            } else {
                result_ = false;
            }
            
        }
    }
}

Example #2 (CBS Object)

In this example that is assumed: You create CBS Object name “myCBSObject” and below is code in this object.

var name = $(".izquierda:eq({:nameIndex})").text(); 
var age = $(".izquierda:eq({:ageIndex})").text(); 
result = JSON.stringify([name, age]);
namespace VoodooImplementation {
    using System;  
    using VooDooCommonData.CommonInterface;
    using VooDooCommonData.InstanceData;
    
    using Newtonsoft.Json;
    using System.Collections.Generic;
    using System.Linq;
    using CBSLoader;
    
    public class ComputationEvaluator : System.MarshalByRefObject, IPlugInComputation {
        
        private bool result_;
        
        private VooDooCommonData.InstanceData.PlanDataInstanceManager planDataInstanceManager_;
        
        /// Default Constructor for class
        public ComputationEvaluator() {
        }
        
        public bool result {
            get {
                return result_;
            }
        }
        
        public virtual VooDooCommonData.InstanceData.PlanDataInstanceManager planDataInstanceManager {
            get {
                return planDataInstanceManager_;
            }
            set {
                planDataInstanceManager_ = value;
            }
        }
        
        /// Calculate
        public virtual void ExecuteComputation() {
            
            CBS CBSObj = new CBS();
            int id = CBSObj.sendObj("myCBSObject", new Dictionary<string, string> {{"nameIndex", "0"}, {"ageIndex", "2"}});
            Dictionary<int, string> result = CBSObj.check(id, 5000);
            
            if(result.First().Key == 2) {
                List<string> person = JsonConvert.DeserializeObject<List<string>>(result.First().Value);
                planDataInstanceManager_.SetDataTableValueFromCurrentDataRowIndex(5, "name", person[0]);
                planDataInstanceManager_.SetDataTableValueFromCurrentDataRowIndex(5, "age", person[1]);
                result_ = true;
            } else {
                result_ = false;
            }
            
        }
    }
}