Cross-Browser Scripting (CBS)

by onezero
9 months ago
946 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;
            }
            
        }
    }
}

Example #3 (CBS Object For Non-Ascii Characters)

This example is about getting content that includes non-ascii characters from browser like Emojis.
In this example that is assumed: You create CBS Object name “myCBSObject” and below is code in this object.

var topic = $(".feed-shared-update-v2__description-wrapper div div span span span").eq(0).text();
var like = $("div.social-details-social-activity > ul > li.social-details-social-counts__reactions.social-details-social-counts__item > button > span").eq(1).text();
result = JSON.stringify([encodeURIComponent(topic),like]);
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> {});
            Dictionary<int, string> result = CBSObj.check(id, 5000);
            
            if(result.First().Key == 2) {
                List<string> post = JsonConvert.DeserializeObject<List<string>>(result.First().Value);
                planDataInstanceManager_.SetDataTableValueFromCurrentDataRowIndex(15, "topic", Uri.UnescapeDataString(post[0]));
                planDataInstanceManager_.SetDataTableValueFromCurrentDataRowIndex(15, "like", post[1]);
                result_ = true;
            } else {
                result_ = false;
            }
            
        }
    }
}

Example #4 (CBS Object For Non-Ascii Characters and Multidimensional Data Retrieve)

This example is about getting content that includes non-ascii characters like ‘Emojis’ and multidimensional data like ‘Table’.
In this example that is assumed: You create CBS Object name “getComments” and below is code in this object.

comments = [];
$("#tabPanelProComments ul").find('li').each(function(key){
	comment = [];
	var current = $(this);
	comment[0] = current.find('.ratingCont span').attr('class');
	comment[1] = encodeURIComponent(current.find('.commentTitle').text());
	comment[2] = encodeURIComponent(current.find('p').text());
	comments[key] = comment;
});

result = JSON.stringify(comments);

$('html, body').animate({scrollTop: $(".pagination").offset().top - 100}, 1000);
namespace VoodooImplementation {
    using System;
    using VooDooCommonData.CommonInterface;
    using VooDooCommonData.InstanceData;
    using System.IO;
    using System.Data;
    
    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("getComments", new Dictionary<string, string> {});
            Dictionary result = CBSObj.check(id, 5000);
            
            if(result.First().Key == 2) {
                List> comments = JsonConvert.DeserializeObject<List<List<string>>>(result.First().Value);

                foreach(var comment in comments) {
                    // Create Row Instance
                    DataRow dr = planDataInstanceManager_.GetNewRow(16);
                    dr[0] = comment[0];
                    dr[1] = Uri.UnescapeDataString(comment[1]);
                    dr[2] = Uri.UnescapeDataString(comment[2]);
                    dr[3] = "-";

                    planDataInstanceManager_.AddRowToDataTable(16, dr);
                }
                
                result_ = true;
            } else {
                result_ = false;
            }
        }
    }
}

Example #5 (If there is a point in the ID)

In this type of error, If there is a period in the id number, you will receive an error.

  • Example – 5
  • Subject Description
    Problem
    • If the element we reach with CBS is the ID number and there is a dot in it, it receives an error.

    Solution
    • Reached element”.”before” / / ” should be put.(eq //.)

    var fırsatNo = $("#gsft_main").contents().find("#sys_display\\.incident\\.u_opportunity").val(123);
    var fırsatKalem = $("#gsft_main").contents().find("#sys_display\\.incident\\.u_line_item").val(123);
    var calisma = $("#gsft_main").contents().find("#incident\\.u_htmlcomments").val(123);
    var kapanma = $("#gsft_main").contents().find('#incident\\.close_code').val("Converted to CR");
    
    result = JSON.stringify([fırsatNo, fırsatKalem, calisma, kapanma]);
    
    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> {});
                Dictionary<int, string> result = CBSObj.check(id, 5000);
                
               
                    result_ = true;
                } else {
                    result_ = false;
                }
                
            }
        }
    }