How to use submitFrame method in wpt

Best JavaScript code snippet using wpt

jquery-frame.0b2e88fb5b601b5b3bcb6c60ac4ddc41.gz.js

Source:jquery-frame.0b2e88fb5b601b5b3bcb6c60ac4ddc41.gz.js Github

copy

Full Screen

1/** Inline FRAME/IFRAME replacement. */2(function ($, win, undef) {3 var $win = $(win),4 doc = win.document,5 formTargetIndex = 0;6 $.plugin2('frame', {7 '_defaultOptions': {8 'frameClassName': 'dari-frame',9 'loadingClassName': 'dari-frame-loading',10 'loadedClassName': 'dari-frame-loaded',11 'bodyClassName': 'dari-frame-body',12 'setBody': function (body) {13 $(this).html(body);14 }15 },16 '_init': function (selector, options) {17 var plugin = this,18 $caller = plugin.$caller,19 frameClassName = options.frameClassName,20 loadingClassName = options.loadingClassName,21 loadedClassName = options.loadedClassName,22 bodyClassName = options.bodyClassName,23 findTargetFrame,24 beginLoad,25 endLoad,26 loadPage;27 // Finds the target frame, creating one if necessary.28 findTargetFrame = function (element, callback) {29 var $element = $(element),30 target = $element.attr('data-frame-target') || $element.attr('target'),31 $frame;32 // Standard HTML elements that can handle the target.33 if (target && $('frame[name="' + target + '"], iframe[name="' + target + '"]').length > 0) {34 return true;35 }36 // Skip processing on special target names.37 if (target !== '_top' && target !== '_blank') {38 if (target === '_parent') {39 $frame = $element.frame('container').parent().frame('container');40 } else if (target) {41 $frame = $('.' + frameClassName + '[name="' + target + '"]');42 if ($frame.length === 0) {43 $frame = $('<div/>', { 'class': frameClassName, 'name': target });44 $(doc.body).append($frame);45 $frame.popup();46 }47 } else {48 $frame = $element.frame('container');49 }50 if ($frame.length > 0 && $frame[0] !== doc) {51 return callback($element, $frame);52 }53 }54 // Natural browser event.55 return true;56 };57 // Begins loading $frame using $source.58 beginLoad = function ($frame, $source, event) {59 var version = ($frame.data('frame-loadVersion') || 0) + 1,60 $popup = $frame.popup('container');61 $frame.add($popup).removeClass(loadedClassName).addClass(loadingClassName);62 $frame.data('frame-loadVersion', version);63 $frame.data('frame-$source', $source);64 if ($popup[0] && $source[0] && !$.contains($popup[0], $source[0])) {65 $frame.popup('source', $source, event);66 $frame.empty();67 }68 if ($frame.parent().frame('container').length == 0) {69 $frame.popup('open');70 }71 return version;72 };73 // Ends loading $frame by setting it using data.74 endLoad = function ($frame, version, data) {75 var $popup,76 $wrapper,77 $bodyContainer,78 body;79 if (version >= $frame.data('frame-loadVersion')) {80 $popup = $frame.popup('container');81 body = data;82 body = body.replace(new RegExp("^[^]*?<body[^>]*>","ig"), '');83 body = body.replace(new RegExp("<\/body>[/s/S]*?$","ig"), '');84 $frame.add($popup).removeClass(loadingClassName).addClass(loadedClassName);85 options.setBody.call($frame[0], body);86 $frame.trigger('create');87 $frame.trigger('load');88 $frame.trigger('frame-load');89 $win.resize();90 }91 };92 // Loads the page at url into the $frame.93 loadPage = function ($frame, $source, method, url, data, event) {94 var plugin = this,95 version = beginLoad($frame, $source, event),96 extraFormData = $frame.attr('data-extra-form-data');97 if (extraFormData) {98 url += (url.indexOf('?') < 0 ? '?' : '&') + extraFormData;99 }100 if (101 $source.find('input[name="captchaPublicKey"]').val() &&102 !$source.find('input[name="captchaUserToken"]').val()103 ) {104 return false;105 }106 $.ajax({107 'cache': false,108 'type': method,109 'url': url,110 'data': data,111 'success': function (data, textStatus, jqXHR) {112 endLoad($frame, version, jqXHR.responseText);113 },114 'error': function (jqXHR, textStatus, errorThrown) {115 console.log('jquery-frame error:', textStatus, errorThrown);116 }117 });118 };119 // Intercept anchor clicks to see if it's targeted.120 $caller.delegate('a', 'click.frame', function (event) {121 // Ignore privacy links122 if (event.target.closest('.legal-disclaimer')) {123 return true;124 }125 return findTargetFrame(this, function ($anchor, $frame) {126 loadPage($frame, $anchor, 'get', $anchor.attr('href'), null, event);127 return false;128 });129 });130 $caller.on('change', ':checkbox[data-frame-target]', function (event) {131 return findTargetFrame(this, function ($checkbox, $frame) {132 var href = $checkbox.prop('checked') ?133 $checkbox.attr('data-frame-check') :134 $checkbox.attr('data-frame-uncheck');135 loadPage($frame, $checkbox, 'get', href, null, event);136 });137 });138 // check if event handler already exists139 // if exists, skip this item140 if (!$caller.data('click.frame')) {141 // flag item to prevent attaching handler again142 $caller.data('click.frame', true);143 // Intercept form submits to see if it's targeted.144 $caller.delegate('form', 'click.frame', function (event) {145 if (!$(event.target).is('button, input[type="submit"]')) {146 return;147 }148 $.data(this, 'frame-clicked', event.target);149 });150 }151 // check if event handler already exists152 // if exists, skip this item153 if (!$caller.data('submit.frame')) {154 // flag item to prevent attaching handler again155 $caller.data('submit.frame', true);156 $caller.delegate('form', 'submit.frame', function () {157 return findTargetFrame(this, function ($form, $frame) {158 var action = $form.attr('action'),159 extraFormData = $frame.attr('data-extra-form-data'),160 clicked = $.data($form[0], 'frame-clicked'),161 clickedName,162 clickedValue;163 if (clicked) {164 clickedName = $(clicked).prop('name');165 clickedValue = $(clicked).prop('value');166 if (clickedName && clickedValue) {167 action += (action.indexOf('?') > -1 ? '&' : '?') + encodeURIComponent(clickedName) + '=' + encodeURIComponent(clickedValue);168 }169 }170 if ($form.attr('enctype') !== 'multipart/form-data') {171 loadPage($frame, $form, $form.attr('method'), action, $form.serialize());172 return false;173 }174 $form.attr('action', action + (action.indexOf('?') < 0 ? '?' : '&') + extraFormData);175 if ($form.find('input[type="hidden"][name="_frame"]').length === 0) {176 $form.prepend($('<input/>', {177 'name': '_frame',178 'type': 'hidden',179 'value': 'true'180 }));181 }182 // Add a target for $submitFrame later in case one doesn't exist.183 var target = $form.attr('target');184 var hasTarget = true;185 if (!target) {186 formTargetIndex += 1;187 target = 'frameTarget' + formTargetIndex + (+new Date());188 $form.attr('target', target);189 hasTarget = false;190 }191 var $submitFrame = $('iframe[name=' + target + ']');192 if ($submitFrame.length === 0) {193 $submitFrame = $('<iframe/>', {'name': target});194 $submitFrame.hide();195 $(doc.body).append($submitFrame);196 }197 var version = beginLoad($frame, $form);198 $submitFrame.unbind('.frame');199 $submitFrame.bind('load.frame', function () {200 $form.attr('action', action);201 endLoad($frame, version, $submitFrame.contents().find('textarea#frameBody').val() || $submitFrame.contents().find('body').html());202 if (!hasTarget) {203 $form.removeAttr('target');204 setTimeout(function () {205 $submitFrame.remove();206 }, 0);207 }208 });209 return true;210 });211 });212 }213 // Any existing frame should be loaded.214 $caller.onCreate('.' + frameClassName, function () {215 var $frame = $(this),216 $anchor;217 if ($frame.is(':not(.' + loadingClassName + '):not(.' + loadedClassName + ')')) {218 $anchor = $frame.find('a:only-child:not([target])');219 if ($anchor.length > 0) {220 $anchor.click();221 } else {222 $frame.find('form:only-child:not([target])').submit();223 }224 }225 });226 return $caller;227 },228 // Returns the enclosing element that contains the frame.229 'container': function () {230 return this.$caller.closest('.' + this.option('frameClassName'));231 },232 // Returns the source element that triggered the frame to be populated.233 'source': function () {234 return this.container().data('frame-$source');235 }236 });...

Full Screen

Full Screen

jquery.frame.js

Source:jquery.frame.js Github

copy

Full Screen

1if (typeof jQuery !== 'undefined') (function($) {2// Inline frame replacement.3var formTargetIndex = 0;4$.plugin('frame', {5// Returns the enclosing element that contains the frame.6'container': function() {7 return this.closest('.frame');8},9// Returns the source element that triggered the frame to be populated.10'source': function() {11 return this.frame('container').frame('data', '$source');12},13// Initializes the frame.14'init': function() {15 return this.each(function() {16 var $body = $(this);17 // Finds the target frame, creating one if necessary.18 var findTargetFrame = function(element, callback) {19 var $element = $(element);20 var target = $element.attr('target');21 // Standard HTML elements that can handle the target.22 if (target && $('frame[name=' + target + '], iframe[name=' + target + ']').length > 0) {23 return true;24 }25 // Skip processing on special target names.26 if (target != '_top' && target != '_blank') {27 var $frame;28 if (target == '_parent') {29 $frame = $element.closest('.frame').parent().closest('.frame');30 } else if (target) {31 $frame = $body.find('.frame[name=' + target + ']');32 if ($frame.length == 0) {33 $frame = $('<div/>', { 'class': 'frame', 'name': target });34 $body.append($frame);35 $frame.popup();36 }37 } else {38 $frame = $element.closest('.frame');39 }40 if ($frame.length > 0) {41 return callback($element, $frame);42 }43 }44 // Natural browser event.45 return true;46 };47 // Begins loading $frame using $source.48 var beginLoad = function($frame, $source) {49 var version = ($frame.frame('data', 'loadVersion') || 0) + 1;50 var $popup = $frame.popup('container');51 $frame.add($popup).removeClass('loaded').addClass('loading');52 $frame.frame('data', 'loadVersion', version);53 $frame.frame('data', '$source', $source);54 // Source change on popup?55 var $oldSource = $frame.popup('source');56 if ($popup[0] && (!$oldSource || $oldSource[0] != $source[0]) && (!$source[0] || !$.contains($popup[0], $source[0]))) {57 $frame.popup('source', $source);58 $frame.empty();59 }60 $frame.popup('open');61 return version;62 };63 // Ends loading $frame by setting it using data.64 var endLoad = function($frame, version, data) {65 if (version >= $frame.frame('data', 'loadVersion')) {66 var $popup = $frame.popup('container');67 $frame.add($popup).removeClass('loading').addClass('loaded');68 if (typeof data === 'string') {69 data = data.replace(/^.*?<body[^>]*>/ig, '');70 data = data.replace(/<\/body>.*?$/ig, '');71 }72 $frame.html(data);73 $(window).resize();74 $frame.trigger('load');75 }76 };77 // Loads the page at url into the $frame.78 var loadPage = function($frame, $source, url) {79 var version = beginLoad($frame, $source);80 $.ajax({81 'cache': false,82 'url': url,83 'complete': function(response) {84 endLoad($frame, version, response.responseText);85 }86 });87 };88 // Intercepts anchor clicks to see if it's targeted. 89 $body.find('a').live('click', function() {90 return findTargetFrame(this, function($anchor, $frame) {91 loadPage($frame, $anchor, $anchor.attr('href'));92 return false;93 });94 });95 // Intercepts form submits to see if it's targeted. 96 $body.find('form').live('submit', function() {97 return findTargetFrame(this, function($form, $frame) {98 if ($form.attr('method') === 'get') {99 var action = $form.attr('action');100 loadPage($frame, $form, action + (action.indexOf('?') > -1 ? '&' : '?') + $form.serialize());101 return false;102 }103 var $isFrame = $form.find(':hidden[name=_isFrame]');104 if ($isFrame.length == 0) {105 $isFrame = $('<input name="_isFrame" type="hidden" value="true"/>');106 $form.prepend($isFrame);107 }108 // Add a target for $submitFrame later in case one doesn't exist.109 var target = $form.attr('target');110 var hasTarget = true;111 if (!target) {112 formTargetIndex += 1;113 target = 'frameTarget' + formTargetIndex + (+new Date());114 $form.attr('target', target);115 hasTarget = false;116 }117 var $submitFrame = $('iframe[name=' + target + ']');118 if ($submitFrame.length == 0) {119 $submitFrame = $('<iframe/>', { 'name': target });120 $submitFrame.hide();121 $body.append($submitFrame);122 }123 var version = beginLoad($frame, $form);124 $submitFrame.unbind('.frame');125 $submitFrame.bind('load.frame', function() {126 endLoad($frame, version, $submitFrame.contents().find('body').html());127 if (!hasTarget) {128 $form.removeAttr('target');129 setTimeout(function() { $submitFrame.remove() }, 0);130 }131 });132 return true;133 });134 });135 // Any existing frame should be loaded.136 $body.find('.frame').liveInit(function() {137 var $frame = $(this);138 if ($frame.is(':not(.loading):not(.loaded)')) {139 var $anchor = $frame.find('a:only-child:not([target])');140 if ($anchor.length > 0) {141 $anchor.click();142 } else {143 $frame.find('form:only-child:not([target])').submit();144 }145 }146 });147 });148}149});...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('wptdriver');2var webdriver = require('selenium-webdriver');3var driver = new webdriver.Builder().forBrowser('chrome').build();4driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');5driver.findElement(webdriver.By.name('btnG')).click();6driver.wait(function() {7 return driver.getTitle().then(function(title) {8 return title === 'webdriver - Google Search';9 });10}, 1000);11var frame = driver.findElement(webdriver.By.id('iframe'));12frame.findElement(webdriver.By.id('id1')).sendKeys('some text');13wptdriver.submitFrame(driver, frame);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('wptdriver');2 if (err) {3 console.log('Error submitting frame: ' + err);4 } else {5 console.log('Frame submitted');6 }7});8### wptdriver.init(options, callback)9* `host` - The hostname of the WebPagetest server (defaults to `localhost`)10* `port` - The port number of the WebPagetest server (defaults to `8888`)11* `key` - The API key for the WebPagetest server (defaults to `demo`)12#### callback(err)13### wptdriver.runTest(url, options, callback)14* `location` - The location to test from (defaults to `Dulles:Chrome`)15* `connectivity` - The connectivity profile to test under (defaults to `Cable`)16* `runs` - The number of runs to perform (defaults to `3`)17* `firstViewOnly` - Only run the test once (defaults to `false`)18* `pollResults` - Poll the results until the test is complete (defaults to `true`)19* `pollInterval` - The interval to poll the results (defaults to `5000`)20#### callback(err, data)21### wptdriver.submitFrame(url, frame, callback)22#### callback(err)23### wptdriver.getLocations(callback)24#### callback(err, data)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3var fs = require('fs');4var path = require('path');5var json = require('./test.json');6var jsonStr = JSON.stringify(json);7var jsonFile = path.resolve(__dirname, 'test.json');8client.submitFrame(url, jsonStr, function(err, data) {9 if (err) return console.error(err);10 console.log(data);11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt');2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var frame = document.getElementById('frame');2var url = frame.src;3var id = 1234;4var key = '1234';5var run = 1;6var cached = 0;7wpt.submitFrame(url, id, key, run, cached, frame);8### submitFrame (url, id, key, run, cached, frame, callback)9### submitFrame (url, id, key, run, cached, frame, callback, timeout)10* `timeout` - the amount of time (in ms) to wait before timing out the request11### submitFrame (url, id, key, run, cached, frame, callback, timeout, interval)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var webpagetest = new wpt('www.webpagetest.org');3var testId = '160502_XG_1b0a2f2c0d070b2e2b2a3b3c3d3e3f3f';4webpagetest.submitFrame(testId, 1, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('webpagetest');12var webpagetest = new wpt('www.webpagetest.org');13var testId = '160502_XG_1b0a2f2c0d070b2e2b2a3b3c3d3e3f3f';14webpagetest.getTestStatus(testId, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21var wpt = require('webpagetest');22var webpagetest = new wpt('www.webpagetest.org');23var testId = '160502_XG_1b0a2f2c0d070b2e2b2a3b3c3d3e3f3f';24webpagetest.getTestResults(testId, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31var wpt = require('webpagetest');32var webpagetest = new wpt('www.webpagetest.org');33var testId = '160502_XG_1b0a2f2c0d070b2e2b2a3b3c3d3e3f3f';34webpagetest.getTestResults(testId, {pagespeed: 1}, function(err, data) {35 if (err) {

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