How to use evaluateXPath method in apickli

Best JavaScript code snippet using apickli

test-xpath-evaluator.js

Source:test-xpath-evaluator.js Github

copy

Full Screen

...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} );...

Full Screen

Full Screen

XMLParser.js

Source:XMLParser.js Github

copy

Full Screen

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());...

Full Screen

Full Screen

SimpleGIO.js

Source:SimpleGIO.js Github

copy

Full Screen

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);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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):

Full Screen

Using AI Code Generation

copy

Full Screen

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');

Full Screen

Using AI Code Generation

copy

Full Screen

1var result = apickli.evaluateXPath('/a/b/c', 'json');2console.log(result);3var result = apickli.evaluateXPath('/a/b/c', 'xml');4console.log(result);5var result = apickli.evaluateXPath('/a/b/c', 'text');6console.log(result);

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run apickli automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful