How to use hostInfo method in wpt

Best JavaScript code snippet using wpt

index.js

Source:index.js Github

copy

Full Screen

1var _ = require('lodash'),2 request = require('request'),3 URLParser = require('url'),4 deferred = require('deferred'),5 cheerio = require('cheerio'),6 microdataParser = require('microdata-node'),7 windows1251 = require('windows-1251'),8 ns = require('./lib/ns'),9 defaultHeaders,10 Ecomparser;11defaultHeaders = {12 'User-Agent' : 'curl/7.35.0',13 'Accept' : '*/*',14 'Accept-Encoding' : '',15 'Cache-Control' : 'max-age=0',16 'Referer' : 'http://farennikov.com',17 'Connection' : 'close'18}19function parseNumber(str) {20 return str.match(/(\d+).? ?(\d+)/)[0].replace(' ','');21}22function getHostInfo(siteData, hostname) {23 var retval = _.reduce(siteData, function(memo, data, host) {24 var reStr = host.replace('*', '.+?'),25 re = new RegExp(reStr),26 matches = hostname.match(re);27 if (matches !== null) memo = data;28 return memo;29 }, null);30 return retval;31}32function getCharset(html) {33 var matches = html.match(/charset=["]*([^>"\s]+)/i);34 return matches.length ? matches[1].toLowerCase() : undefined;35}36function decodeHTML(html) {37 var charset = getCharset(html),38 decoded;39 switch (charset) {40 case 'windows-1251':41 decoded = windows1251.decode(html, { 'mode': 'html' });42 break;43 default:44 decoded = html;45 }46 return decoded;47}48function cleanTxt(str) {49 str = str.replace(/ +(?= )/g, '');50 str = str.replace(/\r?\n|\r/g, '');51 return str.trim();52}53module.exports = Ecomparser = function(url, siteData) {54 var def = deferred(),55 reqOpts = {56 url : url,57 headers : defaultHeaders58 };59 /* --- Try loading and parsing page --- */60 request(reqOpts, function (error, response, html) {61 var retData = {};62 if (!error && response.statusCode === 200) {63 var parsedURL = URLParser.parse(url),64 hostInfo,65 $page,66 microdata,67 parsedImgURL;68 /* --- Detect character encoding and decode HTML if necessary --- */69 html = decodeHTML(html);70 /* --- Set page's hostname --- */71 retData.hostname = parsedURL.hostname;72 hostInfo = getHostInfo(siteData, retData.hostname);73 if (!hostInfo) return def.reject(new Error('Host info is not defined for ' + retData.hostname));74 $page = cheerio.load(html);75 microdata = microdataParser.toJson(html);76 // console.log('microdata:', JSON.stringify(ns.get(microdata, 'items.5.properties.image'), null, 2));77 /* --- Set default values --- */78 retData.url = url;79 retData.title = null;80 retData.image = null;81 retData.price = null;82 retData.priceCurrency = null;83 /* --- Get title --- */84 if (hostInfo.title && hostInfo.title.selector) {85 if (hostInfo.title.attr) {86 retData.title = $page(hostInfo.title.selector).attr(hostInfo.title.attr);87 } else {88 retData.title = $page(hostInfo.title.selector).text();89 }90 }91 retData.title = cleanTxt(retData.title);92 /* --- Get image --- */93 if (hostInfo.image && hostInfo.image.microdata) {94 retData.image = ns.get(microdata, hostInfo.image.microdata);95 } else if (hostInfo.image.selector) {96 if (hostInfo.image.attr) {97 retData.image = $page(hostInfo.image.selector).attr(hostInfo.image.attr);98 } else {99 retData.image = $page(hostInfo.image.selector).text();100 }101 }102 /* --- Fix images with relative URLs --- */103 parsedImgURL = URLParser.parse(retData.image);104 if (parsedImgURL.host === null) {105 parsedImgURL.protocol = parsedURL.protocol;106 parsedImgURL.host = parsedURL.host;107 retData.image = URLParser.format(parsedImgURL);108 }109 /* --- Get canonical URL --- */110 if (hostInfo.url && hostInfo.url.selector) {111 if (hostInfo.url.attr) {112 retData.url = $page(hostInfo.url.selector).attr(hostInfo.url.attr) || url;113 } else {114 retData.url = $page(hostInfo.url.selector).text() || url;115 }116 }117 /* --- Get price ---*/118 if (hostInfo.price && hostInfo.price.microdata) {119 try {120 retData.price = parseNumber(ns.get(microdata, hostInfo.price.microdata));121 } catch (err) {122 console.warn('Parsing price failed for', hostInfo.price.microdata);123 console.log('microdata:', JSON.stringify(ns.get(microdata, 'items'), null, 2));124 }125 } else if (hostInfo.price.selector) {126 if (hostInfo.price.attr) {127 retData.price = parseNumber($page(hostInfo.price.selector).attr(hostInfo.price.attr));128 } else {129 retData.price = parseNumber($page(hostInfo.price.selector).text());130 }131 }132 /* --- Get currency ---*/133 if (hostInfo.priceCurrency && hostInfo.priceCurrency.microdata) {134 retData.priceCurrency = ns.get(microdata, hostInfo.priceCurrency.microdata);135 } else if (hostInfo.priceCurrency.selector) {136 if (hostInfo.priceCurrency.attr) {137 retData.priceCurrency = $page(hostInfo.priceCurrency.selector).attr(hostInfo.priceCurrency.attr);138 } else {139 retData.priceCurrency = $page(hostInfo.priceCurrency.selector).text();140 }141 } else {142 retData.priceCurrency = hostInfo.priceCurrency.default;143 }144 /* --- Resolve deferred --- */145 def.resolve(retData);146 } else {147 console.log('FAILED:', url, error, html);148 def.reject(error);149 }150 });151 return def.promise;152}153Ecomparser.analize = function(url) {154 var def = deferred(),155 reqOpts = {156 url : url,157 headers : defaultHeaders158 };159 /* --- Try loading and parsing page --- */160 request(reqOpts, function (error, response, html) {161 var retData = {},162 microdata;163 if (!error && response.statusCode === 200) {164 /* --- Set defaults --- */165 retData.opengaph = false;166 retData.schema = false;167 retData.charset = getCharset(html);168 /* --- Check opengaph markup --- */169 if (html.match(/property=["|']*og:name/gi)) {170 retData.opengaph = true;171 retData.name = true;172 }173 if (html.match(/property=["|']*og:url/gi)) {174 retData.opengaph = true;175 retData.url = true;176 }177 if (html.match(/property=["|']*og:image/gi)) {178 retData.opengaph = true;179 retData.image = true;180 }181 /* --- Check microformat (schema) --- */182 microdata = microdataParser.toJson(html);183 if (microdata) retData.schema = true;184 def.resolve(retData);185 } else {186 console.log('FAILED:', url, error, html);187 def.reject(error);188 }189 });190 return def.promise;...

Full Screen

Full Screen

hostinfo.js

Source:hostinfo.js Github

copy

Full Screen

1// SERVER-4615: Ensure hostInfo() command returns expected results on each platform2assert.commandWorked( db.hostInfo() );3var hostinfo = db.hostInfo();4// test for os-specific fields5if (hostinfo.os.type == "Windows") {6 assert.neq( hostinfo.os.name, "" || null, "Missing Windows os name" );7 assert.neq( hostinfo.os.version, "" || null, "Missing Windows version" );8} else if (hostinfo.os.type == "Linux") {9 assert.neq( hostinfo.os.name, "" || null, "Missing Linux os/distro name" );10 assert.neq( hostinfo.os.version, "" || null, "Missing Lindows version" );11} else if (hostinfo.os.type == "Darwin") {12 assert.neq( hostinfo.os.name, "" || null, "Missing Darwin os name" );13 assert.neq( hostinfo.os.version, "" || null, "Missing Darwin version" );14} else if (hostinfo.os.type == "BSD") {15 assert.neq( hostinfo.os.name, "" || null, "Missing FreeBSD os name" );16 assert.neq( hostinfo.os.version, "" || null, "Missing FreeBSD version" );17}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');3 if (err) {4 console.log(err);5 } else {6 console.log('Test submitted. Polling for results...');7 wpt.getTestResults(data.data.testId, function(err, data) {8 if (err) {9 console.log(err);10 } else {11 console.log('Test complete!');12 console.log(data.data);13 }14 });15 }16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');19wpt.hostInfo(function(err, data) {20 if (err) {21 console.log(err);22 } else {23 console.log(data);24 }25});26 if (err) {27 console.log(err);28 } else {29 console.log('Test submitted. Polling for

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('API_KEY');3 if (err) return console.log(err);4 test.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.log(err);6 test.getLocations(function(err, data) {7 if (err) return console.log(err);8 console.log(data);9 });10 });11});12{ data:13 { locations:14 [ { location: 'Dulles:Chrome',15 default: '1' },16 { location: 'Dulles:Firefox',17 default: '0' },18 { location: 'Dulles:IE10',19 default: '0' },20 { location: 'Dulles:IE11',21 default: '0' },22 { location: 'Dulles:IE9',23 default: '0' },24 { location: 'Dulles:Opera',25 default: '0' },26 { location: 'Dulles:Safari',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var test = new wpt(options);5 if (err) {6 console.log(err);7 } else {8 test.getTestResults(data.data.testId, function(err, data) {9 if (err) {10 console.log(err);11 } else {12 console.log(data.data.runs[1].firstView);13 }14 });15 }16});17{ TTFB: 163,18 testStartOffset: 0 }19var wpt = require('webpagetest');20var options = {21};22var test = new wpt(options);23 if (err) {24 console.log(err);25 } else {26 test.getTestResults(data.data.testId, function(err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data.data.runs[1].repeatView);31 }32 });33 }34});35{ TTFB: 148,

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var client = wpt('www.webpagetest.org');11client.getTestResults('151101_8N_1e6', function(err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18var wpt = require('webpagetest');19var client = wpt('www.webpagetest.org');20client.getTestHistory('151101_8N_1e6', function(err, data) {21 if (err) {22 console.log(err);23 } else {24 console.log(data);25 }26});27var wpt = require('webpagetest');28var client = wpt('www.webpagetest.org');29client.getLocations(function(err, data) {30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36var wpt = require('webpagetest');37var client = wpt('www.webpagetest.org');38client.getTesters(function(err, data) {39 if (err) {40 console.log(err);41 } else {42 console.log(data);43 }44});45var wpt = require('webpagetest');46var client = wpt('www.webpagetest.org');47client.getMedianRun('151101_8N_1e6', function(err, data) {48 if (err) {49 console.log(err);50 } else {51 console.log(data);52 }53});54var wpt = require('webpagetest');55var client = wpt('www.webpagetest.org');56client.getWaterfall('151101_8N_1e6', function(err, data) {57 if (err) {58 console.log(err);59 } else

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.hostInfo(function(err, data) {3 console.log(data);4});5{ statusCode: 200,6 { host: 'www.webpagetest.org',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest-api');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.hostInfo(function(err, data) {4 if (err) return console.log(err);5 console.log(data);6});7var wpt = require('webpagetest-api');8var wpt = new WebPageTest('www.webpagetest.org');9 if (err) return console.log(err);10 console.log(data);11});12var wpt = require('webpagetest-api');13var wpt = new WebPageTest('www.webpagetest.org');14 if (err) return console.log(err);15 console.log(data);16});17var wpt = require('webpagetest-api');18var wpt = new WebPageTest('www.webpagetest.org');19 if (err) return console.log(err);20 console.log(data);21});22var wpt = require('webpagetest-api');23var wpt = new WebPageTest('www.webpagetest.org');24 if (err) return console.log(err);25 console.log(data);26});27var wpt = require('webpagetest-api');28var wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var hostInfo = wpt.hostInfo(function(error, data) {3 if (error) {4 console.log(error);5 } else {6 console.log("Host Info: " + data);7 }8});9var wpt = require('wpt');10var runTest = wpt.runTest(testUrl, function(error, data) {11 if (error) {12 console.log(error);13 } else {14 console.log("Test Result: " + data);15 }16});17var wpt = require('wpt');18var testId = "140529_6V_5f1";19var getTestResults = wpt.getTestResults(testId, function(error, data) {20 if (error) {21 console.log(error);22 } else {23 console.log("Test Results: " + data);24 }25});26var wpt = require('wpt');27var getLocations = wpt.getLocations(function(error, data) {28 if (error) {29 console.log(error);30 } else {31 console.log("Locations: " + data);32 }33});34var wpt = require('wpt');35var getTesters = wpt.getTesters(function(error, data) {36 if (error) {37 console.log(error);38 } else {39 console.log("Testers: " + data);40 }41});42var wpt = require('wpt');43var testId = "140529_6V_5f1";44var getTestStatus = wpt.getTestStatus(testId, function(error, data) {45 if (error) {46 console.log(error);47 } else {48 console.log("Test Status: " + data);49 }50});51var wpt = require('wpt');

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