How to use selectXPath method in mountebank

Best JavaScript code snippet using mountebank

response.js

Source:response.js Github

copy

Full Screen

1import xmldom from 'xmldom'2import xmlenc from 'xml-encryption'3import Debug from 'debug'4import { SUCCESS_STATUS, PROFILEATTRS } from './consts'5import { checkSamlSignature, selectXpath, formatPEM, NIAError } from './utils'6const debug = Debug('saml2')7export function getStatus (dom) {8 var statusNode = selectXpath('//samlp:Status/samlp:StatusCode', dom, 1)9 if (!statusNode) throw new NIAError('Status not found')10 return statusNode.getAttribute('Value')11}12export function decryptAssertion (dom, privateKeys) {13 const privateKey = formatPEM(privateKeys[0], 'PRIVATE KEY')14 return new Promise((resolve, reject) => {15 const encryptedAssertion = selectXpath('//saml:EncryptedAssertion', dom, 1)16 if (!encryptedAssertion) {17 return reject(new NIAError('Expected 1 EncryptedAssertion found'))18 }19 const encryptedData = selectXpath('//xenc:EncryptedData', encryptedAssertion, 1)20 if (!encryptedData) {21 return reject(new NIAError('No EncryptedData inside EncryptedAssertion found'))22 }23 xmlenc.decrypt(encryptedAssertion, { key: privateKey }, (err, result) => {24 if (err) return reject(err)25 resolve(result)26 })27 })28}29export function logoutPostAssert (options, body) {30 const raw = Buffer.from(body.SAMLResponse || body.SAMLRequest, 'base64')31 const samlResponse = (new xmldom.DOMParser()).parseFromString(raw.toString())32 debug(samlResponse)33 const status = getStatus(samlResponse)34 if (status !== SUCCESS_STATUS) {35 throw new NIAError('SAML Response not success!')36 }37 return parseResponseHeader(samlResponse, 'LogoutResponse')38}39export function loginPostAssert (options, body) {40 const raw = Buffer.from(body.SAMLResponse || body.SAMLRequest, 'base64')41 const samlResponse = (new xmldom.DOMParser()).parseFromString(raw.toString())42 debug(samlResponse)43 const response = {44 header: parseResponseHeader(samlResponse, 'Response')45 }46 const status = getStatus(samlResponse)47 if (status !== SUCCESS_STATUS) throw new NIAError('Status: ' + status)48 return decryptAssertion(samlResponse, [options.private_key])49 .then(decriptedXML => {50 const decriptedDoc = new xmldom.DOMParser().parseFromString(decriptedXML)51 const valid = checkSamlSignature(decriptedDoc, decriptedXML, options.certificates[0])52 if (!valid) throw new NIAError('response signature not mathed')53 checkAuthResponse(decriptedXML, options)54 parseAssertionAttributes(decriptedDoc, response)55 return response56 })57}58export function parseResponseHeader (dom, tag) {59 const response = selectXpath(`//samlp:${tag}`, dom, 1)60 if (!response) throw new NIAError('No Response found')61 const responseHeader = {62 version: response.getAttribute('Version'),63 destination: response.getAttribute('Destination'),64 in_response_to: response.getAttribute('InResponseTo'),65 id: response.getAttribute('ID')66 }67 return responseHeader68}69function parseComplexProfileAttr (val) {70 const decoded = Buffer.from(val, 'base64')71 const dom = (new xmldom.DOMParser()).parseFromString(decoded.toString())72 const subAttrs = selectXpath('//*', dom)73 return subAttrs.reduce((obj, i) => {74 const val = selectXpath('string(node())', i)75 if (val) obj[i.localName] = val76 return obj77 }, {})78}79const COMPLEX_ATTRS = [80 PROFILEATTRS.CURRENT_ADDRESS,81 PROFILEATTRS.CZMORIS_TR_ADRESA_ID82]83function parseAssertionAttributes (dom, response) {84 response.NameID = selectXpath('string(//saml:Subject/saml:NameID)', dom, 1)85 response.SessionIndex = selectXpath('//saml:AuthnStatement', dom, 1)86 .getAttribute('SessionIndex')87 response.LoA = selectXpath('string(//saml:AuthnContextClassRef)', dom, 1)88 const vals = selectXpath('//saml:AttributeStatement//saml:Attribute', dom)89 response.user = {}90 vals.map(i => {91 const name = i.getAttribute('Name')92 const frendlyName = i.getAttribute('FriendlyName')93 const val = selectXpath('string(saml:AttributeValue)', i)94 response.user[frendlyName] = COMPLEX_ATTRS.indexOf(name) < 095 ? val : parseComplexProfileAttr(val)96 })97}98function checkAuthResponse (dom, opts) {99 const conditions = selectXpath('//saml:Conditions', dom, 1)100 if (!conditions) return101 const notBefore = Date.parse(conditions.getAttribute('NotBefore'))102 const notAfter = Date.parse(conditions.getAttribute('NotOnOrAfter'))103 const now = Date.now()104 if (now > notBefore) throw new NIAError('SAML Response is not yet valid')105 if (now < notAfter) throw new NIAError('SAML Response is no longer valid')106 const audience = selectXpath('string(//saml:AudienceRestriction/Audience)', dom, 1)107 if (audience !== opts.audience) {108 throw new NIAError('Response is not valid for this audience')109 }...

Full Screen

Full Screen

PastebinHomePage.js

Source:PastebinHomePage.js Github

copy

Full Screen

1import pkg from 'selenium-webdriver';2const { Builder, Browser, By, until, wait } = pkg;3import { BasicPage } from './BasicPage.js';4export class PastebinHomePage extends BasicPage {5 constructor(browser) {6 super(browser);7 this.urlPastebinHome = 'https://pastebin.com';8 this.formXpath = '//*[@id="w0"]';9 this.textareaXpath = '//*[@id="postform-text"]';10 this.buttonCloseBannerXpath = '//*[@id="hideSlideBanner"]';11 this.syntaxSelectXpath = '//*[@id="select2-postform-format-container"]';12 this.syntaxListXpath =13 '//*[@id="select2-postform-format-results"]/li[@class="select2-results__option"]/ul';14 this.expirationSelectXpath =15 '//*[@id="select2-postform-expiration-container"]';16 this.expirationListXpath =17 '//*[@id="select2-postform-expiration-results"]';18 this.itemXpath = '//li[contains(text(), "RAW")]';19 this.pasteTitleXpath = '//*[@id="postform-name"]';20 this.buttonCreateNewPasteXpath =21 '//*[@class="btn -big" and @type="submit"]';22 this.dataTextareaForTaskTwo =23 'git config --global user.name "New Sheriff in Town"' +24 '\n' +25 'git reset $(git commit-tree HEAD^{tree} -m "Legacy code")' +26 '\n' +27 'git push origin master --force';28 }29 async addNewPaste(data) {30 this.fieldOfPaste = await this.driver.wait(31 until.elementLocated(By.xpath(this.textareaXpath)),32 2000033 );34 await this.fieldOfPaste.sendKeys(data);35 }36 async fillSelect(37 selectXpath,38 select,39 selectList,40 selectListXpath,41 selectItem,42 locatorXpath,43 optionText44 ) {45 await this.driver.wait(46 until.elementLocated(By.xpath(this.formXpath)),47 2000048 );49 this.form = await this.driver.findElement(By.xpath(this.formXpath));50 await this.driver.wait(51 until.elementLocated(By.xpath(selectXpath)),52 2000053 );54 select = await this.form.findElement(By.xpath(selectXpath));55 try {56 await select.click();57 } catch (error) {58 if (error.message.includes('element click intercepted')) {59 this.buttonCloseBanner = await this.driver.wait(60 until.elementLocated(By.xpath(this.buttonCloseBannerXpath)),61 2000062 );63 await this.buttonCloseBanner.click();64 await select.click();65 } else {66 throw error;67 }68 }69 await this.driver.wait(70 until.elementLocated(By.xpath(selectListXpath)),71 2000072 );73 selectList = await this.driver.findElement(By.xpath(selectListXpath));74 async function setSearchWordAndSelectOption(75 locatorXpath,76 optionText,77 browser78 ) {79 let itemLocator = await locatorXpath.replace('RAW', optionText);80 await browser.driver.wait(81 until.elementLocated(By.xpath(itemLocator)),82 2000083 );84 selectItem = await selectList.findElement(By.xpath(itemLocator));85 await selectItem.click();86 }87 async function selectOption(browser) {88 await setSearchWordAndSelectOption(89 locatorXpath,90 optionText,91 browser92 );93 }94 selectOption(this);95 }96 async getSelectBefore(selectXpath) {97 this.syntaxBefore = await this.driver98 .wait(until.elementLocated(By.xpath(selectXpath)), 20000)99 .getText();100 }101 async addPasteName(titleContent) {102 await this.driver.wait(103 until.elementLocated(By.xpath(this.pasteTitleXpath)),104 20000105 );106 this.pasteTitle = await this.form.findElement(107 By.xpath(this.pasteTitleXpath)108 );109 await this.pasteTitle.sendKeys(titleContent);110 this.pasteTitleText = await this.pasteTitle.getText();111 }112 async sendPaste() {113 this.buttonCreateNewPaste = await this.driver.wait(114 until.elementLocated(By.xpath(this.buttonCreateNewPasteXpath)),115 20000116 );117 await this.buttonCreateNewPaste.click();118 }119}...

Full Screen

Full Screen

selectOption.js

Source:selectOption.js Github

copy

Full Screen

1'use strict'2const selectOption = async (selectXPath, option) => {3 await $(selectXPath).selectByVisibleText(option)4 browser.execute(selectXPath => {5 const select = document.evaluate(6 selectXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null7 ).singleNodeValue8 const event = new Event('input')9 select.dispatchEvent(event)10 }, selectXPath)11}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var http = require('http');2var options = {3 headers: {4 }5};6var req = http.request(options, function (res) {7 res.setEncoding('utf8');8 res.on('data', function (chunk) {9 console.log(chunk);10 });11});12req.write(JSON.stringify({13 {14 {15 is: {16 }17 }18 {19 equals: {20 }21 }22 }23}));24req.end();25var http = require('http');26var options = {27 headers: {28 }29};30var req = http.request(options, function (res) {31 res.setEncoding('utf8');32 res.on('data', function (chunk) {33 console.log(chunk);34 });35});36req.write(JSON.stringify({37}));38req.end();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createImposterFromSpec } = require("mountebank-helper");2const imposterSpec = {3 {4 {5 equals: {6 }7 }8 {9 is: {10 body: {11 }12 }13 }14 }15};16describe("test", () => {17 it("test", async () => {18 const imposter = await createImposterFromSpec(imposterSpec);19 const response = await imposter.get("/test");20 expect(response.body).toEqual({21 });22 });23});24### createImposterFromSpec(imposterSpec)25### createImposterFromSpec(imposterSpec, options)26### createImposterFromSpec(imposterSpec, options, mbServer)27### createImposterFromSpec(imposterSpec, mbServer)28### createImposterFromSpec(imposterSpec, options, mbServer, logLevel)

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert'),2 mb = require('mountebank'),3 client = mb.createClient({ port: 2525 });4client.get('/imposters', function (error, response) {5 assert.ifError(error);6 assert.strictEqual(response.statusCode, 200);7 console.log(JSON.stringify(response.body, null, 2));8});9client.post('/imposters', {10 {11 {12 is: {13 headers: {14 }15 }16 }17 }18}, function (error, response) {19 assert.ifError(error);20 assert.strictEqual(response.statusCode, 201);21 console.log(JSON.stringify(response.body, null, 2));22});23client.get('/imposters/3000', function (error, response) {24 assert.ifError(error);25 assert.strictEqual(response.statusCode, 200);26 console.log(JSON.stringify(response.body, null, 2));27});28client.get('/imposters/3000/requests', function (error, response) {29 assert.ifError(error);30 assert.strictEqual(response.statusCode, 200);31 console.log(JSON.stringify(response.body, null, 2));32});33client.del('/imposters/3000', function (error, response) {34 assert.ifError(error);35 assert.strictEqual(response.statusCode, 200);36 console.log(JSON.stringify(response.body, null, 2));37});38client.get('/imposters', function (error, response) {39 assert.ifError(error);40 assert.strictEqual(response.statusCode, 200);41 console.log(JSON.stringify(response.body, null, 2));42});43client.get('/imposters/3000', function (error, response) {44 assert.ifError(error);45 assert.strictEqual(response.statusCode, 404);46 console.log(JSON.stringify(response.body, null, 2));47});48client.del('/imposters', function (error, response) {49 assert.ifError(error);50 assert.strictEqual(response.statusCode, 200);51 console.log(JSON.stringify(response.body, null, 2));52});53client.get('/imposters', function (error, response) {54 assert.ifError(error);55 assert.strictEqual(response.statusCode, 200);56 console.log(JSON.stringify(response.body, null, 2));57});58client.post('/im

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert'),2 mb = require('mountebank'),3 client = mb.createClient({ port: 2525 });4client.get('/imposters', function (error, response) {5 assert.ifError(error);6 assert.strictEqual(response.statusCode, 200);7 console.log(JSON.stringify(response.body, null, 2));8});9client.post('/imposters', {10 {11 {12 is: {13 headers: {14 }15 }16 }17 }18}, function (error, response) {19 assert.ifError(error);20 assert.strictEqual(response.statusCode, 201);21 console.log(JSON.stringify(response.body, null, 2));22});23client.get('/imposters/3000', function (error, response) {24 assert.ifError(error);25 assert.strictEqual(response.sta mountebank26var imposter =trequire('usCode, 20').createImposter(2525);27imposter.get('/test', function (request, response) {0);28 var body = '<html><body><h1>Hello World</h1>< body>< html>';29 response({30 headers: { 'Content-Type': 'text/html' },31 });32});33imposter.start();34 corequest = requnre('request');35var cheerio = require('cheerio');36 if (!error && response.statusCode == 200) {37 var $ = cheerio.load(body);38 console.log(h1.text());39 }40});

Full Screen

Using AI Code Generation

copy

Full Screen

1});2client.get('/imposters/3000/requests', function (error, response) {3 assert.ifError(error);4 assert.strictEqual(response.statusCode, 200);5 console.log(JSON.stringify(response.body, null, 2));6});7client.del('/imposters/3000', function (error, response) {8 assert.ifError(error);9 assert.strictEqual(response.statusCode, 200);10 console.log(JSON.stringify(response.body, null, 2));11});12client.get('/imposters', function (error, response) {13 assert.ifError(error);14 assert.strictEqual(response.statusCode, 200);15 console.log(JSON.stringify(response.body, null, 2));16});17client.get('/imposters/3000', function (error, response) {18 assert.ifError(error);19 assert.strictEqual(response.statusCode, 404);20 console.log(JSON.stringify(response.body, null, 2));21});

Full Screen

Using AI Code Generation

copy

Full Screen

1client.del('/imposters', function (error, response) {2 assert.ifError(error);3 assert.strictEqual(response.statusCode, 200);4 console.log(JSON.stringify(response.body, null, 2));5});6client.get('/imposters', function (error, response) {7 assert.ifError(error);8 assert.strictEqual(response.statusCode, 200);9 console.log(JSON.stringify(response.body, null, 2));10});11client.post('/im

Full Screen

Using AI Code Generation

copy

Full Screen

1const { selectXPath } = require('@testim/root-cause-jest');2test('test', async () => {3});4const { selectXPath } = require('@testim/root-cause-jest');5test('test', async () => {6});7const { selectCSS } = require('@testim/root-cause-jest');8test('test', async () => {9 await selectCSS('.test');10});11const { selectCSS } = require('@testim/root-cause-jest');12test('test', async () => {13 await selectCSS('.test');14});15const { selectXPath } = require('@testim/root-cause-jest');16test('test', async () => {17});18const { selectXPath } = require('@testim/root-cause-jest');19test('test', async () => {20});21const { selectText } = require('@testim/root-cause-jest');22test('test', async () => {23 await selectText('test');24});25const { selectText } = require('@testim/root-cause-jest

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 mountebank 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