Best JavaScript code snippet using cypress
jquery.js
Source:jquery.js
...258 // don't support it.259 if ( nodeName( elem, "template" ) ) {260 elem = elem.content || elem;261 }262 return jQuery.merge( [], elem.childNodes );263 }264}, function (name, fn) {265 const guaranteedUnique = {266 children: true,267 contents: true,268 next: true,269 prev: true270 }271 const rparentsprev = /^(?:parents|prev(?:Until|All))/272 jquery.fn[name] = function (until, selector) {273 let result = jquery.map(this, fn, until)274 if (name.slice(-5) !== 'Until') {275 selector = until276 }277 if (selector && typeof selector === 'string') {278 result = jquery.filter(selector, result)279 }280 if (this.length > 1) {281 if (!guaranteedUnique[name]) {282 jquery.uniqueSort(result)283 }284 if (rparentsprev.test(name)) {285 result.reverse()286 }287 }288 return this.pushStack(result)289 }290})291if (typeof Symbol === 'function') {292 jquery.fn[Symbol.iterator] = [][Symbol.iterator]293}294jquery.each('Boolean Number String Function Array Date RegExp Object Error Symbol'.split(' '), function (index, name) {295 class2type[`[object ${name}]`] = name.toLowerCase()296})297function sibling (cur, dir) {298 while((cur = cur[dir]) && cur.nodeType !== 1) {}299 return cur300}301function siblings (n, elem) {302 const result = []303 for (;n; n = n.nextSibling) {304 if (n.nodeType === 1 && n !== elem) {305 result.push(n)306 }307 }308 return result309}310function dir (elem, dir, until) {311 const matched = []312 const truncate = until !== undefined313 while((elem = elem[dir]) && elem.nodeType !== 9) {314 if (elem.nodeType === 1) {315 if (truncate && jquery(elem).is(until)) {316 break317 }318 matched.push(elem)319 }320 }321 return matched322}323function flat (array) {324 return [].flat ? [].flat.call(array) : [].concat.apply([], array)325}326function DOMEval (code, node, doc) {327 const doc = doc || window.document328 const script = document.createElement('script')329 script.text =code330 const scriptDefaultAttributes = {331 type: true,332 src: true,333 nonce: true,334 noModule: true335 }336 for (let i in scriptDefaultAttributes) {337 const value = node[i] || node.getAttribute || node.getAttribute(i)338 if (value) {339 script.setAttribute(i, value)340 }341 }342 doc.head.appendChild(script).parentNode.removeChild(script)343}344jquery.fn.extend({345 has (target) {346 target = jquery(target, this)347 return this.filter(function () {348 for (let i = 0; i < target.length; i++) {349 if (jquery.contains(this, target[i])) {350 return true351 }352 }353 })354 },355 356 index: function( elem ) {357 // No argument, return index in parent358 if ( !elem ) {359 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;360 }361 // Index in selector362 if ( typeof elem === "string" ) {363 return indexOf.call( jQuery( elem ), this[ 0 ] );364 }365 // Locate the position of the desired element366 return indexOf.call( this,367 // If it receives a jQuery object, the first element is used368 elem.jquery ? elem[ 0 ] : elem369 );370 },371 add: function( selector, context ) {372 return this.pushStack(373 jQuery.uniqueSort(374 jQuery.merge( this.get(), jQuery( selector, context ) )375 )376 );377 },378 addBack: function( selector ) {379 return this.add( selector == null ?380 this.prevObject : this.prevObject.filter( selector )381 );382 }383})384function isWindow (obj) {385 return obj != null && obj === obj.window386}387function isFunction (obj) {388 return typeof obj === 'function' && typeof obj.nodeType !== 'number'...
webp.js
Source:webp.js
1/**2 * webpæ件3 * è°ç¨æ¹å¼1ï¼4 * $.webp();5 * å¤çææçæ lsrc å±æ§ï¼ä¸lsrcå±æ§çç®å½ä¸å
å« images ç®å½çæ ç¾ã6 * å¦ææ¯imgæ ç¾ï¼åèµå¼srcå±æ§ï¼å
¶ä»ç±»åçæ ç¾ä¿®æ¹background-imageå±æ§ã7 *8 * è°ç¨æ¹å¼2:9 * $('.p3').webp({10 * origSrc: "lsrc", // ç¨äºåæ¾å¾çåæ件å°åï¼png,jpg,jpeg,gif)çæ ç¾å±æ§11 * origDir: "images",// å¾çåæä»¶æ ¹ç®å½ï¼ä¼æ¿æ¢ä¸ºwebpçæ ¹ç®å½12 * webpDir: "webps"// å¾çåwebpæ件ç®å½13 *14 }); * æ¥æ¾å¤ç.page.p3 è¿ä¸ªdomèç¹ä¸æææ lsrc å±æ§ï¼ ä¸lsrcå±æ§çç®å½ä¸å
å« images ç®å½çæ ç¾ã15 * å¤çè¿ç¨åä¸ã16 *17 * 注æï¼ç±äºéç¨lsrcçå½¢å¼ï¼æ以imgæ ç¾ä¸è¦è®¾å®srcå±æ§ï¼é²æ¢éå¤å è½½ã18 * 对äºè®¾ç½®äºèæ¯å¾ççæ ç¾ï¼è¯·å°cssä¸çbackground-imageåç¬æåºæ¥æ³¨éæã19 */20(function(window, $) {21 let __supportwebp = false;22 let __checked = false;23 let supportWebp = function(callback) {24 if (__checked) {25 callback();26 return;27 }28 (function() {29 let webp = new Image();30 webp.onload = webp.onerror = function() {31 __checked = true;32 __supportwebp = webp.height === 2;33 webp.onload = webp.onerror = null;34 webp = null;35 callback();36 };37 //é«åº¦ä¸º2çä¸ä¸ªwebpå¾ç38 webp.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';39 })();40 };41 $.fn.webp = function(options) {42 let elements = this;43 let settings = {44 origSrc: "lsrc",45 origDir: "",46 webpDir: ""47 };48 /**49 * å
对elementsè¿è¡å¤çï¼æ¾å°æ以å
å« origSrc çåå
ç´ ã50 */51 function adjust() {52 let _elements;53 elements.each(function() {54 let $this = $(this),55 _tmp;56 if (settings.skip_invisible && !$this.is(":visible")) {57 return;58 }59 let original = $this.attr(settings.origSrc);60 // å¦æå½å对象没æorigSrcå±æ§ï¼åæ¶å½å对象ä¸æ¯å¾çèç¹ï¼61 // åæ¥æ¾åèç¹ä¸æorigSrcå±æ§çèç¹ï¼è¿è¡webpå¤ç62 if (!original) {63 _tmp = $this.find("[" + settings.origSrc + "*=" + settings.origDir + "]");64 } else {65 _tmp = $this;66 }67 if (_elements && _elements.length > 0) {68 if ($.merge) { // jquery merge69 _elements = $.merge(_elements, _tmp);70 } else { // zepto merge71 _elements.concat(_tmp);72 }73 } else {74 _elements = _tmp;75 }76 });77 elements = _elements;78 }79 adjust();80 function update() {81 elements.each(function() {82 $(this).trigger("appear");83 });84 }85 if (options) {86 $.extend(settings, options);87 }88 if (options.origDir && !options.webpDir) {89 throw new Error('option webpDir undefined!');90 }91 elements.each(function() {92 let self = this;93 let $self = $(self);94 self.loaded = false;95 /* 触åappearäºä»¶æ¶ï¼æ§å¶æ¿æ¢æç´æ¥æ¾ç¤ºåå¾ç */96 $self.one("appear", function() {97 if (!this.loaded) {98 let original = $self.attr(settings.origSrc);99 // æ¿æ¢webpç®å½åå¾çåç¼100 if (__supportwebp) {101 original = original102 .replace(settings.origDir, settings.webpDir)103 .replace(/\.(jpg|png|jpeg|gif)$/ig, '.webp');104 }105 $("<img />")106 .bind("load", function() {107 if ($self.is("img")) {108 // å¦æå½åèç¹æ¯å¾çï¼åèµå¼srcå±æ§109 $self.attr("src", original);110 } else {111 // å¦æå½åèç¹ä¸æ¯å¾çï¼åèµå¼background-imageå±æ§112 $self.css("background-image", "url('" + original + "')");113 }114 self.loaded = true;115 /* Remove image from array so it is not looped next time. */116 var temp = $.grep(elements, function(element) {117 return !element.loaded;118 });119 elements = $(temp);120 })121 .attr("src", original);122 }123 });124 });125 supportWebp(function(){126 update();127 });128 return this;129 };130 $.extend($, {131 webp: function(options) {132 $(document).ready(function() {133 $(document).webp(options);134 });135 }136 });...
webpack.config.js
Source:webpack.config.js
1/* Webpack Configuration2===================================================================================================================== */3// Load Core:4const path = require('path');5const webpack = require('webpack');6// Load Plugins:7const CleanPlugin = require('clean-webpack-plugin');8const UglifyJsPlugin = require('uglifyjs-webpack-plugin');9const ExtractTextPlugin = require('extract-text-webpack-plugin');10// Define Base:11const BASE = '/resources/vendor/silverware/userforms';12// Define Paths:13const PATHS = {14 MODULE: {15 SRC: path.resolve(__dirname, 'client/src'),16 DIST: path.resolve(__dirname, 'client/dist'),17 PUBLIC: BASE + '/client/dist/'18 },19 MODULES: path.resolve(__dirname, 'node_modules')20};21// Define Configs:22const CONFIGS = [23 {24 paths: PATHS.MODULE,25 entry: {26 'bundle': 'bundles/bundle.js'27 },28 resolve: {29 alias: {30 'bootstrap': path.resolve(process.env.PWD, '../../../themes/silverware-theme/node_modules/bootstrap'),31 'silverware-theme': path.resolve(process.env.PWD, '../../../themes/silverware-theme/source')32 }33 }34 }35];36// Define Rules:37const rules = (env) => {38 39 // Answer Rules:40 41 return [42 {43 test: /\.js$/,44 use: [45 {46 loader: 'babel-loader'47 }48 ],49 exclude: [50 PATHS.MODULES51 ]52 },53 {54 test: /\.css$/,55 use: style(env)56 },57 {58 test: /\.scss$/,59 use: style(env, [60 {61 loader: 'resolve-url-loader',62 options: {63 sourceMap: true64 }65 },66 {67 loader: 'sass-loader',68 options: {69 sourceMap: true70 }71 }72 ])73 },74 {75 test: /\.(gif|jpg|png)$/,76 use: [77 {78 loader: 'url-loader',79 options: {80 name: 'images/[name].[ext]',81 limit: 1000082 }83 }84 ]85 },86 {87 test: /\.svg$/,88 use: [89 {90 loader: 'file-loader',91 options: {92 name: 'svg/[name].[ext]'93 }94 },95 {96 loader: 'svgo-loader',97 options: {98 plugins: [99 { removeTitle: true },100 { convertColors: { shorthex: false } },101 { convertPathData: true }102 ]103 }104 }105 ]106 },107 {108 test: /\.(ttf|eot|woff|woff2)$/,109 loader: 'file-loader',110 options: {111 name: 'fonts/[name].[ext]'112 }113 }114 ];115 116};117// Define Style Loaders:118const style = (env, extra = []) => {119 120 // Common Loaders:121 122 let loaders = [123 {124 loader: 'css-loader',125 options: {126 sourceMap: true127 }128 },129 {130 loader: 'postcss-loader',131 options: {132 config: {133 path: path.resolve(__dirname, 'postcss.config.js')134 },135 sourceMap: true136 }137 }138 ];139 140 // Merge Loaders:141 142 loaders = [...loaders, ...extra];143 144 // Answer Loaders:145 146 return (env === 'production') ? ExtractTextPlugin.extract({147 fallback: 'style-loader',148 use: loaders149 }) : [{ loader: 'style-loader' }].concat(loaders);150 151};152// Define Devtool:153const devtool = (env) => {154 return (env === 'production') ? false : 'source-map';155};156// Define Plugins:157const plugins = (env, config) => {158 159 // Common Plugins:160 161 let plugins = [162 new webpack.ProvidePlugin({163 $: 'jquery',164 jQuery: 'jquery'165 })166 ];167 168 // Merge Plugins:169 170 if (config.plugins) {171 plugins = [...plugins, ...config.plugins];172 }173 174 // Answer Plugins:175 176 return plugins.concat(177 (env === 'production') ? [178 new CleanPlugin(179 [ config.paths.DIST ]180 ),181 new ExtractTextPlugin({182 filename: 'styles/[name].css',183 allChunks: true184 }),185 new UglifyJsPlugin({186 uglifyOptions: {187 output: {188 comments: false189 }190 }191 })192 ] : [193 194 ]195 );196 197};198// Define Resolve:199const resolve = (env, config) => {200 201 let resolve = {202 modules: [203 config.paths.SRC,204 PATHS.MODULES205 ]206 };207 208 if (config.resolve) {209 Object.assign(resolve, config.resolve);210 }211 212 return resolve;213 214};215// Define Externals:216const externals = (env, config) => {217 218 let externals = {219 jquery: 'jQuery'220 };221 222 if (config.externals) {223 Object.assign(externals, config.externals);224 }225 226 return externals;227 228};229// Define Configuration:230const config = (env, configs) => {231 232 // Define Exports:233 234 let exports = [];235 236 // Iterate Configs:237 238 for (let config of configs) {239 240 // Build Export:241 242 exports.push({243 entry: config.entry,244 output: {245 path: config.paths.DIST,246 filename: 'js/[name].js',247 publicPath: config.paths.PUBLIC248 },249 module: {250 rules: rules(env)251 },252 devtool: devtool(env),253 plugins: plugins(env, config),254 resolve: resolve(env, config),255 externals: externals(env, config)256 });257 258 }259 260 // Answer Exports:261 262 return exports;263 264};265// Define Module Exports:266module.exports = (env = {}) => {267 process.env.NODE_ENV = env.production ? 'production' : 'development';268 console.log(`Running in ${process.env.NODE_ENV} mode...`);269 return config(process.env.NODE_ENV, CONFIGS);...
utils.js
Source:utils.js
1/**2 * Copyright (c) Yohei Sasaki <yssk22@gmail.com>3 * MIT Licensed4 */5var path = require('path'),6 fs = require('fs');7var $ = require('jquery');8/**9 * Merge the objects into the first argument.10 *11 * @api private12 */13exports.merge = function merge(){14 return $.extend.apply($, arguments);15};16/**17 * Clone the object. This is the deep copy implementation18 *19 * @param {Object} obj20 * @api private21 */22exports.clone = function clone(obj){23 if( obj === null || obj === undefined ){24 return obj;25 }else{26 if( typeof(obj) == 'object' ){27 if( Array.isArray(obj) ){28 return $.extend.call($, true, [], obj);29 }else{30 return $.extend.call($, true, {}, obj);31 }32 }else{33 // not a object.34 return obj;35 }36 }37};38/**39 * Returns abstract path40 *41 * @param {String} p path42 * @return {String} abstract path43 */44exports.abspath = function abspath(p){45 return p.indexOf('/') == 0 ? p : path.join(process.cwd(), p);46};47/**48 * Bind the context with the given target object.49 *50 * @param {Object} target object bound with.51 * @param {Object} context context object.52 * @param {Function} callback the callback function which receives (err, bound) arguments.53 *54 *55 */56exports.bindContext = function bindContext(target, context, callback){57 var type = typeof(target);58 if( typeof(context) == 'function' ){59 callback = context;60 context = {};61 }62 if( target == null ){ // null or undefined63 callback(null, target);64 }else if( type == 'object' ){ // object or array65 // Array or Object66 target = exports.clone(target);67 var wait = 0;68 var cb = function(err){69 wait -= 1;70 if( wait == 0 ){71 callback(err, target);72 }73 };74 for(var i in target){75 if( target.hasOwnProperty(i) ){76 wait += 1;77 (function(k){78 process.nextTick(function(){79 bindContext(target[k], context, function(err, result){80 if( result === undefined ){81 delete(target[k]);82 }else{83 target[k] = result;84 }85 cb(err);86 });87 });88 })(i);89 }90 }91 }else if( type == 'function' ){ // Function92 target.call(context, callback);93 }else{ // Number, String, or boolean94 callback(null, target);95 }96};97var log4js = undefined;98exports.logConfigure = function(fileSystem, standardOutput, configPaths){99 log4js = require('log4js')(fileSystem, standardOutput, configPaths);100 return log4js;101}102/**103 * Returns the logger.104 * This function is an wrapper for log4js to reduce dependencies.105 *106 * @param {String} name logger category name.107 * @return {Object} logger instance108 * @api public109 */110exports.getLogger = function getLogger(name){111 if( log4js == undefined ){112 log4js = require('log4js')();113 }114 return log4js.getLogger(name || "sunrise");115};116/**117 * Load JSON file from the given filepath.118 *119 * @param {String} filepath path to json file.120 * @param {Function} callback121 * @api public122 */123exports.loadJSON = function(filepath, callback){124 fs.readFile(path, function(err, data){125 if( err ){126 callback(e);127 }else{128 try{129 callback(null, JSON.parse(data));130 }catch(e){131 callback(e);132 }133 }134 });135};136/**137 * Synchronized version of loadJSON138 */139exports.loadJSONSync = function(filepath){140 var obj = JSON.parse(fs.readFileSync(filepath));141 return obj;142};143/**144 * Parallel executions for function list.145 */146exports.parallel = function(){147 var args = Array.prototype.slice.call(arguments);148 var callback = args.pop();149 var remains = args.length;150 if( callback == undefined || remains < 1 ){151 throw new TypeError('one or more functions must be passed to `parallel`');152 }153 args.forEach(function(f){154 process.nextTick(function(){155 f(function(){156 remains--;157 if( remains == 0 ){158 callback();159 }160 });161 });162 });...
objectWidget.js
Source:objectWidget.js
1define([2 'bluebird',3 'jquery',4 '../../merge'5], function (6 Promise,7 $,8 merge9) {10 'use strict';11 class ObjectWidgetAdapter {12 constructor(config) {13 if (!config.runtime) {14 throw {15 type: 'ArgumentError',16 reason: 'RuntimeMissing',17 message: 'The runtime factory construction property is required but not provided'18 };19 }20 this.runtime = config.runtime;21 this.module = config.widgetDef.module;22 this.initConfig = new merge.ShallowMerger({}).mergeIn(config.initConfig).value();23 this.widget = null;24 this.hostNode = null;25 this.container = null;26 }27 init(config) {28 return new Promise((resolve, reject) => {29 require([this.module],30 (Widget) => {31 if (!Widget) {32 reject(new Error('Widget module did not load properly (undefined) for ' + this.module));33 return;34 }35 // NB we save the config, because the internal widget36 // unfortunately requires the container in init, and37 // that is not available until attach...38 // or does it?? and how many of these are there? ...39 this.initConfig = new merge.DeepMerger(this.initConfig).mergeIn(config).value();40 this.widget = Object.create(Widget);41 resolve();42 },43 (error) => {44 reject(error);45 });46 });47 }48 attach(node) {49 this.hostNode = node;50 this.container = this.hostNode.appendChild(document.createElement('div'));51 }52 start(params) {53 return Promise.try(() => {54 // The config is supplied by the caller, but we add55 // standard properties here.56 /* TODO: be more generic */57 // But then again, a widget constructed on this model does58 // not need a connector!59 // not the best .. perhaps merge the params into the config60 // better yet, rewrite the widgets in the new model...61 //var widgetConfig = config.widgetDef || params || {};62 //_.extend(widgetConfig, initConfig);63 var widgetConfig = new merge.ShallowMerger(this.initConfig).mergeIn({64 container: $(this.container),65 // userId: this.runtime.getService('session').getUsername(),66 runtime: this.runtime,67 params: params68 }).value();69 return this.widget.init(widgetConfig);70 })71 .then(()=> {72 // go????73 return this.widget.go();74 });75 }76 stop() {77 // noop78 }79 detach() {80 if (this.hostNode && this.container) {81 this.hostNode.removeChild(this.container);82 }83 }84 destroy() {85 // no method on the object widget to call.86 }87 }88 return {ObjectWidgetAdapter};...
nbga-1.0.js
Source:nbga-1.0.js
1/**2 * nbga.js - Non-Blocking Google Analytics3 * http://925html.com/code/non-blocking-google-analytics-integration/4 * 5 * Copyright (c) 2008 Eric Ferraiuolo - http://eric.ferraiuolo.name6 * MIT License - http://www.opensource.org/licenses/mit-license.php7 * 8 * @version 1.09 */10function ga( adapter ){11 12 // Private13 14 var _adapters, _defaults, _config, _initialized;15 16 _adapters = {17 18 yui3 : {19 merge : function( defaults, options ) {20 var result;21 YUI().use('object', function(Y){22 result = Y.merge( defaults, options );23 });24 return result;25 },26 getScript : function( url, callback ) {27 YUI().use('get', function(Y){28 Y.Get.script( url, { onSuccess : callback } );29 });30 }31 },32 33 yui2 : {34 merge : function( defaults, options ) {35 return YAHOO.lang.merge( defaults, options );36 },37 getScript : function( url, callback ) {38 YAHOO.util.Get.script( url, { onSuccess : callback } );39 }40 },41 42 jquery : {43 merge : function( defaults, options ) {44 return jQuery.extend( {}, defaults, options );45 },46 getScript : function( url, callback ) {47 jQuery.getScript( url, callback );48 }49 }50 51 };52 53 if ( typeof adapter !== 'undefined' ) {54 adapter = adapter;55 } else if ( typeof YUI !== 'undefined' ) {56 adapter = _adapters.yui3;57 } else if ( typeof YAHOO !== 'undefined' ) {58 adapter = _adapters.yui2;59 } else if ( typeof jQuery !== 'undefined' ) {60 adapter = _adapters.jquery;61 }62 63 _defaults = {64 url: {65 http: 'http://www.google-analytics.com/ga.js',66 https: 'https://ssl.google-analytics.com/ga.js'67 }68 };69 _config = null;70 _initialized = false;71 72 function init() {73 var isSecure, gaURL;74 75 isSecure = (document.location.protocol == 'https:');76 gaURL = (isSecure && _config.url.https) ? (_config.url.https || _config.url)77 : (_config.url.http || _config.url);78 79 adapter.getScript( gaURL, function(){80 _config.tracker = _gat._getTracker( _config.id );81 _initialized = true;82 while ( _config.queue.length > 0 )83 Public.track( _config.queue.shift() );84 } );85 }86 87 // Public88 89 var Public = {90 91 config: function( options ) {92 options = adapter.merge( _defaults, (options || {}) );93 if ( !_config && options.id ) {94 _config = options;95 _config.queue = [];96 init();97 }98 return this;99 },100 101 track: function( url ) {102 if ( _initialized ) {103 if ( url )104 _config.tracker._trackPageview( url );105 else106 _config.tracker._trackPageview();107 } else if ( _config ) {108 _config.queue.push( url || null );109 }110 return this;111 }112 113 };114 return Public;115 ...
main.js
Source:main.js
1define(['Core', 'jquery', 'jsclass'], function (Core, jquery) {2 'use strict';3 var adapter = {},4 AbstactRteAdapter = new JS.Class({5 initialize: function (config) {6 this.config = config;7 this.editor = null;8 this.isEnabled = false;9 },10 onInit: function () {11 Core.exception('PluginException', '85000', "AbstactRteAdapterException:onInit - Not implemented yet");12 },13 applyToContent: function () {14 Core.exception('PluginException', '85001', "AbstactRteAdapterException:applyToContent - Not implemented yet!");15 },16 triggerOnReady: function () {17 var params = ['rte:rteAdapter:isReady'],18 args = Array.prototype.slice.call(arguments);19 jquery.merge(params, args);20 Core.Mediator.publish.apply(Core.Mediator, params);21 },22 triggerOnEdit: function (data) {23 Core.Mediator.publish('rte:rteAdapter:editedContent', data);24 },25 getEditor: function () {26 return this.editor;27 },28 enable: function () {29 this.isEnabled = true;30 },31 disable: function () {32 this.isEnabled = false;33 }34 });35 return {36 createAdapter: function (adapterName, def) {37 def.getName = (function () {38 return function () {39 return adapterName;40 };41 }(adapterName));42 adapter = new JS.Class(AbstactRteAdapter, def);43 return adapter;44 },45 use: function (adapter) {46 require(['rteadapter!' + adapter]);47 }48 };...
Using AI Code Generation
1describe('Cypress', () => {2 it('is working', () => {3 expect(true).to.equal(true)4 })5 it('can visit a site', () => {6 })7})8describe('Cypress', () => {9 it('is working', () => {10 expect(true).to.equal(true)11 })12 it('can visit a site', () => {13 })14})15describe('Cypress', () => {16 it('is working', () => {17 expect(true).to.equal(true)18 })19 it('can visit a site', () => {20 })21})22describe('Cypress', () => {23 it('is working', () => {24 expect(true).to.equal(true)25 })26 it('can visit a site', () => {27 })28})29describe('Cypress', () => {30 it('is working', () => {31 expect(true).to.equal(true)32 })33 it('can visit a site', () => {34 })35})36describe('Cypress', () => {37 it('is working', () => {38 expect(true).to.equal(true)39 })40 it('can visit a site', () => {41 })42})43 expect(true).to.equal(true)44 expect(true).to.equal(true)
Using AI Code Generation
1var arr1 = [1, 2, 3, 4, 5];2var arr2 = [6, 7, 8, 9, 10];3var arr3 = Cypress._.merge(arr1, arr2);4console.log(arr3);5var arr1 = [1, 2, 3, 4, 5];6var arr2 = [6, 7, 8, 9, 10];7var arr3 = Cypress._.merge(arr1, arr2);8console.log(arr3);9var arr1 = [1, 2, 3, 4, 5];10var arr2 = [6, 7, 8, 9, 10];11var arr3 = Cypress._.merge(arr1, arr2);12console.log(arr3);13var arr1 = [1, 2, 3, 4, 5];14var arr2 = [6, 7, 8, 9, 10];15var arr3 = Cypress._.merge(arr1, arr2);16console.log(arr3);17var arr1 = [1, 2, 3, 4, 5];18var arr2 = [6, 7, 8, 9, 10];
Using AI Code Generation
1it('test', function() {2 var arr1 = [1, 2, 3, 4];3 var arr2 = [5, 6, 7, 8];4 var arr3 = [];5 var arr4 = [];6 arr3 = Cypress.$.merge(arr1, arr2);7 arr4 = jQuery.merge(arr1, arr2);8 expect(arr3).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8]);9 expect(arr4).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8]);10});11Cypress.Commands.add('addJQuery', () => {12 cy.window().then(win => {13 let script = win.document.createElement('script');14 script.onload = () => {15 win.jQuery = win.$ = Cypress.$;16 };17 win.document.body.appendChild(script);18 });19});20describe('Test', function() {21 it('test', function() {22 cy.addJQuery();23 cy.get('.query-list').then($el => {24 var arr1 = [1, 2, 3, 4];25 var arr2 = [5, 6, 7, 8];26 var arr3 = [];27 var arr4 = [];28 arr3 = Cypress.$.merge(arr1, arr2);29 arr4 = jQuery.merge(arr1, arr2);30 expect(arr3).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8]);31 expect(arr4).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8]);32 });33 });34});35{36}37import './commands';
Using AI Code Generation
1describe('Merge method', function() {2 it('Merges two arrays', function() {3 let array5 = jQuery.merge(array1, array2)4 let array6 = jQuery.merge(array3, array4)5 let array7 = jQuery.merge(array5, array6)6 cy.log(array1)7 cy.log(array2)8 cy.log(array3)9 cy.log(array4)10 cy.log(array5)11 cy.log(array6)12 cy.log(array7)13 })14})15jQuery.merge() method of Cypress16jQuery.merge(first, second)
Using AI Code Generation
1beforeEach(() => {2})3it('does not do much!', () => {4 cy.get('.query-list')5 .find('li')6 .contains('apples')7 .should('have.class', 'third')8 cy.get('.query-list')9 .find('li')10 .contains('oranges')11 .should('have.class', 'third')12 cy.get('.query-list')13 .find('li')14 .contains('bananas')15 .should('have.class', 'third')16})17beforeEach(() => {18})19it('does not do much!', () => {20 cy.get('.query-list')21 .find('li')22 .contains('apples')23 .should('have.class', 'third')24 cy.get('.query-list')25 .find('li')26 .contains('oranges')27 .should('have.class', 'third')28 cy.get('.query-list')29 .find('li')30 .contains('bananas')31 .should('have.class', 'third')32})33beforeEach(() => {34})35it('does not do much!', () => {36 cy.get('.query-list')37 .find('li')38 .contains('apples')39 .should('have.class', 'third')40 cy.get('.query-list')41 .find('li')42 .contains('oranges')43 .should('have.class', 'third')44 cy.get('.query-list')45 .find('li')46 .contains('bananas')47 .should('have.class', 'third')48})49beforeEach(() => {50})51it('does not do much!', () => {52 cy.get('.query-list')53 .find('li')54 .contains('apples')55 .should('have.class', 'third')56 cy.get('.query-list')57 .find('li')58 .contains('oranges')59 .should('have.class', 'third')60 cy.get('.query-list')61 .find('li
Using AI Code Generation
1describe("test", function () {2 it("test", function () {3 cy.get("input[type=text]").type("test");4 cy.get("input[type=text]").type("test");5 cy.get("input[type=text]").then(($input) => {6 let input = $input;7 cy.get("input[type=text]").then(($input1) => {8 let input1 = $input1;9 cy.get("input[type=text]").then(($input2) => {10 let input2 = $input2;11 cy.get("input[type=text]").then(($input3) => {12 let input3 = $input3;13 cy.get("input[type=text]").then(($input4) => {14 let input4 = $input4;15 cy.get("input[type=text]").then(($input5) => {16 let input5 = $input5;17 cy.get("input[type=text]").then(($input6) => {18 let input6 = $input6;19 cy.get("input[type=text]").then(($input7) => {20 let input7 = $input7;21 cy.get("input[type=text]").then(($input8) => {22 let input8 = $input8;23 cy.get("input[type=text]").then(($input9) => {24 let input9 = $input9;25 cy.get("input[type=text]").then(($input10) => {26 let input10 = $input10;27 cy.get("input[type=text]").then(($input11) => {28 let input11 = $input11;29 cy.get("input[type=text]").then(($input12) => {30 let input12 = $input12;31 cy.get("input[type=text]").then(($input13) => {32 let input13 = $input13;33 cy.get("input[type=text]").then(($input14) => {34 let input14 = $input14;35 cy.get("input[type=text]").then(($input15) => {36 let input15 = $input15;37 cy.get("input[type=text]").then(($input16) => {38 let input16 = $input16;39 cy.get("input[type=text]").then(($input17) => {40 let input17 = $input17;41 cy.get("input[type=text]").then(($input18
Using AI Code Generation
1const firstArray = [1, 2, 3, 4, 5];2const secondArray = [6, 7, 8, 9, 10];3const mergedArray = Cypress.$.merge(firstArray, secondArray);4console.log(mergedArray);5const array = [1, 2, 3, 4, 5];6const queryString = Cypress.$.param(array);7console.log(queryString);8const array = [1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9];9const uniqueArray = Cypress.$.unique(array);10console.log(uniqueArray);11const string = ' This is a string ';12const trimmedString = Cypress.$.trim(string);13console.log(trimmedString);14const object = {name: 'John', age: 20};15const type = Cypress.$.type(object);16console.log(type);
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.get('input[name="q"]').type('Cypress')4 cy.get('input[name="btnK"]').click()5 cy.get('div[class="g"]').should('have.length', 10)6 var arr3 = Cypress.$.merge(arr1, arr2)7 expect(Cypress.$.inArray(3, arr3)).to.be.greaterThan(-1)8 expect(Cypress.$.inArray(11, arr3)).to.be.equal(-1)9 })10})11{12 "env": {13 }14}15{16 "scripts": {17 },18 "devDependencies": {19 }20}21 * @type {Cypress.PluginConfig}22module.exports = (on, config) => {23}24Cypress.Commands.add('login', () => {25 cy.visit('/login')26 cy.get('input[name="username"]').type(Cypress.env('test_user'))27 cy.get('input[name="password"]').type(Cypress
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!