Best JavaScript code snippet using apickli
test-xpath-evaluator.js
Source:test-xpath-evaluator.js
...12var rootNode = req.responseXML;13module( "xpath-evaluator" );14test( "XPath å¼ãè©ä¾¡ãã¦ææ¸é ã«å
¨ã¦ã®è©²å½ãã¼ããè¿ã", 9, function () {15 var nodes;16 nodes = core.evaluateXPath( rootNode, "/ddd", "all" );17 ok( Array.isArray( nodes ), "é
åãè¿ã" );18 ok( nodes.length === 1, "ã«ã¼ãè¦ç´ ãé¸æããå ´å㯠1 åã®é
åãè¿ã" );19 ok( nodes[0] === rootNode.documentElement, "è¿ã£ã¦ããè¦ç´ ãã«ã¼ãè¦ç´ ã§ãã" );20 nodes = core.evaluateXPath( rootNode, "/ddd" );21 ok( Array.isArray( nodes ),22 "第 3 å¼æ°ãæå®ããªãã£ãå ´åã all ãæå®ããå ´åã¨åæ§ã«é
åãè¿ã" );23 ok( nodes.length === 1, "ã«ã¼ãè¦ç´ ãé¸æããå ´å㯠1 åã®é
åãè¿ã" );24 ok( nodes[0] === rootNode.documentElement, "è¿ã£ã¦ããè¦ç´ ãã«ã¼ãè¦ç´ ã§ãã" );25 nodes = core.evaluateXPath( rootNode, "/ddd/eee/ccc", "all" );26 ok( nodes.length === 2, "該å½ãããã¼ããè¤æ°ååå¨ããå ´åã¯è¤æ°åè¿ã£ã¦ãã" );27 nodes = core.evaluateXPath( rootNode, "/ddd/none/ccc", "all" );28 ok( Array.isArray( nodes ),29 "該å½ãããã¼ããåå¨ããªãå ´åã¯ç©ºã®é
åãè¿ã (é
åã§ãããã¨ã確èª)" );30 ok( nodes.length === 0,31 "該å½ãããã¼ããåå¨ããªãå ´åã¯ç©ºã®é
åãè¿ã (空ã§ãããã¨ã®ç¢ºèª)" );32} );33test( "XPath å¼ãè©ä¾¡ãã¦ãã¼ããè¿ã", 4, function () {34 var node;35 node = core.evaluateXPath( rootNode, "/ddd/eee/ccc", "first" );36 ok( node.nodeType && node.nodeType === node.ELEMENT_NODE,37 "first æå®ãããã¨è¦ç´ ã表ã DOM ãªãã¸ã§ã¯ããè¿ã" );38 node = core.evaluateXPath( rootNode, "/abcde", "first" );39 ok( node === null,40 "first æå®ããã¦çµæã空㮠node-set ãªãã° null ãè¿ã" );41 node = core.evaluateXPath( rootNode, "/ddd/eee/ccc", "any" );42 ok( node.nodeType && node.nodeType === node.ELEMENT_NODE,43 "any æå®ãããã¨è¦ç´ ã表ã DOM ãªãã¸ã§ã¯ããè¿ã" );44 node = core.evaluateXPath( rootNode, "/abcde", "any" );45 ok( node === null,46 "any æå®ããã¦çµæã空㮠node-set ãªãã° null ãè¿ã" );47} );48test( "XPath å¼ãè©ä¾¡ãã¦æ°å¤åã§è¿ã", 2, function () {49 var num;50 num = core.evaluateXPath( rootNode, "/ddd/eee/ccc", "number" );51 equal( num, 801, "number åãæå®ããã¨æ°å¤ã«å¤æããã¦è¿ã£ã¦ãã" );52 num = core.evaluateXPath( rootNode, "(/ddd/eee/ccc)[2]", "number" );53 ok( isNaN(num), "æ°å¤ã«å¤æã§ããªãå ´å㯠NaN" );54} );55test( "XPath å¼ãè©ä¾¡ãã¦æåååã§è¿ã", 4, function () {56 var text;57 text = core.evaluateXPath( rootNode, "/ddd/eee/ccc", "string" );58 equal( text, "801", "string åãæå®ãã㨠string ã«å¤æããã¦è¿ã£ã¦ãã" );59 text = core.evaluateXPath( rootNode, "(/ddd/eee/ccc)[2]", "string" );60 equal( text, "NGNG!!", "string åãæå®ãã㨠string ã«å¤æããã¦è¿ã£ã¦ãã" );61 text = core.evaluateXPath( rootNode, "/abcde", "string" );62 equal( text, "", "çµæã空㮠node-set ãªãã° string ã«å¤æããã¨ç©ºæåå" );63 text = core.evaluateXPath( rootNode, "//text", "string" );64 equal( text, "text1text2good",65 "çµæã® node-set ã®å
é ã® node ã«è¤æ°ã® node ãå«ã¾ããå ´åã¯çµåããæåå" );66} );67test( "XPath å¼ãè©ä¾¡ãã¦çå½å¤åã§è¿ã", 2, function () {68 var bool;69 bool = core.evaluateXPath( rootNode, "/ddd/eee/ccc", "boolean" );70 equal( bool, true, "boolean åãæå®ããã¨ç©ºã§ãªã node-set 㯠true ã«ãªã" );71 bool = core.evaluateXPath( rootNode, "/abcde", "boolean" );72 equal( bool, false, "boolean åãæå®ããã¨ç©ºã® node-set 㯠false ã«ãªã" );73} );...
XMLParser.js
Source:XMLParser.js
1import * as APICalls from './APICalls.js';2let xPath;3/**4 * universal xmlParser5 * returns parsed xml text6 * @param {string} text passes an XML String that needs to be parsed7 * @returns {Document} document parsed from xml string8 * */9function xmlParser(text) {10 let parser = new DOMParser();11 return parser.parseFromString(text, "text/xml");12}13/**14 * evaluates a given path for any xml text15 * returns result nodes16 * @param {string} xPath xPath to find needed data in a xml string17 * @param {string} xmlText xml string to be evaluated18 * */19export function evaluateXPATH(xPath, xmlText) {20 let xmlDoc = xmlParser(xmlText);21 return xmlDoc.evaluate(xPath, xmlDoc, null, XPathResult.ANY_TYPE, null);22}23/**24* returns a list of names for module instances25* */26export function getAllModuleInstanceNames() {27 xPath = "//module_instance/@datablock_name"28 return evaluateXPATH(xPath, APICalls.getAllModuleInstances());29}30/**31* get module type with module instance name32 * @param {string} miName module instance name33* */34export function getModuleTypeByModuleInstanceName(miName) {35 xPath = "string(//module_instance[@datablock_name='" + miName + "']/@type)";36 return evaluateXPATH(xPath, APICalls.getAllModuleInstances());37}38/**39 * get module instance node with module instance name40 * @param {string} miName module instance name41 * */42export function getModuleInstanceByModuleInstanceName(miName) {43 xPath = "//module_instance[@datablock_name='" + miName + "']";44 return evaluateXPATH(xPath, APICalls.getAllModuleInstances());45}46/**47* gets all module parameters with its name48 * @param {string} moduleName module name49 * @returns {XPathResult}50**/51export function getModuleParamsByModuleName(moduleName){52 xPath = "//module[@name='"+ moduleName +"']/param";53 return evaluateXPATH(xPath, APICalls.getAllModules());54}55/**56 * gets all module reports by module name57 * @param {string} modName module name58 * @returns {XPathResult}59 * */60export function getModuleReportByModuleName(modName) {61 xPath = "//module[@name='" + modName + "']/report";62 let xmlDoc = xmlParser(APICalls.getAllModules());63 return xmlDoc.evaluate(xPath, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);64}65/**66* gets names of saved processes67* */68export function getAllSavedProcesses(){69 xPath = "//process/@name";70 return evaluateXPATH(xPath,APICalls.getAllSavedProcesses());71}72/**73 * gets names of historical processes74 * */75export function getAllHistoricalProcesses(){76 xPath = "//process/@name";77 return evaluateXPATH(xPath,APICalls.getAllHistoricalProcesses());78}79/**80 * gets IDs of saved processes81 * */82export function getAllProcessesIDs(){83 xPath = "//process/@id";84 return evaluateXPATH(xPath,APICalls.getAllSavedProcesses());85}86/**87 * gets IDs of saved processes88 * */89export function getProcessIDByProcessesName(name){90 xPath = "string(//process[@name='" + name + "']/@id)";91 return evaluateXPATH(xPath,APICalls.getAllSavedProcesses());92}93/**94 * gets IDs of historical processes95 * */96export function getAllHistoricalProcessesIDs(){97 xPath = "//process/@id";98 return evaluateXPATH(xPath,APICalls.getAllHistoricalProcesses());99}100/**101 * gets finished times of historical processes102 * */103export function getAllHistoricalProcessesFinishedTimesByProcessId(id){104 xPath = "//process[@id=\""+id+"\"]//time_finished";105 return evaluateXPATH(xPath,APICalls.getAllHistoricalProcesses());106}107/**108 * gets Status of historical processes109 * */110export function getHistoricalProcessesById(id){111 xPath = "//process[@id=\""+id+"\"]";112 return evaluateXPATH(xPath,APICalls.getAllHistoricalProcesses());113}114/**115 * @param id116 * @return {XPathResult}117 */118export function getRunningProcessModuleInstances(id){119 xPath = "//process/*";120 return evaluateXPATH(xPath,APICalls.getRunningProcess(id));121}122/**123 * @param id124 * @return {XPathResult}125 */126export function getRunningProcessName(id){127 xPath = "//process/@name";128 return evaluateXPATH(xPath,APICalls.getRunningProcess(id));129}130/**131 * @param id132 * @return {XPathResult}133 */134export function getHistoricalProcessModuleInstancesByProcessId(id){135 xPath = "//process[@id=\""+id+"\"]/*";136 return evaluateXPATH(xPath,APICalls.getAllHistoricalProcesses());137}138/**139 * gets IDs of saved modules140 * */141export function getAllModuleIDs(){142 xPath = "//module/@id";143 return evaluateXPATH(xPath,APICalls.getAllModules());144}145/**146 * gets modules of saved modules147 * */148export function getAllModuleNames(){149 xPath = "//module/@name";150 return evaluateXPATH(xPath,APICalls.getAllModules());151}152/**153 * @param {string} pName process name154 * @returns {XPathResult}155 * */156export function getProcessModuleInstancesByProcessName(pName){157 xPath = "/processes/process[@name='" + pName + "']/*";158 return evaluateXPATH(xPath,APICalls.getAllSavedProcesses());159}160/**161 * @return {XPathResult}162 */163export function getRunningProcessesIds(){164 xPath = "/runningProcesses/*";165 return evaluateXPATH(xPath,APICalls.getRunningProcesses());...
SimpleGIO.js
Source:SimpleGIO.js
1function main(csvpath){ 2 readCSV(csvpath);3 while (! DDT.CurrentDriver.EOF())4 { var data = processrow();5 6 OpenURL("https://www.gio.com.au/personal-life-insurance/life-protection-insurance.html");7 GoToLifeQuote();8 FillForm(data);9 CloseBrowser();10 11 DDT.CurrentDriver.Next();12 }13 CloseCSV();14}15function OpenURL(url){16 if(ProjectSuite.Variables.SUITE_BROWSER != null){17 Browsers.Item(ProjectSuite.Variables.SUITE_BROWSER).Run(url);18 }19 else{20 Browsers.Item(btFirefox).Run(url);21 }22 23}24function readCSV(csvpath){25 driver = DDT.CSVDriver(csvpath);26}27function processrow(){28 var line = {};29 line.dod = driver.Value(0); 30 var date = new Date(driver.Value(1));31 line.birthday = date.getDate();32 33 const monthnames= ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]34 line.birthmonth = monthnames[date.getMonth()];35 36 line.birthyear = String(date.getFullYear());37 38 line.gender = driver.Value(2);39 40 line.smoking = driver.Value(3);41 42 line.lifecover = driver.Value(4);43 44 line.coveramount = currencyFormat(driver.Value(5));45 46 line.family = driver.Value(6);47 48 49 return line;50}51function currencyFormat(num) {52 //from: https://blog.abelotech.com/posts/number-currency-formatting-javascript/53 return '$ ' + num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')54}55 56function GoToLifeQuote(){57 let page = Sys.Browser("*").Page("*");58 let arr = page.EvaluateXPath("//a[contains(text(), 'Get a quote in 30 seconds')]");59 // Check the result 60 if (!strictEqual(arr, null))61 {62 // and click the first element that was found 63 arr[0].Click(); // Note we refer to the array item 64 }65 else 66 { 67 // If nothing was found, post a message to the log 68 Log.Error("Nothing was found.");69 }70 aqUtils.Delay(1000);71 //check if on correct page72 page = Sys.Browser("*").Page("*");73 if (!strictEqual(page.EvaluateXPath("//h1[contains(text(),'Life Protect')]"),null))74 {75 Log.Message("OK!");76 }77 else{78 Log.Error("Not on Life Protect!")79 }80}81function FillForm(data){82 let page = Sys.Browser("*").Page("*");83 let cursor = page.EvaluateXPath("//div[@class='dod-section']//span[contains(text(),\'"+data.dod+"\')]",);84 cursor[0].Click();85 cursor = page.EvaluateXPath("//select[contains(@id,'dateOfBirth_Days')]");86 cursor[0].ClickItem(data.birthday);87 cursor = page.EvaluateXPath("//select[contains(@id,'dateOfBirth_Months')]");88 cursor[0].ClickItem(data.birthmonth);89 cursor = page.EvaluateXPath("//select[contains(@id,'dateOfBirth_Years')]");90 cursor[0].ClickItem(data.birthyear);91 cursor = page.EvaluateXPath("//div[@id='genderButtons']//span[contains(text(),\"" + data.gender +"\")]");92 cursor[0].Click();93 cursor = page.EvaluateXPath("//div[@id='smokerButtons']//span[contains(text(),\"" + data.smoking +"\")]");94 cursor[0].Click();95 cursor = page.EvaluateXPath("//div[@id='coverAmountDefinedButtons']//span[contains(text(),\"" + data.lifecover +"\")]");96 cursor[0].Click();97 cursor = page.EvaluateXPath("//select[@id='topCoverAmount']");98 cursor[0].ClickItem(data.coveramount);99 cursor = page.EvaluateXPath("//div[@id='familyDiscountButtons']//span[contains(text(),'No')]");100 cursor[0].Click();101 cursor = page.EvaluateXPath("//button[@id='getQuoteBtn']");102 cursor[0].Click();103 aqUtils.Delay(5000);104}105function CloseBrowser(){106 aqUtils.Delay(1000);107 Sys.Browser("*").Close();108 // Closes the driver109}110function CloseCSV(){111 DDT.CloseDriver(DDT.CurrentDriver.Name);...
Using AI Code Generation
1var apickli = require('apickli');2var apickliObject = new apickli.Apickli('https', 'httpbin.org');3apickliObject.addRequestHeader('Content-Type', 'application/json');4apickliObject.get('/get', function (error, response) {5 if (error) {6 console.log(error);7 } else {8 console.log(response);9 }10});11Your name to display (optional):12Your name to display (optional):13var apickli = require('apickli');14var apickliObject = new apickli.Apickli('https', 'httpbin.org');15apickliObject.addRequestHeader('Content-Type', 'application/json');16apickliObject.get('/get', function (error, response) {17 if (error) {18 console.log(error);19 } else {20 console.log(response);21 }22});23Your name to display (optional):
Using AI Code Generation
1var apickli = require('apickli');2var apickliObject = new apickli.Apickli('http', 'localhost:8080');3 console.log(value);4});5var apickli = require('apickli');6var apickliObject = new apickli.Apickli('http', 'localhost:8080');7 console.log(value[0]);8});9var apickli = require('apickli');10var apickliObject = new apickli.Apickli('http', 'localhost:8080');11 console.log(value[1]);12});13var apickli = require('apickli');14var apickliObject = new apickli.Apickli('http', 'localhost:8080');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!