Best JavaScript code snippet using testcafe
config.js
Source:config.js
...75 }, jstestdriver.utils.serializeErrors));76 // legacy77 jstestdriver.testCaseManager.TestCase = jstestdriver.global.TestCase;78 var id = parseInt(jstestdriver.extractId(top.location.toString()));79 function getBrowserInfo() {80 return new jstestdriver.BrowserInfo(id);81 }82 jstestdriver.manualResourceTracker = new jstestdriver.ManualResourceTracker(83 jstestdriver.JSON.parse,84 jstestdriver.JSON.stringify,85 jstestdriver.pluginRegistrar,86 getBrowserInfo,87 new jstestdriver.ManualScriptLoader(88 window,89 jstestdriver.testCaseManager,90 jstestdriver.now));91 return jstestdriver.executor = createCommandExecutor(92 jstestdriver.testCaseManager,93 jstestdriver.testRunner,...
iframeheight.js
Source:iframeheight.js
1/*2Jquery Iframe Auto Height Plugin3Version 1.2.1 (20.04.2013)4Author : Ilker Guller (http://ilkerguller.com)5Description: This plugin can get contents of iframe and set height of iframe automatically. Also it has cross-domain fix (*).6Details: http://github.com/Sly777/Iframe-Height-Jquery-Plugin7*/8(function($){9 var iframeOptions = {10 resizeMaxTry : 4, // how many try that find true values11 resizeWaitTime : 50, // wait time before next try12 minimumHeight : 200, // minimum height for iframe13 defaultHeight : 3000, // default height for iframe14 heightOffset : 0, // default top offset for iframe15 exceptPages : "", // Pages that doesnt need auto height16 debugMode : false, // Debug mode17 visibilitybeforeload : false, // If you change this to true, iframe will be invisible when every iframe load18 blockCrossDomain : false, // Set true if you dont want use cross domain fix19 externalHeightName : "bodyHeight", // Height data name that comes from postMessage (CDI) and gives height value20 onMessageFunctionName: "getHeight", // Function name that plugin calls this to get data from external source21 domainName : "*" // Set this if you want to get data from specific domain22 };23 $.iframeHeight = function(el, options){24 var base = this;25 $.iframeHeight.resizeTimeout = null;26 $.iframeHeight.resizeCount = 0;27 base.$el = $(el);28 base.el = el;29 base.$el.data("iframeHeight", base);30 base.debug = {31 FirstTime : true,32 Init : function() {33 if (!('console' in window)) console={};34 'log info warn error dir clear'.replace(/\w+/g,function(f) {35 if (!(f in console)) console[f]=console.log||new Function;36 });37 },38 Log : function(message) {39 if(this.FirstTime && this.FirstTime === true){40 this.Init();41 this.FirstTime = false;42 }43 if (base.options.debugMode && base.options.debugMode === true && console && (message !== null || message !== "")) {44 console["log"](message);45 }46 },47 GetBrowserInfo : (function (pub) { // this function is from Jquery.Migrate with IE6 & Browser Null Fix48 var matched, browserObj;49 var uaMatch = function (ua) {50 ua = ua.toLowerCase();51 if (/*@cc_on/*@if(@_jscript_version<=5.6)1@else@*/0/*@end@*/) {52 ua = "msie 6.0";53 }54 var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||55 /(webkit)[ \/]([\w.]+)/.exec(ua) ||56 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||57 /(msie) ([\w.]+)/.exec(ua) ||58 ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||59 [];60 return {61 browserObj: match[ 1 ] || "",62 version: match[ 2 ] || "0"63 };64 };65 matched = uaMatch(navigator.userAgent);66 browserObj = {67 chrome: false,68 safari: false,69 mozilla: false,70 msie: false,71 webkit: false72 };73 if ( matched.browserObj ) {74 browserObj[ matched.browserObj ] = true;75 browserObj.version = matched.version;76 }77 if (browserObj.chrome) {78 browserObj.webkit = true;79 } else if (browserObj.webkit) {80 browserObj.safari = true;81 }82 pub = browserObj;83 return pub;84 }(this.GetBrowserInfo || {}))85 };86 var isThisCDI = function(){87 try88 {89 var contentHtml;90 if (base.debug.GetBrowserInfo.msie && base.debug.GetBrowserInfo.version == "7.0") {91 contentHtml = base.$el.get(0).contentWindow.location.href;92 } else {93 contentHtml = base.$el.get(0).contentDocument.location.href;94 }95 base.debug.Log("This page is non-Cross Domain - " + contentHtml);96 return false;97 }98 catch(err)99 {100 base.debug.Log("This page is Cross Domain");101 return true;102 }103 };104 base.resetIframe = function(){105 if(base.options.visibilitybeforeload && !(base.debug.GetBrowserInfo.msie && base.debug.GetBrowserInfo.version == "7.0")) base.$el.css("visibility", "hidden");106 base.debug.Log("Old Height is " + base.$el.height() + "px");107 base.$el.css("height","").removeAttr("height");108 base.debug.Log("Reset iframe");109 base.debug.Log("Height is " + base.$el.height() + "px after reset");110 };111 base.resizeFromOutside = function(event){112 if(base.options.blockCrossDomain) { 113 base.debug.Log("Blocked cross domain fix");114 return false; 115 }116 if(event === undefined) return false;117 base.resetIframe();118 var frameHeightPx = (parseInt(event.data) + base.options.heightOffset)+'px';119 base.$el.height(frameHeightPx);120 if(base.options.visibilitybeforeload && !(base.debug.GetBrowserInfo.msie && base.debug.GetBrowserInfo.version == "7.0")) base.$el.css("visibility", "visible");121 base.debug.Log("Got height from outside. Height is " + (parseInt(event.data) + base.options.heightOffset) + 'px');122 return true;123 };124 base.checkMessageEvent = function(){ // it works on IE8+, Chrome, Firefox3+, Opera and Safari125 if(base.options.blockCrossDomain || (base.debug.GetBrowserInfo.msie && base.debug.GetBrowserInfo.version == "7.0")) {126 base.debug.Log("Blocked cross domain fix");127 return false; 128 }129 base.resetIframe();130 if(base.options.visibilitybeforeload && !(base.debug.GetBrowserInfo.msie && base.debug.GetBrowserInfo.version == "7.0")) base.$el.css("visibility", "visible");131 if (window.addEventListener) {132 window.addEventListener('message', base.resizeFromOutside, false);133 } else if (window.attachEvent) {134 window.attachEvent('onmessage', base.resizeFromOutside);135 }136 var frame = document.getElementById(base.$el.attr("id"));137 var message = base.options.onMessageFunctionName;138 if (frame.contentWindow.postMessage) {139 frame.contentWindow.postMessage(message, "*");140 }141 else {142 base.debug.Log("Your browser does not support the postMessage method!");143 return false;144 }145 base.debug.Log("Cross Domain Iframe started");146 return true;147 };148 var tryFixIframe = function(){149 if($.iframeHeight.resizeCount <= base.options.resizeMaxTry){150 $.iframeHeight.resizeCount++;151 $.iframeHeight.resizeTimeout = setTimeout(""+$.iframeHeight.resizeIframe()+"", base.options.resizeWaitTime);152 base.debug.Log($.iframeHeight.resizeCount + " time(s) tried");153 } else {154 clearTimeout($.iframeHeight.resizeTimeout);155 $.iframeHeight.resizeCount = 0;156 base.$el.height(base.options.defaultHeight + base.options.heightOffset).css("height", base.options.defaultHeight + base.options.heightOffset);157 if(base.options.visibilitybeforeload && !(base.debug.GetBrowserInfo.msie && base.debug.GetBrowserInfo.version == "7.0")) base.$el.css("visibility", "visible");158 base.debug.Log("set default height for iframe = " + (base.options.defaultHeight + base.options.heightOffset) + "px");159 }160 };161 base.sendInfotoTop = function(){162 if(top.length > 0 && typeof JSON != "undefined"){163 var data = {};164 data[base.options.externalHeightName].value = $(document).height(); 165 var domain = '*';166 data = JSON.stringify(data);167 top.postMessage(data, domain);168 base.debug.Log("sent info to top page");169 return false;170 }171 return true;172 };173 $.iframeHeight.resizeIframe = function(){174 base.resetIframe();175 if(isThisCDI()){176 base.$el.height(base.options.defaultHeight + base.options.heightOffset).css("height", base.options.defaultHeight + base.options.heightOffset);177 if(base.options.visibilitybeforeload && !(base.debug.GetBrowserInfo.msie && base.debug.GetBrowserInfo.version == "7.0")) base.$el.css("visibility", "visible");178 base.checkMessageEvent();179 } else {180 if(base.$el.css("height") === base.options.minimumHeight+"px") {181 base.resetIframe();182 }183 if(base.$el.get(0).contentWindow.document.body !== null) {184 base.debug.Log("This page has body info");185 var _pageHeight = $(base.$el.get(0).contentWindow.document).height();186 var _pageName = base.$el.get(0).contentWindow.document.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1).toLowerCase();187 base.debug.Log("page height : " + _pageHeight + "px || page name : " + _pageName);188 if((_pageHeight <= base.options.minimumHeight && base.options.exceptPages.indexOf(_pageName) == -1)) {189 tryFixIframe();190 } else if (_pageHeight > base.options.minimumHeight && base.options.exceptPages.indexOf(_pageName) == -1) {191 base.$el.height(_pageHeight + base.options.heightOffset).css("height", _pageHeight + base.options.heightOffset);192 if(base.options.visibilitybeforeload && !(base.debug.GetBrowserInfo.msie && base.debug.GetBrowserInfo.version == "7.0")) base.$el.css("visibility", "visible");193 base.debug.Log("Now iframe height is " + (_pageHeight + base.options.heightOffset) + "px");194 }195 } else {196 base.debug.Log("This page has not body info");197 tryFixIframe();198 }199 }200 };201 202 base.init = function(){ 203 base.options = $.extend({},$.iframeHeight.defaultOptions, options);204 base.debug.Log(base.options);205 //noinspection JSValidateTypes206 if(base.$el.get(0).tagName === undefined || base.$el.get(0).tagName.toLowerCase() !== "iframe") {207 base.debug.Log("This element is not iframe!");208 return false;209 }210 211 $.iframeHeight.resizeIframe();212 base.$el.load(function () {213 $.iframeHeight.resizeIframe();214 });215 return true;216 };217 base.init();218 };219 220 $.iframeHeight.defaultOptions = iframeOptions;221 222 $.fn.iframeHeight = function(options){223 return this.each(function(){224 (new $.iframeHeight(this, options));225 });226 };227 $.iframeHeightExternal = function (){228 if(arguments.length === 1) {229 if($.isPlainObject(arguments[0])) {230 iframeOptions = arguments[0];231 }232 }233 if (window.addEventListener) {234 window.addEventListener ("message", OnMessage, false);235 }236 else if (window.attachEvent) {237 window.attachEvent("onmessage", OnMessage);238 }239 function OnMessage (event){240 var _domain;241 if ('domain' in event) {242 _domain = event.domain;243 }244 if ('origin' in event) {245 _domain = event.origin;246 }247 if(iframeOptions.domainName !== "*") {248 if(_domain !== iframeOptions.domainName) {249 $.iframeHeight.debug.Log("It's not same domain. Blocked!");250 return;251 }252 }253 if (event.data == iframeOptions.onMessageFunctionName) {254 var message = $(document).height();255 event.source.postMessage(message, event.origin);256 }257 }258 };...
CommandExecutor.js
Source:CommandExecutor.js
...103 jstestdriver.JSON.stringify(104 new jstestdriver.BrowserLog(1000,105 'jstestdriver.CommandExecutor',106 message,107 this.getBrowserInfo())),108 this.getBrowserInfo());109 if (top.console && top.console.log) {110 top.console.log(message);111 }112 this.streamingService_.close(response, this.__boundExecuteCommand);113 this.unloadSignal_.set(true); // reloads are possible between actions.114 // Propagate the exception.115 throw e;116 }117};118jstestdriver.CommandExecutor.prototype.execute = function(cmd) {119 var response = new jstestdriver.Response(120 jstestdriver.RESPONSE_TYPES.COMMAND_RESULT,121 JSON.stringify(this.__boundEvaluateCommand(cmd)),122 this.getBrowserInfo());123 this.streamingService_.close(response, this.__boundExecuteCommand);124};125jstestdriver.CommandExecutor.prototype.evaluateCommand = function(cmd) {126 var res = '';127 try {128 var evaluatedCmd = eval('(' + cmd + ')');129 if (evaluatedCmd) {130 res = evaluatedCmd.toString();131 }132 } catch (e) {133 res = 'Exception ' + e.name + ': ' + e.message +134 '\n' + e.fileName + '(' + e.lineNumber +135 '):\n' + e.stack;136 }137 return res;138};139/**140 * Registers a command to the executor to handle incoming command requests.141 * @param {String} name The name of the command142 * @param {Object} context The context to call the command in.143 * @param {function(Array):null} func the command.144 */145jstestdriver.CommandExecutor.prototype.registerCommand =146 function(name, context, func) {147 this.commandMap_[name] = jstestdriver.bind(context, func);148};149/**150 * Registers a command to the executor to handle incoming command requests151 * @param {String} name The name of the command152 * @param {Object} context The context to call the command in.153 * @param {function(Array):null} func the command.154 */155jstestdriver.CommandExecutor.prototype.registerTracedCommand =156 function(name, context, func) {157 var bound = jstestdriver.bind(context, func);158 var signal = this.currentActionSignal_;159 this.commandMap_[name] = function() {160 signal.set(name);161 return bound.apply(null, arguments);162 };163};164jstestdriver.CommandExecutor.prototype.dryRun = function() {165 var response =166 new jstestdriver.Response(jstestdriver.RESPONSE_TYPES.TEST_QUERY_RESULT,167 JSON.stringify(this.__testCaseManager.getCurrentlyLoadedTestCases()),168 this.getBrowserInfo());169 170 this.streamingService_.close(response, this.__boundExecuteCommand);171};172jstestdriver.CommandExecutor.prototype.dryRunFor = function(args) {173 var expressions = jsonParse('{"expressions":' + args[0] + '}').expressions;174 var tests = JSON.stringify(175 this.__testCaseManager.getCurrentlyLoadedTestCasesFor(expressions))176 var response = new jstestdriver.Response(177 jstestdriver.RESPONSE_TYPES.TEST_QUERY_RESULT,178 tests,179 this.getBrowserInfo());180 this.streamingService_.close(response, this.__boundExecuteCommand);181};182jstestdriver.CommandExecutor.prototype.listen = function(loadResults) {183 var response;184 if (window.location.href.search('refresh') != -1) {185 response =186 new jstestdriver.Response(jstestdriver.RESPONSE_TYPES.RESET_RESULT,187 '{"loadedFiles":' + JSON.stringify(loadResults) + '}',188 this.getBrowserInfo(),189 true);190 jstestdriver.log('Runner reset: ' + window.location.href);191 } else {192 jstestdriver.log('Listen: ' + window.location.href);193 response =194 new jstestdriver.Response(jstestdriver.RESPONSE_TYPES.BROWSER_READY,195 '{"loadedFiles":' + JSON.stringify(loadResults) + '}',196 this.getBrowserInfo(),197 true);198 }199 this.streamingService_.close(response, this.__boundExecuteCommand);...
browser-provider-test.js
Source:browser-provider-test.js
...9 var originalBrowserToolsOpen = null;10 var originalBrowserToolsGetInstallations = null;11 function getBrowserInfo (arg) {12 return browserProviderPool13 .getBrowserInfo(arg)14 .then(function (browserInfo) {15 return browserInfo.provider.openBrowser('id', 'test-url', browserInfo.browserName);16 })17 .catch(function (error) {18 expect(error.message).to.contain('STOP');19 return processedBrowserInfo;20 });21 }22 before(function () {23 originalBrowserToolsGetBrowserInfo = testcafeBrowserTools.getBrowserInfo;24 originalBrowserToolsOpen = testcafeBrowserTools.open;25 originalBrowserToolsGetInstallations = testcafeBrowserTools.getInstallations;26 testcafeBrowserTools.getBrowserInfo = function (path) {27 return {28 path: path,29 cmd: '--internal-arg'30 };31 };32 testcafeBrowserTools.open = function (browserInfo) {33 processedBrowserInfo = browserInfo;34 throw new Error('STOP');35 };36 testcafeBrowserTools.getInstallations = function () {37 return new Promise(function (resolve) {38 resolve({ chrome: {} });39 });40 };41 });42 after(function () {43 testcafeBrowserTools.getBrowserInfo = originalBrowserToolsGetBrowserInfo;44 testcafeBrowserTools.open = originalBrowserToolsOpen;45 testcafeBrowserTools.getInstallations = originalBrowserToolsGetInstallations;46 });47 it('Should parse browser parameters with arguments', function () {48 return getBrowserInfo('path:/usr/bin/chrome --arg1 --arg2')49 .then(function (browserInfo) {50 expect(browserInfo.path).to.be.equal('/usr/bin/chrome');51 expect(browserInfo.cmd).to.be.equal('--internal-arg --arg1 --arg2');52 });53 });54 it('Should parse browser parameters with arguments if there are spaces in a file path', function () {55 return getBrowserInfo('path:`/opt/Google Chrome/chrome` --arg1 --arg2')56 .then(function (browserInfo) {57 expect(browserInfo.path).to.be.equal('/opt/Google Chrome/chrome');58 expect(browserInfo.cmd).to.be.equal('--internal-arg --arg1 --arg2');59 });60 });61 it('Should parse alias with arguments', function () {62 return getBrowserInfo('chrome --arg1 --arg2')63 .then(function (browserInfo) {64 expect(browserInfo.path).to.be.equal('chrome');65 expect(browserInfo.cmd).to.be.equal('--internal-arg --arg1 --arg2');66 });67 });68 });69 describe('Init/dispose error handling', function () {70 var initShouldSuccess = false;71 var dummyProvider = {72 init: function () {73 if (initShouldSuccess)74 return Promise.resolve();75 return Promise.reject(new Error('Initialization error'));76 },...
getBrowserInfo.spec.js
Source:getBrowserInfo.spec.js
1'use strict'2const assert = require('assert')3const getBrowserInfo = require('../../../lib/utils/getBrowserInfo')4describe('getBrowserInfo(browser)', () => {5 const getEmulatedDevicesSizes = async () => {6 return {7 emulated1: {portrait: {width: 1, height: 11}, landscape: {width: 11, height: 1}},8 emulated2: {portrait: {width: 2, height: 22}, landscape: {width: 22, height: 2}},9 }10 }11 const getIosDevicesSizes = async () => {12 return {13 ios1: {portrait: {width: 10, height: 110}, landscape: {width: 110, height: 10}},14 }15 }16 it('works with desktop browser', async () => {17 const browser = {name: 'browser1', width: 3, height: 33}18 assert.deepStrictEqual(await getBrowserInfo({browser, getEmulatedDevicesSizes, getIosDevicesSizes}), {19 name: 'browser1',20 width: 3,21 height: 33,22 })23 })24 it('works with emulated device syntax', async () => {25 const browser = {deviceName: 'emulated1', name: 'chrome', screenOrientation: 'landscape'}26 assert.deepStrictEqual(await getBrowserInfo({browser, getEmulatedDevicesSizes, getIosDevicesSizes}), {27 name: 'emulated1',28 screenOrientation: 'landscape',29 width: 11,30 height: 1,31 })32 const device1 = {deviceName: 'emulated1'}33 assert.deepStrictEqual(await getBrowserInfo({browser: device1, getEmulatedDevicesSizes, getIosDevicesSizes}), {34 name: 'emulated1',35 screenOrientation: 'portrait',36 width: 1,37 height: 11,38 })39 const device1Portrait = {deviceName: 'emulated1', screenOrientation: 'portrait'}40 assert.deepStrictEqual(41 await getBrowserInfo({browser: device1Portrait, getEmulatedDevicesSizes, getIosDevicesSizes}),42 {43 name: 'emulated1',44 screenOrientation: 'portrait',45 width: 1,46 height: 11,47 },48 )49 const device1Landscape = {deviceName: 'emulated1', screenOrientation: 'landscape'}50 assert.deepStrictEqual(51 await getBrowserInfo({52 browser: device1Landscape,53 getEmulatedDevicesSizes,54 getIosDevicesSizes,55 }),56 {57 name: 'emulated1',58 screenOrientation: 'landscape',59 width: 11,60 height: 1,61 },62 )63 const device2 = {chromeEmulationInfo: {deviceName: 'emulated2'}}64 assert.deepStrictEqual(await getBrowserInfo({browser: device2, getEmulatedDevicesSizes, getIosDevicesSizes}), {65 name: 'emulated2',66 screenOrientation: 'portrait',67 width: 2,68 height: 22,69 })70 const device2Portrait = {71 chromeEmulationInfo: {deviceName: 'emulated2', screenOrientation: 'portrait'},72 }73 assert.deepStrictEqual(74 await getBrowserInfo({browser: device2Portrait, getEmulatedDevicesSizes, getIosDevicesSizes}),75 {76 name: 'emulated2',77 screenOrientation: 'portrait',78 width: 2,79 height: 22,80 },81 )82 const device2Landscape = {83 chromeEmulationInfo: {deviceName: 'emulated2', screenOrientation: 'landscape'},84 }85 assert.deepStrictEqual(86 await getBrowserInfo({87 browser: device2Landscape,88 getEmulatedDevicesSizes,89 getIosDevicesSizes,90 }),91 {92 name: 'emulated2',93 screenOrientation: 'landscape',94 width: 22,95 height: 2,96 },97 )98 })99 it('works with ios device syntax', async () => {100 const device1 = {iosDeviceInfo: {deviceName: 'ios1'}}101 assert.deepStrictEqual(await getBrowserInfo({browser: device1, getEmulatedDevicesSizes, getIosDevicesSizes}), {102 name: 'ios1',103 screenOrientation: 'portrait',104 width: 10,105 height: 110,106 })107 const device1Portrait = {108 iosDeviceInfo: {deviceName: 'ios1', screenOrientation: 'portrait'},109 }110 assert.deepStrictEqual(111 await getBrowserInfo({browser: device1Portrait, getEmulatedDevicesSizes, getIosDevicesSizes}),112 {113 name: 'ios1',114 screenOrientation: 'portrait',115 width: 10,116 height: 110,117 },118 )119 const device1Landscape = {120 iosDeviceInfo: {deviceName: 'ios1', screenOrientation: 'landscape'},121 }122 assert.deepStrictEqual(123 await getBrowserInfo({124 browser: device1Landscape,125 getEmulatedDevicesSizes,126 getIosDevicesSizes,127 }),128 {129 name: 'ios1',130 screenOrientation: 'landscape',131 width: 110,132 height: 10,133 },134 )135 })...
getBrowserInfo.test.js
Source:getBrowserInfo.test.js
...5const getBrowserInfo = require('../../../src/browser/getBrowserInfo');6describe('getBrowserInfo', () => {7 it('should return browser name and width', async () => {8 const browser = {name: 'chrome', width: 800};9 const result = await getBrowserInfo(browser, async () => {});10 expect(result).to.deep.equal(browser);11 });12 it('should return emulated device information', async () => {13 let cmd;14 const browser = {15 deviceName: 'Galaxy S20',16 screenOrientation: 'landscape',17 };18 const result = await getBrowserInfo(browser, async ({command}) => {19 cmd = command;20 return {21 'Galaxy S20': {landscape: {width: 500, height: 200}},22 };23 });24 expect(cmd).to.equal('getEmulatedDevicesSizes');25 expect(result).to.deep.equal({26 name: 'Galaxy S20',27 width: 500,28 height: 200,29 });30 });31 it('should return ios device information', async () => {32 let cmd;33 const browser = {34 iosDeviceInfo: {35 deviceName: 'iPhone XR',36 screenOrientation: 'landscape',37 },38 };39 const result = await getBrowserInfo(browser, async ({command}) => {40 cmd = command;41 return {42 'iPhone XR': {landscape: {width: 500, height: 200}},43 };44 });45 expect(cmd).to.equal('getIosDevicesSizes');46 expect(result).to.deep.equal({47 name: 'iPhone XR',48 width: 500,49 height: 200,50 });51 });52 it('throws an informative error message', async () => {53 let cmd;54 const browser = {55 deviceName: 'iPhone 11 Pro',56 screenOrientation: 'landscape',57 };58 const [err] = await presult(59 getBrowserInfo(browser, async ({command}) => {60 cmd = command;61 return {62 'iPhone X': {landscape: {width: 500, height: 200}},63 };64 }),65 );66 expect(cmd).to.equal('getEmulatedDevicesSizes');67 expect(err.toString().split('\n')[0]).to.equal(68 `Error: 'iPhone 11 Pro' does not exist in the list of emulated devices.`,69 );70 });...
browser.js
Source:browser.js
...3const {4 browser: { name, version },5 os: { name: os },6 platform: { type: platform },7} = getBrowserInfo();8export default WrappedComponent => props => (9 <WrappedComponent10 {...props}11 browser={{12 name,13 os,14 platform,15 version,16 }}17 />...
index.js
Source:index.js
12import { cookieStore } from "./cookieStore"3import { sessionStore } from "./sessionStore"4import { getBrowserInfo } from './getBrowserInfo'56export {7 cookieStore,8 sessionStore,9 getBrowserInfo,
...
Using AI Code Generation
1import { ClientFunction } from 'testcafe';2const getBrowserInfo = ClientFunction(() => {3 return {4 };5});6test('My Test', async t => {7 const browserInfo = await getBrowserInfo();8 console.log(browserInfo);9});10import { chromium } from 'playwright';11const browser = await chromium.launch();12const context = await browser.newContext();13const page = await context.newPage();14const browserInfo = await page.evaluate(() => {15 return {16 };17});18console.log(browserInfo);19await browser.close();
Using AI Code Generation
1import { ClientFunction } from 'testcafe';2const getBrowserInfo = ClientFunction(() => {3 return {4 };5});6test('My Test', async t => {7 const browserInfo = await getBrowserInfo();8 console.log(browserInfo);9});10import { ClientFunction } from 'testcafe';11const getBrowserInfo = ClientFunction(() => {12 return {13 };14});15test('My Test', async t => {16 const browserInfo = await getBrowserInfo();17 console.log(browserInfo);18});19import { ClientFunction } from 'testcafe';20const getBrowserInfo = ClientFunction(() => {21 return {22 };23});24test('My Test', async t => {25 const browserInfo = await getBrowserInfo();26 console.log(browserInfo);27});28import { ClientFunction } from
Using AI Code Generation
1import { getBrowserInfo } from 'testcafe-browser-tools';2test('My Test', async t => {3 const browserInfo = await getBrowserInfo('chrome');4 console.log(browserInfo);5});6import { createBrowserConnection } from 'testcafe';7test('My Test', async t => {8 const connection = await createBrowserConnection();9 const runner = await testcafe.createRunner();10 .src('test.js')11 .browsers(connection)12 .run();13 const results = await connection.waitForConnectionReady();14 console.log(results);15});16const createTestCafe = require('testcafe');17const testcafe = await createTestCafe('localhost', 1337, 1338);18const runner = testcafe.createRunner();19 .src('test.js')20 .browsers('chrome')21 .run();
Using AI Code Generation
1import { Selector, t } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 const articleHeader = await Selector('.result-content').find('h1');6 const browserInfo = await t.getBrowserInfo();7 if (browserInfo.name === 'chrome') {8 await t.expect(articleHeader.innerText).eql('Thank you, John Smith!');9 }10 else {11 await t.expect(articleHeader.innerText).eql('Thank you, John Smith!');12 }13});14{ name: 'chrome', version: '70.0.3538.110' }
Using AI Code Generation
1import { ClientFunction } from 'testcafe';2const getBrowserInfo = ClientFunction(() => {3 return {4 };5});6test('My first test', async t => {7 const browserInfo = await getBrowserInfo();8 console.log(browserInfo);9});10import { ClientFunction } from 'testcafe';11const getBrowserInfo = ClientFunction(() => {12 return {13 };14});15test('My first test', async t => {16 const browserInfo = await getBrowserInfo();17 console.log(browserInfo);18 if(browserInfo.userAgent.indexOf("Chrome") > -1){19 await t.typeText('#developer-name', 'John Smith');20 await t.click('#submit-button');21 }22});
Using AI Code Generation
1import { getBrowserInfo } from 'testcafe-browser-tools';2test('My Test', async t => {3 .expect(getBrowserInfo('chrome'))4 .eql({5 os: {6 },7 });8});9import { getBrowserInfo } from 'testcafe-browser-tools';10test('My Test', async t => {11 .expect(getBrowserInfo('safari'))12 .eql({13 os: {14 },15 });16});17import { getBrowserInfo } from 'testcafe-browser-tools';18test('My Test', async t =>
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!!