How to use readAttribute method in Playwright Internal

Best JavaScript code snippet using playwright-internal

nested_record_complex.js

Source:nested_record_complex.js Github

copy

Full Screen

...62 testParent = null;63 store = null;64 }65});66test("Function: readAttribute() in the Parent Record",67function() {68 equals(testParent.readAttribute('name'), 'Parent Name', "readAttribute should be correct for name attribute");69 equals(testParent.readAttribute('nothing'), null, "readAttribute should be correct for invalid key");70 same(testParent.readAttribute('person'),71 {72 type: 'Person',73 name: 'Albert',74 address: {75 type: 'Address',76 street: '123 Sesame St',77 city: 'New York',78 state: 'NY'79 }80 },81 "readAttribute should be correct for 'person' child attribute");82});83test("Function: readAttribute() in the Parent > Child",84function() {85 var person = testParent.get('person');86 ok(person, "check to see if the first child in the chain exists");87 equals(person.readAttribute('name'), 'Albert', "child readAttribute should be correct for name attribute");88 equals(person.readAttribute('nothing'), null, "child readAttribute should be correct for invalid key");89 same(person.readAttribute('address'),90 {91 type: 'Address',92 street: '123 Sesame St',93 city: 'New York',94 state: 'NY'95 },96 "readAttribute should be correct for address on the child");97});98test("Function: readAttribute() in the Parent > Child > Child",99function() {100 var address = testParent.getPath('person.address');101 ok(address, "check to see if the child of the child in the chain exists with a getPath()");102 equals(address.readAttribute('street'), '123 Sesame St', "child readAttribute should be correct for street attribute w/ getPath()");103 equals(address.readAttribute('nothing'), null, "child readAttribute should be correct for invalid key w/ getPath()");104 // Test the individual gets105 var person = testParent.get('person');106 var address2 = person.get('address');107 ok(address2, "check to see if the child of the child in the chain exists with a get");108 equals(address2.readAttribute('street'), '123 Sesame St', "child readAttribute should be correct for street attribute w/ get()");109 equals(address2.readAttribute('nothing'), null, "child readAttribute should be correct for invalid key w/ get()");110});111test("Function: writeAttribute() in the Parent Record",112function() {113 testParent.writeAttribute('name', 'New Parent Name');114 equals(testParent.get('name'), 'New Parent Name', "writeAttribute should be the new name attribute");115 testParent.writeAttribute('nothing', 'nothing');116 equals(testParent.get('nothing'), 'nothing', "writeAttribute should be correct for new key");117 testParent.writeAttribute('person',118 {119 type: 'Person',120 name: 'Al Gore',121 address: {122 type: 'Address',123 street: '123 Crazy St',124 city: 'Khacki Pants',125 state: 'Insanity'126 }127 });128 same(testParent.readAttribute('person'),129 {130 type: 'Person',131 name: 'Al Gore',132 address: {133 type: 'Address',134 street: '123 Crazy St',135 city: 'Khacki Pants',136 state: 'Insanity'137 }138 },139 "writeAttribute with readAttribute should be correct for person child attribute");140});141test("Function: writeAttribute() in the Parent > Child",142function() {143 var person = testParent.get('person');144 person.writeAttribute('name', 'Luke Skywalker');145 equals(person.readAttribute('name'), 'Luke Skywalker', "writeAttribute should be the new name attribute on the child");146 var p = testParent.readAttribute('person');147 equals(p.name, 'Luke Skywalker', "check to see if a writeAttribute single change on the child will reflect on the parent");148 // check for a change on the child of the child149 var newAddress = {150 type: 'Address',151 street: '1 Way Street',152 city: 'Springfield',153 state: 'IL'154 };155 person.writeAttribute('address', newAddress);156 same(person.readAttribute('address'), {157 type: 'Address',158 street: '1 Way Street',159 city: 'Springfield',160 state: 'IL'161 }, "writeAttribute should be the new address attribute on the child");162 p = testParent.readAttribute('person');163 same(p.address, {164 type: 'Address',165 street: '1 Way Street',166 city: 'Springfield',167 state: 'IL'168 }, "check to see if a writeAttribute address change on the child will reflect on the parent");169});170test("Function: writeAttribute() in the Parent > Child > Child",171function() {172 var address = testParent.getPath('person.address');173 address.writeAttribute('street', '1 Death Star Lane');174 equals(address.readAttribute('street'), '1 Death Star Lane', "writeAttribute should be the new name attribute on the child.street");175 // Now, test the person176 var p = testParent.readAttribute('person');177 equals(p.address.street, '1 Death Star Lane', "check to see if a writeAttribute change on the child will reflect on the child > child.address.street");178 // now test the Parent record179 var parentAttrs = testParent.get('attributes');180 equals(parentAttrs.person.address.street, '1 Death Star Lane', "check to see if a writeAttribute change on the child will reflect on the child > child > parent.attributes.person.address.street");181});182test("Basic Read",183function() {184 // Test general gets185 equals(testParent.get('name'), 'Parent Name', "Parent.get() should be correct for name attribute");186 equals(testParent.get('nothing'), null, "Parent.get() should be correct for invalid key");187 // Test Child Record creation188 var p = testParent.get('person');189 // Check Model Class information190 ok(SC.kindOf(p, SC.Record), "(parent > child).get() creates an actual instance that is a kind of a SC.Record Object");191 ok(SC.instanceOf(p, NestedRecord.Person), "(parent > child).get() creates an actual instance of a Person Object");192 // Check reference information193 var pKey = p.get('id');194 var storeRef = store.find(NestedRecord.Person, pKey);195 ok(storeRef, 'checking that the store has the instance of the child record with proper primary key');196 equals(p, storeRef, "checking the parent reference is the same as the direct store reference");197 same(storeRef.get('attributes'), testParent.readAttribute('person'), "check that the ChildRecord's attributes are the same as the parent.person's readAttribute for the reference");198 var a = testParent.getPath('person.address');199 // Check Model Class information200 ok(SC.kindOf(a, SC.Record), "(parent > child > child) w/ getPath() creates an actual instance that is a kind of a SC.Record Object");201 ok(SC.instanceOf(a, NestedRecord.Address), "(parent > child > child) w/ getPath() creates an actual instance of an Address Object");202 // Check reference information203 var aKey = a.get('id');204 storeRef = store.find(NestedRecord.Address, aKey);205 ok(storeRef, 'checking that the store has the instance of the (parent > child > child) record with proper primary key');206 equals(a, storeRef, "checking the (parent > child > child) reference is the same as the direct store reference");207 same(storeRef.get('attributes'), p.readAttribute('address'), "check that the ChildRecord's attributes are the same as the (parent > child.address)'s readAttribute for the reference");208});209test("Basic Write",210function() {211 var oldP, p, key, oldKey, storeRef;212 var a, parentAttrs;213 // Test general gets214 testParent.set('name', 'New Parent Name');215 equals(testParent.get('name'), 'New Parent Name', "set() should change name attribute");216 testParent.set('nothing', 'nothing');217 equals(testParent.get('nothing'), 'nothing', "set should change non-existent property to a new property");218 // Test Child Record creation219 oldP = testParent.get('person');220 testParent.set('person', {221 type: 'Person',222 name: 'Al Gore',223 address: {224 type: 'Address',225 street: '123 Crazy St',226 city: 'Khacki Pants',227 state: 'Insanity'228 }229 });230 p = testParent.get('person');231 // Check Model Class information232 ok(SC.kindOf(p, SC.Record), "set() with an object creates an actual instance that is a kind of a SC.Record Object");233 ok(SC.instanceOf(p, NestedRecord.Person), "set() with an object creates an actual instance of a ChildRecordTest Object");234 // Check reference information235 key = p.get('id');236 storeRef = store.find(NestedRecord.Person, key);237 ok(storeRef, 'after a set() with an object, checking that the store has the instance of the child record with proper primary key');238 equals(p, storeRef, "after a set with an object, checking the parent reference is the same as the direct store reference");239 oldKey = oldP.get('id');240 ok((oldKey === key), 'check to see that the old child record has the same key as the new child record');241 // Check for changes on the child bubble to the parent.242 p.set('name', 'Child Name Change');243 equals(p.get('name'), 'Child Name Change', "after a set('name', <new>) on child, checking that the value is updated");244 ok(p.get('status') & SC.Record.DIRTY, 'check that the child record is dirty');245 ok(testParent.get('status') & SC.Record.DIRTY, 'check that the parent record is dirty');246 oldP = p;247 p = testParent.get('person');248 same(p, oldP, "after a set('name', <new>) on child, checking to see that the parent has received the changes from the child record");249 same(testParent.readAttribute('person'), p.get('attributes'), "after a set('name', <new>) on child, readAttribute on the parent should be correct for info child attributes");250 // Check changes on the address251 a = testParent.getPath('person.address');252 a.set('street', '321 Nutty Professor Lane');253 parentAttrs = testParent.readAttribute('person');254 same(a.get('attributes'), parentAttrs.address, "after a set('street', <new>) on address child, checking to see that the parent has received the changes from the child record");255});256test("Basic normalize()", function() {257 var pAttrs;258 testParent.set('person', {259 type: 'Person',260 name: 'Al Gore',261 address: {262 type: 'Address',263 street: '123 Crazy St',264 city: 'Khacki Pants'265 }266 });267 testParent.normalize();...

Full Screen

Full Screen

prototype.rails.js

Source:prototype.rails.js Github

copy

Full Screen

1Event.observe(document, 'dom:loaded', function() {2 function handle_remote(el, e){3 var data = null,4 method = el.readAttribute('method') || el.readAttribute('data-method') || 'GET',5 url = el.readAttribute('action') || el.readAttribute('data-url'),6 async = el.readAttribute('data-remote-type') === 'synchronous' ? false : true,7 update = el.readAttribute('data-update-success'),8 position = el.readAttribute('data-update-position');9 if (el.readAttribute('data-submit')) {10 var submit_el = $(el.readAttribute('data-submit'));11 if(submit_el !== undefined && submit_el.tagName.toUpperCase() === 'FORM'){12 data = submit_el.serialize();13 }14 } else if (el.readAttribute('data-with')) {15 // It seems there is a big inconsistency between what :with means depending on the element type16 // so this is going to look a bit crazy17 if(el.tagName.toUpperCase() === 'SCRIPT' && el.readAttribute('data-observed') !== null){18 // Handle observe_field and observe_form19 var observed_element = $(el.readAttribute('data-observed'));20 if(observed_element.tagName.toUpperCase() === 'FORM'){21 data = el.readAttribute('data-with') + '=' + observed_element.serialize();22 } else if(observed_element.tagName.toUpperCase() === 'INPUT' && observed_element.readAttribute('type').toUpperCase() !== "BUTTON" && observed_element.readAttribute('type').toUpperCase() !== "SUBMIT") {23 data = el.readAttribute('data-with') + '=' + observed_element.getValue();24 }25 } else {26 // Handle link_to and button_to27 data = evalAttribute(el, 'data-with');28 }29 } else if(el.tagName.toUpperCase() === 'FORM') {30 data = el.serialize();31 }32 document.fire('rails:before');33 if(url !== null){34 var request = new Ajax.Request(url, {35 method: method,36 asynchronous: async,37 parameters: data,38 evalJS: true,39 evalJSON: true,40 onComplete: function(xhr){41 document.fire('rails:complete', {xhr: xhr, element: el, submitted_button: getEventProperty(e, 'submitted_button')});42 },43 onLoading: function(xhr){44 document.fire('rails:after', {xhr: xhr, element: el});45 document.fire('rails:loading', {xhr: xhr, element: el});46 },47 onLoaded: function(xhr){48 document.fire('rails:loaded', {xhr: xhr, element: el});49 },50 onSuccess: function(xhr){51 document.fire('rails:success', {xhr: xhr, element: el});52 },53 onFailure: function(xhr){54 document.fire('rails:failure', {xhr: xhr, element: el});55 }56 });57 }58 }59 function setEventProperty(e, property, value){60 if(e.memo === undefined){61 e.memo = {};62 }63 e.memo[property] = value;64 }65 function getEventProperty(e, property){66 if(e !== null && e.memo !== undefined && e.memo[property] !== undefined){67 return e.memo[property];68 }69 }70 function confirmed(e, el){71 if(getEventProperty(e,'confirm_checked') !== true){72 setEventProperty(e, 'confirm_checked', true);73 el = Event.findElement(e, 'form') || el;74 var confirm_msg = el.readAttribute('data-confirm');75 if(confirm_msg !== null){76 var result = el.fire('rails:confirm', {confirm_msg: confirm_msg});77 if(result.memo.stop_event === true){78 Event.stop(e);79 return false;80 }81 }82 }83 return true;84 }85 function disable_button(el){86 var disable_with = el.readAttribute('data-disable-with'); 87 if(disable_with !== null){88 el.writeAttribute('data-enable-with', el.readAttribute('value'));89 el.writeAttribute('value', disable_with);90 el.writeAttribute('disabled', true);91 }92 }93 function enable_button(el){94 var enable_with = el.readAttribute('data-enable-with'); 95 if(enable_with !== null){96 el.writeAttribute('value', enable_with);97 }98 el.writeAttribute('disabled', false);99 }100 function updateHTML(el, content, result){101 var element_id = null;102 if(result === 'success'){103 element_id = el.readAttribute('data-update-success');104 } else if(result === 'failure'){105 element_id = el.readAttribute('data-update-failure');106 }107 var element_to_update = $(element_id);108 if(element_to_update !== null){109 var position = el.readAttribute('data-update-position');110 if(position !== null){111 var options = {};112 options[position] = content;113 element_to_update.insert(options);114 } else {115 element_to_update.update(content);116 }117 }118 }119 $$("script[data-periodical=true]").each(function(el){120 var executor = new PeriodicalExecuter(function() { handle_remote(el);}, el.readAttribute('data-frequency'));121 });122 $$("script[data-observe=true]").each(function(el){123 var observed_element = $(el.readAttribute('data-observed')),124 original_value = observed_element.tagName.toUpperCase() === 'FORM' ? observed_element.serialize() : observed_element.getValue(),125 callback = el.readAttribute('data-onobserve'),126 executor = new PeriodicalExecuter(function() { 127 value = observed_element.tagName.toUpperCase() === 'FORM' ? observed_element.serialize() : observed_element.getValue();128 if(original_value !== value){129 original_value = value;130 if(callback !== null){131 evalAttribute(el, 'onobserve');132 } else if(el.readAttribute('data-url') !== null){133 handle_remote(el);134 }135 }136 }, el.readAttribute('data-frequency'));137 });138 /**139 *140 * Event Listeners141 *142 * the original element is contained inside the event,143 * for some reason prototype wont let me listen for custom events on document144 * if the event wasn't fired on document145 *146 */147 Event.observe(document, 'submit', function (e) {148 var form = Event.findElement(e, 'form');149 // Make sure conditions and confirm have not already run150 if(form !== undefined && conditions_met(e, form) && confirmed(e, form)){151 var button = form.down('input[data-submitted=true]');152 button.writeAttribute('data-submitted', null);153 setEventProperty(e, 'submitted_button', button);154 disable_button(button);155 if(form.readAttribute('data-remote') === 'true'){156 Event.stop(e);157 handle_remote(form, e);158 }159 }160 });161 Event.observe(document, 'click', function (e) {162 var el = Event.findElement(e, 'a') || Event.findElement(e, 'input');163 if(el !== undefined && el.tagName.toUpperCase() === 'INPUT' && el.readAttribute('type').toUpperCase() === 'SUBMIT'){164 el.writeAttribute('data-submitted', 'true');165 166 // Submit is handled by submit event, don't continue on this path167 el = undefined;168 } else if(el !== undefined && el.tagName.toUpperCase() === 'INPUT' && el.readAttribute('type').toUpperCase() !== 'BUTTON'){169 // Make sure other inputs do not send this event170 el = undefined;171 }172 if(el !== undefined && conditions_met(e, el) && confirmed(e, el)){173 if(el.tagName.toUpperCase() === 'INPUT' && el.readAttribute('type').toUpperCase() === 'BUTTON'){174 disable_button(el);175 }176 if(el.readAttribute('data-remote') === 'true'){177 Event.stop(e);178 handle_remote(el, e);179 } else if(el.readAttribute('data-popup') !== null){180 Event.stop(e);181 document.fire('rails:popup', {element: el});182 }183 }184 });185 /**186 *187 * Default Event Handlers188 *189 */190 Event.observe(document, 'rails:confirm', function(e){191 setEventProperty(e, 'stop_event', !confirm(getEventProperty(e,'confirm_msg')));192 });193 Event.observe(document, 'rails:popup', function(e){194 var el = getEventProperty(e, 'element'),195 url = el.readAttribute('href') || el.readAttribute('data-url');196 197 if(el.readAttribute('data-popup') === true){198 window.open(url);199 } else {200 window.open(url, el.readAttribute('data-popup'));201 }202 });203 Event.observe(document, 'rails:complete', function(e){204 var el = getEventProperty(e, 'element');205 if(el.tagName.toUpperCase() === 'FORM'){206 var button = getEventProperty(e, 'submitted_button') ;207 enable_button(button);208 }209 });210 Event.observe(document, 'rails:success', function(e){211 var el = getEventProperty(e, 'element'),212 xhr = getEventProperty(e, 'xhr');213 if(xhr.responseText !== null){214 updateHTML(el, xhr.responseText, 'success');215 }216 });217 Event.observe(document, 'rails:failure', function(e){218 var el = getEventProperty(e, 'element'),219 xhr = getEventProperty(e, 'xhr');220 if(xhr.responseText !== null){221 updateHTML(el, xhr.responseText, 'failure');222 }223 });224 /**225 *226 * Rails 2.x Helpers / Event Handlers 227 *228 */229 function evalAttribute(el, attribute){230 var js = el.readAttribute('data-' + attribute);231 if(js){232 eval(js);233 }234 }235 function conditions_met(e, el){236 if(getEventProperty(e,'condition_checked') !== true){237 setEventProperty(e, 'condition_checked', true);238 el = Event.findElement(e, 'form') || el;239 var conditions = el.readAttribute('data-condition');240 if(conditions !== null){241 if(eval(conditions) === false){242 Event.stop(e);243 return false;244 }245 }246 }247 return true;248 }249 Event.observe(document, 'rails:success', function(e){250 evalAttribute(el, 'onsuccess');251 });252 Event.observe(document, 'rails:failure', function(e){253 evalAttribute(el, 'onfailure');254 });255 Event.observe(document, 'rails:complete', function(e){256 var el = getEventProperty(e, 'element');257 evalAttribute(el, 'oncomplete');258 evalAttribute(el, 'on' + getEventProperty('xhr', xhr.status)); 259 if(el.readAttribute('data-periodical') === 'true'){260 evalAttribute(el, 'onobserve');261 }262 });263 Event.observe(document, 'rails:loading', function(e){264 evalAttribute(el, 'onloading');265 });266 Event.observe(document, 'rails:loaded', function(e){267 evalAttribute(el, 'onloaded');268 });269 Event.observe(document, 'rails:before', function(e){270 evalAttribute(el, 'onbefore');271 });272 Event.observe(document, 'rails:after', function(e){273 evalAttribute(el, 'onafter');...

Full Screen

Full Screen

prototype_ujs.js

Source:prototype_ujs.js Github

copy

Full Screen

...3 onCreate: function(request) {4 var token = $$('meta[name=csrf-token]')[0];5 if (token) {6 if (!request.options.requestHeaders) request.options.requestHeaders = {};7 request.options.requestHeaders['X-CSRF-Token'] = token.readAttribute('content');8 }9 }10 });11 // Technique from Juriy Zaytsev12 // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/13 function isEventSupported(eventName) {14 var el = document.createElement('div');15 eventName = 'on' + eventName;16 var isSupported = (eventName in el);17 if (!isSupported) {18 el.setAttribute(eventName, 'return;');19 isSupported = typeof el[eventName] == 'function';20 }21 el = null;22 return isSupported;23 }24 function isForm(element) {25 return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM';26 }27 function isInput(element) {28 if (Object.isElement(element)) {29 var name = element.nodeName.toUpperCase();30 return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA';31 }32 else return false;33 }34 var submitBubbles = isEventSupported('submit'),35 changeBubbles = isEventSupported('change');36 if (!submitBubbles || !changeBubbles) {37 // augment the Event.Handler class to observe custom events when needed38 Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(39 function(init, element, eventName, selector, callback) {40 init(element, eventName, selector, callback);41 // is the handler being attached to an element that doesn't support this event?42 if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||43 (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {44 // "submit" => "emulated:submit"45 this.eventName = 'emulated:' + this.eventName;46 }47 }48 );49 }50 if (!submitBubbles) {51 // discover forms on the page by observing focus events which always bubble52 document.on('focusin', 'form', function(focusEvent, form) {53 // special handler for the real "submit" event (one-time operation)54 if (!form.retrieve('emulated:submit')) {55 form.on('submit', function(submitEvent) {56 var emulated = form.fire('emulated:submit', submitEvent, true);57 // if custom event received preventDefault, cancel the real one too58 if (emulated.returnValue === false) submitEvent.preventDefault();59 });60 form.store('emulated:submit', true);61 }62 });63 }64 if (!changeBubbles) {65 // discover form inputs on the page66 document.on('focusin', 'input, select, textarea', function(focusEvent, input) {67 // special handler for real "change" events68 if (!input.retrieve('emulated:change')) {69 input.on('change', function(changeEvent) {70 input.fire('emulated:change', changeEvent, true);71 });72 input.store('emulated:change', true);73 }74 });75 }76 function handleRemote(element) {77 var method, url, params;78 var event = element.fire("ajax:before");79 if (event.stopped) return false;80 if (element.tagName.toLowerCase() === 'form') {81 method = element.readAttribute('method') || 'post';82 url = element.readAttribute('action');83 // serialize the form with respect to the submit button that was pressed84 params = element.serialize({ submit: element.retrieve('rails:submit-button') });85 // clear the pressed submit button information86 element.store('rails:submit-button', null);87 } else {88 method = element.readAttribute('data-method') || 'get';89 url = element.readAttribute('href');90 params = {};91 }92 new Ajax.Request(url, {93 method: method,94 parameters: params,95 evalScripts: true,96 onCreate: function(response) { element.fire("ajax:create", response); },97 onComplete: function(response) { element.fire("ajax:complete", response); },98 onSuccess: function(response) { element.fire("ajax:success", response); },99 onFailure: function(response) { element.fire("ajax:failure", response); }100 });101 element.fire("ajax:after");102 }103 function insertHiddenField(form, name, value) {104 form.insert(new Element('input', { type: 'hidden', name: name, value: value }));105 }106 function handleMethod(element) {107 var method = element.readAttribute('data-method'),108 url = element.readAttribute('href'),109 csrf_param = $$('meta[name=csrf-param]')[0],110 csrf_token = $$('meta[name=csrf-token]')[0];111 var form = new Element('form', { method: "POST", action: url, style: "display: none;" });112 $(element.parentNode).insert(form);113 if (method !== 'post') {114 insertHiddenField(form, '_method', method);115 }116 if (csrf_param) {117 insertHiddenField(form, csrf_param.readAttribute('content'), csrf_token.readAttribute('content'));118 }119 form.submit();120 }121 function disableFormElements(form) {122 form.select('input[type=submit][data-disable-with]').each(function(input) {123 input.store('rails:original-value', input.getValue());124 input.setValue(input.readAttribute('data-disable-with')).disable();125 });126 }127 function enableFormElements(form) {128 form.select('input[type=submit][data-disable-with]').each(function(input) {129 input.setValue(input.retrieve('rails:original-value')).enable();130 });131 }132 function allowAction(element) {133 var message = element.readAttribute('data-confirm');134 return !message || confirm(message);135 }136 document.on('click', 'a[data-confirm], a[data-remote], a[data-method]', function(event, link) {137 if (!allowAction(link)) {138 event.stop();139 return false;140 }141 if (link.readAttribute('data-remote')) {142 handleRemote(link);143 event.stop();144 } else if (link.readAttribute('data-method')) {145 handleMethod(link);146 event.stop();147 }148 });149 document.on("click", "form input[type=submit], form button[type=submit], form button:not([type])", function(event, button) {150 // register the pressed submit button151 event.findElement('form').store('rails:submit-button', button.name || false);152 });153 document.on("submit", function(event) {154 var form = event.findElement();155 if (!allowAction(form)) {156 event.stop();157 return false;158 }159 if (form.readAttribute('data-remote')) {160 handleRemote(form);161 event.stop();162 } else {163 disableFormElements(form);164 }165 });166 document.on('ajax:create', 'form', function(event, form) {167 if (form == event.findElement()) disableFormElements(form);168 });169 document.on('ajax:complete', 'form', function(event, form) {170 if (form == event.findElement()) enableFormElements(form);171 });...

Full Screen

Full Screen

associations.js

Source:associations.js Github

copy

Full Screen

...4 $$(".firstSelect").each(function(elem){5 elem.writeAttribute('ref',counter);6 buffer[counter] = []7 elem.childElements().each(function(e){8 buffer[counter].push([e.innerHTML,e.readAttribute('value')])9 })10 counter += 1;11 })12 $$(".searchMany").each(function(elem){13 Event.observe(elem,'keyup',function(e){14 var select = elem.parentNode.parentNode.childElements()[2].childElements()[0];15 var aux = []16 var ref = select.readAttribute('ref')17 var text = e.target.value.toLowerCase();18 buffer[ref].each(function(ev){19 if(ev[0].toLowerCase().indexOf(text)!=-1){20 aux.push(ev)21 }22 })23 select.childElements().each(function(ev){24 ev.remove();25 })26 aux.each(function(ev){27 var option = new Element('option',{"value":ev[1]}).update(ev[0])28 select.insert({bottom:option});29 })30 })31 })32 $$(".addAssoc").each(function(elem){33 var assocName = elem.parentNode.parentNode.childElements()[4].childElements()[0].readAttribute('name');34 Event.observe(elem,'click',function(e){35 var parentDiv = e.findElement('a').parentNode.parentNode;36 var hiddenFields = parentDiv.childElements()[4];37 var select = parentDiv.childElements()[2].childElements()[0];38 var select_two = parentDiv.childElements()[2].childElements()[3]39 var counter = select.readAttribute("ref");40 select.childElements().each(function(ev){41 if(ev.selected == true){42 var option = new Element('option',{"value":ev.readAttribute('value')}).update(ev.innerHTML)43 select_two.insert({bottom:option});44 ev.remove()45 var hidden = new Element('input',{"name":assocName,"type":"hidden","value":ev.readAttribute('value')})46 hiddenFields.insert({bottom:hidden});47 }48 })49 buffer[counter] = []50 select.childElements().each(function(e){51 buffer[counter].push([e.innerHTML,e.readAttribute('value')])52 })53 })54 })55 $$(".removeAssoc").each(function(elem){56 var assocName = elem.parentNode.parentNode.childElements()[4].childElements()[0].readAttribute('name');57 Event.observe(elem,'click',function(e){58 var parentDiv = e.findElement('a').parentNode.parentNode;59 var hiddenFields = parentDiv.childElements()[4];60 var select = parentDiv.childElements()[2].childElements()[0];61 var select_two = parentDiv.childElements()[2].childElements()[3]62 var counter = select.readAttribute("ref");63 select_two.childElements().each(function(ev){64 if(ev.selected == true){65 var option = new Element('option',{"value":ev.readAttribute('value')}).update(ev.innerHTML)66 select.insert({bottom:option});67 ev.remove()68 hiddenFields.childElements().each(function(o){69 var hiddenValue = o.value;70 if(hiddenValue==ev.readAttribute('value')){71 o.remove()72 }73 })74 if (!hiddenFields.childElements().length) {75 var dummyField = new Element('input', {"type": "hidden", "name": assocName})76 hiddenFields.insert({bottom: dummyField});77 }78 }79 })80 buffer[counter] = []81 select.childElements().each(function(e){82 buffer[counter].push([e.innerHTML,e.readAttribute('value')])83 })84 })85 })86 $$(".addAllAssoc").each(function(elem){87 var assocName = elem.parentNode.parentNode.childElements()[4].childElements()[0].readAttribute('name');88 Event.observe(elem,'click',function(e){89 var parentDiv = e.findElement('a').parentNode.parentNode;90 var hiddenFields = parentDiv.childElements()[4];91 var select = parentDiv.childElements()[2].childElements()[0];92 var select_two = parentDiv.childElements()[2].childElements()[3]93 select.childElements().each(function(ev){94 var option = new Element('option',{"value":ev.readAttribute('value')}).update(ev.innerHTML)95 select_two.insert({bottom:option});96 ev.remove()97 var hidden = new Element('input',{"name":assocName,"type":"hidden","value":ev.readAttribute('value')})98 hiddenFields.insert({bottom:hidden});99 })100 var counter = select.readAttribute("ref");101 buffer[counter] = []102 })103 })104 $$(".clearAssoc").each(function(elem){105 var assocName = elem.parentNode.parentNode.childElements()[4].childElements()[0].readAttribute('name');106 Event.observe(elem,'click',function(e){107 var parentDiv = e.findElement('a').parentNode.parentNode;108 var hiddenFields = parentDiv.childElements()[4];109 var select = parentDiv.childElements()[2].childElements()[0];110 var select_two = parentDiv.childElements()[2].childElements()[3]111 select_two.childElements().each(function(ev){112 var option = new Element('option',{"value":ev.readAttribute('value')}).update(ev.innerHTML)113 select.insert({bottom:option});114 ev.remove()115 })116 hiddenFields.childElements().each(function(ev){117 ev.remove();118 });119 if (!hiddenFields.childElements().length) {120 var dummyField = new Element('input', {"type": "hidden", "name": assocName})121 hiddenFields.insert({bottom: dummyField});122 }123 var counter = select.readAttribute("ref");124 buffer[counter] = []125 select.childElements().each(function(e){126 buffer[counter].push([e.innerHTML,e.readAttribute('value')])127 })128 })129 })130 $$(".searchMany").each(function(elem){131 Event.observe(elem,'focus',function(e){132 var used = e.target.readAttribute('used');133 if(used=="0"){134 e.target.setStyle({color:"#000"});135 e.target.writeAttribute('used','1');136 e.target.value = ""137 }138 })139 Event.observe(elem,'blur',function(e){140 var text = e.target.value;141 var used = e.target.readAttribute('used');142 var assoc = e.target.readAttribute('ref');143 if(text.length == 0){144 e.target.setStyle({color:"#AAA"});145 e.target.writeAttribute('used','0');146 e.target.value = "Search " + assoc147 }148 })149 })...

Full Screen

Full Screen

rails.js

Source:rails.js Github

copy

Full Screen

1document.observe("dom:loaded", function() {2 var authToken = $$('meta[name=csrf-token]').first().readAttribute('content'),3 authParam = $$('meta[name=csrf-param]').first().readAttribute('content'),4 formTemplate = '<form method="#{method}" action="#{action}">\5 #{realmethod}<input name="#{param}" value="#{token}" type="hidden">\6 </form>',7 realmethodTemplate = '<input name="_method" value="#{method}" type="hidden">';8 function handleRemote(element) {9 var method, url, params;10 if (element.tagName.toLowerCase() == 'form') {11 method = element.readAttribute('method') || 'post';12 url = element.readAttribute('action');13 params = element.serialize(true);14 } else {15 method = element.readAttribute('data-method') || 'get';16 // TODO: data-url support is going away, just use href17 url = element.readAttribute('data-url') || element.readAttribute('href');18 params = {};19 }20 var event = element.fire("ajax:before");21 if (event.stopped) return false;22 new Ajax.Request(url, {23 method: method,24 parameters: params,25 asynchronous: true,26 evalScripts: true,27 onLoading: function(request) { element.fire("ajax:loading", {request: request}); },28 onLoaded: function(request) { element.fire("ajax:loaded", {request: request}); },29 onInteractive: function(request) { element.fire("ajax:interactive", {request: request}); },30 onComplete: function(request) { element.fire("ajax:complete", {request: request}); },31 onSuccess: function(request) { element.fire("ajax:success", {request: request}); },32 onFailure: function(request) { element.fire("ajax:failure", {request: request}); }33 });34 element.fire("ajax:after");35 }36 $(document.body).observe("click", function(event) {37 var message = event.element().readAttribute('data-confirm');38 if (message && !confirm(message)) {39 event.stop();40 return false;41 }42 var element = event.findElement("a[data-remote=true]");43 if (element) {44 handleRemote(element);45 event.stop();46 }47 var element = event.findElement("a[data-method]");48 if (element && element.readAttribute('data-remote') != 'true') {49 var method = element.readAttribute('data-method'),50 piggyback = method.toLowerCase() != 'post',51 formHTML = formTemplate.interpolate({52 method: 'POST',53 realmethod: piggyback ? realmethodTemplate.interpolate({ method: method }) : '',54 action: element.readAttribute('href'),55 token: authToken,56 param: authParam57 });58 var form = new Element('div').update(formHTML).down().hide();59 this.insert({ bottom: form });60 form.submit();61 event.stop();62 }63 });64 // TODO: I don't think submit bubbles in IE65 $(document.body).observe("submit", function(event) {66 var message = event.element().readAttribute('data-confirm');67 if (message && !confirm(message)) {68 event.stop();69 return false;70 }71 var inputs = event.element().select("input[type=submit][data-disable-with]");72 inputs.each(function(input) {73 input.disabled = true;74 input.writeAttribute('data-original-value', input.value);75 input.value = input.readAttribute('data-disable-with');76 });77 var element = event.findElement("form[data-remote=true]");78 if (element) {79 handleRemote(element);80 event.stop();81 }82 });83 $(document.body).observe("ajax:complete", function(event) {84 var element = event.element();85 if (element.tagName.toLowerCase() == 'form') {86 var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");87 inputs.each(function(input) {88 input.value = input.readAttribute('data-original-value');89 input.writeAttribute('data-original-value', null);90 input.disabled = false;91 });92 }93 });...

Full Screen

Full Screen

code_favorites.js

Source:code_favorites.js Github

copy

Full Screen

...13 var pre_element = link_element.up(".dp-highlighter").next();14 var parameters = undefined;15 if(pre_element.hasAttribute("code_favorite_id")){16 parameters = {17 "code_favorite[id]": pre_element.readAttribute("code_favorite_id")18 }19 }else{20 var language = pre_element.readAttribute("class");21 language = (!language || language == "data_info")?pre_element.readAttribute("language"):language;22 var pre_index = pre_element.readAttribute("pre_index") || link_element.up(".dp-highlighter").readAttribute("pre_index");23 parameters = {24 'code_favorite[source_url]': pre_element.readAttribute("source_url"),25 'code_favorite[page_title]': pre_element.readAttribute("title"),26 'code_favorite[language]': language,27 'code_favorite[codeable_id]': pre_element.readAttribute("codeable_id"),28 'code_favorite[codeable_type]': pre_element.readAttribute("codeable_type"),29 'code_favorite[code_index]': pre_index30 };}31 link_element.down('.star').hide();32 link_element.down('.spinner').show();33 new Ajax.Request('/admin/code/new_xhr', {34 method: 'post',35 parameters: parameters,36 onSuccess: function(response){37 $(document.getElementsByTagName('body')[0]).insert({38 bottom:response.responseText39 });40 link_element.down('.spinner').hide();41 link_element.down('.star').show();42 }...

Full Screen

Full Screen

wiki.js

Source:wiki.js Github

copy

Full Screen

...4 for (var i=0; i < anchors.length; i++){5 var anchor = anchors[i];6 var openInNewWindow = false;7 //set interwiki and externallink link to open in new window 8 if (Element.readAttribute(anchor, "class")) {9 if (Element.readAttribute(anchor, "class") == "externallink") {10 if(Element.readAttribute(anchor,"href").indexOf("mailto:") != -1) {11 anchor.setAttribute("class", "b_link_mailto");12 openInNewWindow = false;13 } else {14 openInNewWindow = true;15 }16 }17 if (Element.readAttribute(anchor, "class") == "interwiki") openInNewWindow = true;18 }19 //open media links in new window, but only if file exists20 if (Element.readAttribute(anchor, "title")) {21 var href = Element.readAttribute(anchor,"href");22 if (!Element.readAttribute(anchor, "class") && Element.readAttribute(anchor, "title").indexOf("Media") != -1) { //normal media link file found23 openInNewWindow = true;24 //modify link to non ajax mode as opening in new window with ajax mode on fails25 if (href.indexOf(":1/") != -1) {26 var pre = href.substr(0, href.indexOf(":1/"));27 var post = href.substr(href.indexOf(":1/")+3, href.length);28 anchor.setAttribute("href", pre+":0/"+post);29 }30 } else if (Element.readAttribute(anchor, "class") == "edit" && Element.readAttribute(anchor, "title").indexOf("Media:") != -1) { //media file not found31 href = href.substr(0, href.indexOf("Edit:topic"));32 href = href+"Upload";33 anchor.setAttribute("href", href);34 }35 }36 if (openInNewWindow) anchor.target = "_blank";37 }...

Full Screen

Full Screen

toggle.js

Source:toggle.js Github

copy

Full Screen

...12 }13}14function toggle_diff(dom_id) {15 e = $(dom_id)16 if (! e.readAttribute("loaded")) {17 e.update(dispatch({controller: 'diff', action: 'diff', revision: e.readAttribute("rev"), git_path: e.readAttribute("git_path"), path: (e.readAttribute("path") || ""), layout: false}))18 e.setAttribute("loaded");19 }20 21 set_togglable_visibility( dom_id, ! e.visible() );22}23function toggle_log(dom_id) {24 e = $(dom_id)25 if (! e.readAttribute("loaded")) {26 e.update(dispatch({controller: 'log', action: 'log', revisions: e.readAttribute("revisions"), git_path: e.readAttribute("git_path"), path: (e.readAttribute("path") || ""), layout: false}))27 // e.setAttribute("loaded");28 }29 30 set_togglable_visibility( dom_id, ! e.visible() );...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const searchInput = await page.$('input[name="q"]');7 const value = await searchInput.evaluate(element => element.readAttribute('name'));8 console.log(value);9 await browser.close();10})();11const {chromium} = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 const searchInput = await page.$('input[name="q"]');17 await searchInput.evaluate(element => element.writeAttribute('name', 'search'));18 await page.screenshot({path: 'google.png'});19 await browser.close();20})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const input = await page.$('input[name="q"]');7 const value = await input.getAttribute('value');8 console.log(value);9 await browser.close();10})();11const { chromium } = require('playwright');12const { GooglePage } = require('./page-objects/google-page');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const googlePage = new GooglePage(page);18 await googlePage.goto();19 await googlePage.search('playwright');20 await browser.close();21})();22class GooglePage {23 constructor(page) {24 this.page = page;25 }26 async goto() {27 }28 async search(value) {29 const input = await this.page.$('input[name="q"]');30 await input.type(value);31 await input.press('Enter');32 }33}34class GooglePage {35 constructor(page) {36 this.page = page;37 }38 async goto() {39 }40 async search(value) {41 const input = await this.page.$('input[name="q"]');42 await input.type(value);43 await input.press('Enter');44 }45}46const { chromium } = require('playwright');47(async () => {48 const browser = await chromium.launch();49 const context = await browser.newContext();50 const page = await context.newPage();51 const input = await page.$('input[name="q"]');52 const value = await input.getAttribute('value');53 console.log(value);54 await browser.close();55})();56const { chromium } = require('playwright');57const { GooglePage } = require('./page-objects/google-page');58(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({path: `google.png`});7 const title = await page.title();8 console.log(title);9 await browser.close();10})();11const playwright = require('playwright');12(async () => {13 const browser = await playwright.chromium.launch({headless: false});14 const context = await browser.newContext();15 const page = await context.newPage();16 await page.screenshot({path: `google.png`});17 const title = await page.title();18 console.log(title);19 await browser.close();20})();21const playwright = require('playwright');22(async () => {23 const browser = await playwright.chromium.launch({headless: false});24 const context = await browser.newContext();25 const page = await context.newPage();26 await page.screenshot({path: `google.png`});27 const title = await page.title();28 console.log(title);29 await browser.close();30})();31const playwright = require('playwright');32(async () => {33 const browser = await playwright.chromium.launch({headless: false});34 const context = await browser.newContext();35 const page = await context.newPage();36 await page.screenshot({path: `google.png`});37 const title = await page.title();38 console.log(title);39 await browser.close();40})();41const playwright = require('playwright');42(async () => {43 const browser = await playwright.chromium.launch({headless: false});44 const context = await browser.newContext();45 const page = await context.newPage();46 await page.screenshot({path: `google.png`});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 const searchField = await page.$('input[name="q"]');7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch({ headless: false });12 const context = await browser.newContext();13 const page = await context.newPage();14 const searchField = await page.$('input[name="q"]');15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch({ headless: false });20 const context = await browser.newContext();21 const page = await context.newPage();22 const searchField = await page.$('input[name="q"]');23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch({ headless: false });28 const context = await browser.newContext();29 const page = await context.newPage();30 const searchField = await page.$('input[name="q"]');31 await browser.close();32})();33const { chromium } = require('playwright');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const href = await page.evaluate(() => document.querySelector('text=Get started').href);6 console.log(href);7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { readAttributes } = require('playwright');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const content = await readAttributes(page, 'css=nav');8 console.log(content);9 await browser.close();10})();11[ { 'aria-label': 'Playwright' },12 { 'aria-label': 'Docs' },13 { 'aria-label': 'Examples' },14 { 'aria-label': 'Blog' },15 { 'aria-label': 'GitHub' } ]

Full Screen

Using AI Code Generation

copy

Full Screen

1const { readAttribute } = require('playwright-core/lib/server/dom');2const { chromium } = require('playwright-core');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const handle = await page.$('h1');8 const value = await readAttribute(handle, 'textContent');9 console.log(value);10 await browser.close();11})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { readAttribute } = require('playwright/lib/protocol/protocol');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('text=Get started');8 console.log(await readAttribute(element, 'href'));9 await browser.close();10})();11import { chromium } from 'playwright';12import { readAttribute } from 'playwright/lib/protocol/protocol';13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const element = await page.$('text=Get started');18 console.log(await readAttribute(element, 'href'));19 await browser.close();20})();21const { chromium } = require('playwright');22const { readAttribute } = require('playwright/lib/protocol/protocol');23(async () => {24 const browser = await chromium.launch();25 const context = await browser.newContext();26 const page = await context.newPage();27 const element = await page.$('text=Get started');28 console.log(await readAttribute(element, 'href'));29 await browser.close();30})();31import { chromium } from 'playwright';32import { readAttribute } from 'playwright/lib/protocol/protocol';33(async () => {34 const browser = await chromium.launch();35 const context = await browser.newContext();36 const page = await context.newPage();37 const element = await page.$('text=Get started');38 console.log(await readAttribute(element, 'href'));39 await browser.close();40})();41const { chromium } = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const attributeValue = await page.$eval('input[name="q"]', (element) => element.readAttribute('name'));7 console.log(attributeValue);8 await browser.close();9})();

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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