Best JavaScript code snippet using chromeless
tests.js
Source:tests.js  
1/*2 *3 * Licensed to the Apache Software Foundation (ASF) under one4 * or more contributor license agreements.  See the NOTICE file5 * distributed with this work for additional information6 * regarding copyright ownership.  The ASF licenses this file7 * to you under the Apache License, Version 2.0 (the8 * "License"); you may not use this file except in compliance9 * with the License.  You may obtain a copy of the License at10 *11 *   http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing,14 * software distributed under the License is distributed on an15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY16 * KIND, either express or implied.  See the License for the17 * specific language governing permissions and limitations18 * under the License.19 *20 */21/* jshint jasmine: true */22/* global WinJS */23exports.defineAutoTests = function () {24    var isWindowsStore = (cordova.platformId == "windows8") || (cordova.platformId == "windows" && !WinJS.Utilities.isPhone),25        onEvent;26    describe('Battery (navigator.battery)', function () {27        it("battery.spec.1 should exist", function () {28            if (isWindowsStore) {29                pending('Battery status is not supported on windows store');30            }31            expect(navigator.battery).toBeDefined();32        });33    });34    describe('Battery Events', function () {35        describe("batterystatus", function () {36            afterEach(function () {37                if (!isWindowsStore) {38                    try {39                        window.removeEventListener("batterystatus", onEvent, false);40                    }41                    catch (e) {42                        console.err('Error removing batterystatus event listener: ' + e);43                    }44                }45            });46            it("battery.spec.2 should fire batterystatus events", function (done) {47                if (isWindowsStore) {48                    pending('Battery status is not supported on windows store');49                }50                onEvent = jasmine.createSpy("BatteryStatus");51                // batterystatus -> 3052                window.addEventListener("batterystatus", onEvent, false);53                navigator.battery._status({54                    level: 30,55                    isPlugged: false56                });57                setTimeout(function () {58                    expect(onEvent).toHaveBeenCalled();59                    done();60                }, 100);61            });62        });63        describe("batterylow", function () {64            afterEach(function () {65                if (!isWindowsStore) {66                    try {67                        window.removeEventListener("batterylow", onEvent, false);68                    }69                    catch (e) {70                        console.err('Error removing batterylow event listener: ' + e);71                    }72                }73            });74            it("battery.spec.3 should fire batterylow event (30 -> 20)", function (done) {75                if (isWindowsStore) {76                    pending('Battery status is not supported on windows store');77                }78                onEvent = jasmine.createSpy("BatteryLow");79                // batterylow 30 -> 2080                window.addEventListener("batterylow", onEvent, false);81                navigator.battery._status({82                    level : 30,83                    isPlugged : false84                });85                navigator.battery._status({86                    level : 20,87                    isPlugged : false88                });89                setTimeout(function () {90                    expect(onEvent).toHaveBeenCalled();91                    done();92                }, 100);93            });94            it("battery.spec.3.1 should fire batterylow event (30 -> 19)", function (done) {95                if (isWindowsStore) {96                    pending('Battery status is not supported on windows store');97                }98                onEvent = jasmine.createSpy("BatteryLow");99                // batterylow 30 -> 19100                window.addEventListener("batterylow", onEvent, false);101                navigator.battery._status({102                    level : 30,103                    isPlugged : false104                });105                navigator.battery._status({106                    level : 19,107                    isPlugged : false108                });109                setTimeout(function () {110                    expect(onEvent).toHaveBeenCalled();111                    done();112                }, 100);113            });114            it("battery.spec.3.2 should not fire batterylow event (5 -> 20)", function (done) {115                if (isWindowsStore) {116                    pending('Battery status is not supported on windows store');117                }118                onEvent = jasmine.createSpy("BatteryLow");119                // batterylow should not fire when level increases (5->20) ( CB-4519 )120                window.addEventListener("batterylow", onEvent, false);121                navigator.battery._status({122                    level : 5,123                    isPlugged : false124                });125                navigator.battery._status({126                    level: 20,127                    isPlugged: false128                });129                setTimeout(function () {130                    expect(onEvent).not.toHaveBeenCalled();131                    done();132                }, 100);133            });134            it("battery.spec.3.3 batterylow event(21 -> 20) should not fire if charging", function (done) {135                if (isWindowsStore) {136                    pending('Battery status is not supported on windows store');137                }138                onEvent = jasmine.createSpy("BatteryLow");139                // batterylow should NOT fire if we are charging   ( CB-4520 )140                window.addEventListener("batterylow", onEvent, false);141                navigator.battery._status({142                    level : 21,143                    isPlugged : true144                });145                navigator.battery._status({146                    level : 20,147                    isPlugged : true148                });149                setTimeout(function () {150                    expect(onEvent).not.toHaveBeenCalled();151                    done();152                }, 100);153            });154        });155        describe("batterycritical", function () {156            afterEach(function () {157                if (!isWindowsStore) {158                    try {159                        window.removeEventListener("batterycritical", onEvent, false);160                    }161                    catch (e) {162                        console.err('Error removing batterycritical event listener: ' + e);163                    }164                }165            });166            it("battery.spec.4 should fire batterycritical event (19 -> 5)", function (done) {167                if (isWindowsStore) {168                    pending('Battery status is not supported on windows store');169                }170                onEvent = jasmine.createSpy("BatteryCritical");171                // batterycritical 19->5172                window.addEventListener("batterycritical", onEvent, false);173                navigator.battery._status({174                    level: 19,175                    isPlugged: false176                });177                navigator.battery._status({178                    level: 5,179                    isPlugged: false180                });181                setTimeout(function () {182                    expect(onEvent).toHaveBeenCalled();183                    done();184                }, 100);185            });186            it("battery.spec.4.1 should fire batterycritical event (19 -> 4)", function (done) {187                if (isWindowsStore) {188                    pending('Battery status is not supported on windows store');189                }190                onEvent = jasmine.createSpy("BatteryCritical");191                // batterycritical 19->4192                window.addEventListener("batterycritical", onEvent, false);193                navigator.battery._status({194                    level: 19,195                    isPlugged: false196                });197                navigator.battery._status({198                    level: 4,199                    isPlugged: false200                });201                setTimeout(function () {202                    expect(onEvent).toHaveBeenCalled();203                    done();204                }, 100);205            });206            it("battery.spec.4.2 should fire batterycritical event (100 -> 4) when decreases", function (done) {207                if (isWindowsStore) {208                    pending('Battery status is not supported on windows store');209                }210                onEvent = jasmine.createSpy("BatteryCritical");211                // setup: batterycritical should fire when level decreases (100->4) ( CB-4519 )212                window.addEventListener("batterycritical", onEvent, false);213                navigator.battery._status({214                    level: 100,215                    isPlugged: false216                });217                navigator.battery._status({218                    level: 4,219                    isPlugged: false220                });221                setTimeout(function () {222                    expect(onEvent).toHaveBeenCalled();223                    done();224                }, 100);225            });226            it("battery.spec.4.3 should not fire batterycritical event (4 -> 5) when increasing", function (done) {227                if (isWindowsStore) {228                    pending('Battery status is not supported on windows store');229                }230                onEvent = jasmine.createSpy("BatteryCritical");231                window.addEventListener("batterycritical", onEvent, false);232                // batterycritical should not fire when level increases (4->5)( CB-4519 )233                navigator.battery._status({234                    level: 4,235                    isPlugged: false236                });237                navigator.battery._status({238                    level: 5,239                    isPlugged: false240                });241                setTimeout(function () {242                    expect(onEvent.calls.count()).toBeLessThan(2);243                    done();244                }, 100);245            });246            it("battery.spec.4.4 should not fire batterycritical event (6 -> 5) if charging", function (done) {247                if (isWindowsStore) {248                    pending('Battery status is not supported on windows store');249                }250                onEvent = jasmine.createSpy("BatteryCritical");251                window.addEventListener("batterycritical", onEvent, false);252                // batterycritical should NOT fire if we are charging   ( CB-4520 )253                navigator.battery._status({254                    level: 6,255                    isPlugged: true256                });257                navigator.battery._status({258                    level: 5,259                    isPlugged: true260                });261                setTimeout(function () {262                    expect(onEvent).not.toHaveBeenCalled();263                    done();264                }, 100);265            });266        });267    });268};269//******************************************************************************************270//***************************************Manual Tests***************************************271//******************************************************************************************272exports.defineManualTests = function (contentEl, createActionButton) {273    /* Battery */274    function updateInfo(info) {275        document.getElementById('levelValue').innerText = info.level;276        document.getElementById('pluggedValue').innerText = info.isPlugged;277        if (info.level > 5) {278            document.getElementById('criticalValue').innerText = "false";279        }280        if (info.level > 20) {281            document.getElementById('lowValue').innerText = "false";282        }283    }284    function batteryLow(info) {285        document.getElementById('lowValue').innerText = "true";286    }287    function batteryCritical(info) {288        document.getElementById('criticalValue').innerText = "true";289    }290    function addBattery() {291        window.addEventListener("batterystatus", updateInfo, false);292    }293    function removeBattery() {294        window.removeEventListener("batterystatus", updateInfo, false);295    }296    function addLow() {297        window.addEventListener("batterylow", batteryLow, false);298    }299    function removeLow() {300        window.removeEventListener("batterylow", batteryLow, false);301    }302    function addCritical() {303        window.addEventListener("batterycritical", batteryCritical, false);304    }305    function removeCritical() {306        window.removeEventListener("batterycritical", batteryCritical, false);307    }308    //Generate Dynamic Table309    function generateTable(tableId, rows, cells, elements) {310        var table = document.createElement('table');311        for (var r = 0; r < rows; r++) {312            var row = table.insertRow(r);313            for (var c = 0; c < cells; c++) {314                var cell = row.insertCell(c);315                cell.setAttribute("align", "center");316                for (var e in elements) {317                    if (elements[e].position.row == r && elements[e].position.cell == c) {318                        var htmlElement = document.createElement(elements[e].tag);319                        var content;320                        if (elements[e].content !== "") {321                            content = document.createTextNode(elements[e].content);322                            htmlElement.appendChild(content);323                        }324                        if (elements[e].type) {325                            htmlElement.type = elements[e].type;326                        }327                        htmlElement.setAttribute("id", elements[e].id);328                        cell.appendChild(htmlElement);329                    }330                }331            }332        }333        table.setAttribute("align", "center");334        table.setAttribute("id", tableId);335        return table;336    }337    // Battery Elements338    var batteryElements =339        [{340            id : "statusTag",341            content : "Status:",342            tag : "div",343            position : {344                row : 0,345                cell : 0346            }347        }, {348            id : "statusValue",349            content : "",350            tag : "div",351            position : {352                row : 0,353                cell : 1354            }355        }, {356            id : "levelTag",357            content : "Level:",358            tag : "div",359            position : {360                row : 1,361                cell : 0362            }363        }, {364            id : "levelValue",365            content : "",366            tag : "div",367            position : {368                row : 1,369                cell : 1370            }371        }, {372            id : "pluggedTag",373            content : "Plugged:",374            tag : "div",375            position : {376                row : 2,377                cell : 0378            }379        }, {380            id : "pluggedValue",381            content : "",382            tag : "div",383            position : {384                row : 2,385                cell : 1386            }387        }, {388            id : "lowTag",389            content : "Low:",390            tag : "div",391            position : {392                row : 3,393                cell : 0394            }395        }, {396            id : "lowValue",397            content : "",398            tag : "div",399            position : {400                row : 3,401                cell : 1402            }403        }, {404            id : "criticalTag",405            content : "Critical:",406            tag : "div",407            position : {408                row : 4,409                cell : 0410            }411        }, {412            id : "criticalValue",413            content : "",414            tag : "div",415            position : {416                row : 4,417                cell : 1418            }419        }420    ];421    //Title audio results422    var div = document.createElement('h2');423    div.appendChild(document.createTextNode('Battery Status'));424    div.setAttribute("align", "center");425    contentEl.appendChild(div);426    var batteryTable = generateTable('info', 5, 3, batteryElements);427    contentEl.appendChild(batteryTable);428    div = document.createElement('h2');429    div.appendChild(document.createTextNode('Actions'));430    div.setAttribute("align", "center");431    contentEl.appendChild(div);432    contentEl.innerHTML += '<h3>Battery Status Tests</h3>' +433        'Will update values for level and plugged when they change. If battery low and critical values are false, they will get updated in status box, but only once' +434        '<div id="addBS"></div><div id="remBs"></div>' +435        '<h3>Battery Low Tests</h3>' +436        '</p> Will update value for battery low to true when battery is below 20%' +437        '<div id="addBl"></div><div id="remBl"></div>' +438        '<h3>Battery Critical Tests</h3>' +439        '</p> Will update value for battery critical to true when battery is below 5%' +440        '<div id="addBc"></div><div id="remBc"></div>';441    createActionButton('Add "batterystatus" listener', function () {442        addBattery();443    }, 'addBS');444    createActionButton('Remove "batterystatus" listener', function () {445        removeBattery();446    }, 'remBs');447    createActionButton('Add "batterylow" listener', function () {448        addLow();449    }, 'addBl');450    createActionButton('Remove "batterylow" listener', function () {451        removeLow();452    }, 'remBl');453    createActionButton('Add "batterycritical" listener', function () {454        addCritical();455    }, 'addBc');456    createActionButton('Remove "batterycritical" listener', function () {457        removeCritical();458    }, 'remBc');...souce.js
Source:souce.js  
...15hideElement("rate_l");16hideElement("rate_s");17hideElement("hide_log");18hideElement("crop_nonsuit");19onEvent("A.I.", "click", function( ) {20  setScreen("A.I_1");21});22onEvent("tips_ai", "click", function( ) {23  setScreen("Tips");24});25onEvent("find_ai", "click", function( ) {26  if (getText("drop_ai") == "Rice") {27  if (getText("month_sowing") == "Januray") {28    showElement("crop_nonsuit");29  }30  if (getText("month_sowing") == "Feburary") {31    showElement("crop_nonsuit");32  }33  if (getText("month_sowing") == "March") {34    showElement("crop_nonsuit");35  }36  if (getText("month_sowing") == "April") {37    showElement("crop_nonsuit");38  }39  if (getText("month_sowing") == "May") {40    showElement("crop_nonsuit");41  }42  if (getText("month_sowing") == "June") {43    if (getText("rate_sqm") > "8") {44      onEvent("find_ai", "click", function( ) {45        showElement("loss_ai");46        showElement("tips_ai");47      });48    }49  }50  if (getText("month_sowing") == "July") {51    if ("8" < getText("rate_sqm")) {52      showElement("profit_ai");53    }54  }55  if (getText("month_sowing") == "August") {56    showElement("crop_nonsuit");57  }58  if (getText("month_sowing") == "September") {59    showElement("crop_nonsuit");60  }61  if (getText("month_sowing") == "October") {62    showElement("crop_nonsuit");63  }64  if (getText("month_sowing") == "November") {65    showElement("crop_nonsuit");66  }67  if (getText("month_sowing") == "December") {68    showElement("crop_nonsuit");69  }70  } else {71    return false;72  }73});74onEvent("calc_ai", "click", function( ) {75  setScreen("Calculate");76});77onEvent("register_reg", "click", function( ) {78  playSpeech("Thanks!For regestering", "female", "English");79  var UserData={};80  UserData.name = getText("user_reg");81  UserData.nname = getText("name_reg");82  UserData.mail = getText("emai_reg");83  UserData.main = getText("pass_reg");84  createRecord("data_user", UserData, function(record) {85    console.log("Record created with id:" + record.id);86    console.log("User Name:" + UserData.name + " Name:" + UserData.nname + " Email:" + UserData.mail + "Password:" + UserData.main);87    88  });89});90onEvent("login_b_login", "click", function( ) {91 readRecords("data_user", {}, function(records) {92   for (var i =0; i < records.length; i++) {93     if ((records[i]).name == getText("user_name_log")) {94       if ((records[i]).main == getText("pass_log")) {95         setScreen("Home_main");96       } else {97         showElement("hide_log");98       }99     } else {100       showElement("hide_log");101     }102   }103 });104});105onEvent("return_login", "click", function( ) {106  setScreen("Home");107});108onEvent("return_register", "click", function( ) {109  setScreen("Home");110});111onEvent("login", "click", function( ) {112  setScreen("Login");113  playSpeech("welcome back", "female", "English");114});115onEvent("register", "click", function( ) {116  setScreen("Register");117  playSpeech("welcome", "female", "English");118});119onEvent("dropdown1", "change", function( ) {120  if (getText("dropdown1") == "Home") {121    setScreen("Home_main");122  }123});124onEvent("dropdown2", "change", function( ) {125  if (getText("dropdown2") == "Home") {126    setScreen("Home_main");127  }128});129onEvent("dropdown3", "change", function( ) {130  if (getText("dropdown3") == "Home") {131    setScreen("Home_main");132  }133});134onEvent("dropdown4", "change", function( ) {135  if (getText("dropdown4") == "Home") {136    setScreen("Home_main");137  }138});139onEvent("dropdown5", "change", function( ) {140  if (getText("dropdown5") == "Home") {141    setScreen("Home_main");142  }143});144onEvent("dropdown6", "change", function( ) {145  if (getText("dropdown6") == "Home") {146    setScreen("Home_main");147  }148});149onEvent("dropdown1", "change", function( ) {150  if (getText("dropdown1") == "Buy") {151    setScreen("Buy");152  }153});154onEvent("dropdown2", "change", function( ) {155  if (getText("dropdown2") == "Buy") {156    setScreen("Buy");157  }158});159onEvent("dropdown3", "change", function( ) {160  if (getText("dropdown3") == "Buy") {161    setScreen("Buy");162  }163});164onEvent("dropdown4", "change", function( ) {165  if (getText("dropdown4") == "Buy") {166    setScreen("Buy");167  }168});169onEvent("dropdown5", "change", function( ) {170  if (getText("dropdown5") == "Buy") {171    setScreen("Buy");172  }173});174onEvent("dropdown6", "change", function( ) {175  if (getText("dropdown6") == "Buy") {176    setScreen("Buy");177  }178});179onEvent("dropdown1", "change", function( ) {180  if (getText("dropdown1") == "News") {181    setScreen("News");182  }183});184onEvent("dropdown2", "change", function( ) {185  if (getText("dropdown2") == "News") {186    setScreen("News");187  }188});189onEvent("dropdown3", "change", function( ) {190  if (getText("dropdown3") == "News") {191    setScreen("News");192  }193});194onEvent("dropdown4", "change", function( ) {195  if (getText("dropdown4") == "News") {196    setScreen("News");197  }198});199onEvent("dropdown5", "change", function( ) {200  if (getText("dropdown5") == "News") {201    setScreen("News");202  }203});204onEvent("dropdown6", "change", function( ) {205  if (getText("dropdown6") == "News") {206    setScreen("News");207  }208});209onEvent("dropdown1", "change", function( ) {210  if (getText("dropdown1") == "Sell") {211    setScreen("Sell");212  }213});214onEvent("dropdown2", "change", function( ) {215  if (getText("dropdown2") == "Sell") {216    setScreen("Sell");217  }218});219onEvent("dropdown3", "change", function( ) {220  if (getText("dropdown3") == "Sell") {221    setScreen("Sell");222  }223});224onEvent("dropdown4", "change", function( ) {225  if (getText("dropdown4") == "Sell") {226    setScreen("Sell");227  }228});229onEvent("dropdown5", "change", function( ) {230  if (getText("dropdown5") == "Sell") {231    setScreen("Sell");232  }233});234onEvent("dropdown6", "change", function( ) {235  if (getText("dropdown6") == "Sell") {236    setScreen("Sell");237  }238});239onEvent("dropdown1", "change", function( ) {240  if (getText("dropdown1") == "Tips") {241    setScreen("Tips");242  }243});244onEvent("dropdown2", "change", function( ) {245  if (getText("dropdown2") == "Tips") {246    setScreen("Tips");247  }248});249onEvent("dropdown3", "change", function( ) {250  if (getText("dropdown3") == "Tips") {251    setScreen("Tips");252  }253});254onEvent("dropdown4", "change", function( ) {255  if (getText("dropdown4") == "Tips") {256    setScreen("Tips");257  }258});259onEvent("dropdown5", "change", function( ) {260  if (getText("dropdown5") == "Tips") {261    setScreen("Tips");262  }263});264onEvent("dropdown6", "change", function( ) {265  if (getText("dropdown6") == "Tips") {266    setScreen("Tips");267  }268});269onEvent("dropdown1", "change", function( ) {270  if (getText("dropdown1") == "Tools") {271    setScreen("Tools");272  }273});274onEvent("dropdown2", "change", function( ) {275  if (getText("dropdown2") == "Tools") {276    setScreen("Tools");277  }278});279onEvent("dropdown3", "change", function( ) {280  if (getText("dropdown3") == "Tools") {281    setScreen("Tools");282  }283});284onEvent("dropdown4", "change", function( ) {285  if (getText("dropdown4") == "Tools") {286    setScreen("Tools");287  }288});289onEvent("dropdown5", "change", function( ) {290  if (getText("dropdown5") == "Tools") {291    setScreen("Tools");292  }293});294onEvent("dropdown6", "change", function( ) {295  if (getText("dropdown6") == "Tools") {296    setScreen("Tools");297  }298});299onEvent("dropdown1", "change", function( ) {300  if (getText("dropdown1") == "Calculate") {301    setScreen("Calculate");302  }303});304onEvent("dropdown2", "change", function( ) {305  if (getText("dropdown2") == "Calculate") {306    setScreen("Calculate");307  }308});309onEvent("dropdown3", "change", function( ) {310  if (getText("dropdown3") == "Calculate") {311    setScreen("Calculate");312  }313});314onEvent("dropdown4", "change", function( ) {315  if (getText("dropdown4") == "Calculate") {316    setScreen("Calculate");317  }318});319onEvent("dropdown5", "change", function( ) {320  if (getText("dropdown5") == "Calculate") {321    setScreen("Calculate");322  }323});324onEvent("dropdown6", "change", function( ) {325  if (getText("dropdown6") == "Calculate") {326    setScreen("Calculate");327  }328});329onEvent("dropdown7", "change", function( ) {330  if (getText("dropdown7") == "Calculate") {331    setScreen("Calculate");332  }333});334onEvent("dropdown7", "change", function( ) {335  if (getText("dropdown7") == "Home") {336    setScreen("Home");337  }338});339onEvent("dropdown7", "change", function( ) {340  if (getText("dropdown7") == "Sell") {341    setScreen("Sell");342  }343});344onEvent("dropdown7", "change", function( ) {345  if (getText("dropdown7") == "Buy") {346    setScreen("Buy");347  }348});349onEvent("dropdown7", "change", function( ) {350  if (getText("dropdown7") == "Tips") {351    setScreen("Tips");352  }353});354onEvent("dropdown7", "change", function( ) {355  if (getText("dropdown7") == "Tools") {356    setScreen("Tools");357  }358});359onEvent("dropdown7", "change", function( ) {360  if (getText("dropdown7") == "News") {361    setScreen("News");362  }363});364onEvent("getsource", "click", function( ) {365  setScreen("source");366});367onEvent("source_button", "click", function( ) {368  if (getText("user_int") == "aws_proj") {369    if (getText("pass_int") == "proj_agriculture") {370      open("https://github.com/Stensith/Aws_proj.git");371    }372  } else {373    playSound("sound://category_alerts/vibrant_game_correct_answer_hit.mp3", false);374    showElement("Eroor_acess");375  }376});377onEvent("Return_s", "click", function( ) {378  setScreen("Tools");379  playSound("sound://category_alerts/retro_game_health_pickup_6.mp3", false);380});381onEvent("equals_calculate", "click", function( ) {382  showElement("calc_out");383  setText("calc_out", getText("height_calc") * getText("width_calc"));384  showElement("cost_fence");385  showElement("cost_level");386  showElement("cost_seeds");387  showElement("rate_l");388  showElement("rate_f");389  showElement("rate_s");390});391onEvent("cost_fence", "click", function( ) {392  showElement("out_cfence");393  setText("out_cfence", ((getText("height_calc") + getText("width_calc")) * "2") * getText("rate_f"));394});395onEvent("cost_level", "click", function( ) {396  showElement("out_cleveling");397  setText("out_cleveling", getText("calc_out") * getText("rate_l"));398});399onEvent("cost_seeds", "click", function( ) {400  showElement("out_cseeds");401  setText("out_cseeds", getText("calc_out") * getText("rate_s"));402});403onEvent("wheat1_buy", "click", function( ) {404  playSound("sound://category_whoosh/animation_whoosh10deep.mp3", false);405  open("https://www.amazon.in/s?k=Best+1kg+of+wheat+seeds&ref=nb_sb_noss");406});407onEvent("wheat1_buy_b", "click", function( ) {408  playSound("sound://category_whoosh/animation_whoosh10deep.mp3", false);409  open("https://www.amazon.in/s?k=Best+1kg+of+wheat+seeds&ref=nb_sb_noss");410});411onEvent("rice_buy", "click", function( ) {412  playSound("sound://category_whoosh/animation_whoosh10deep.mp3", false);413  open("https://www.amazon.in/s?k=best+rice+seeds&adgrpid=66369839430&ext_vrnc=hi&gclid=CjwKCAjwiY6MBhBqEiwARFSCPiOfrEP8PQ3uvyUxog7mFDSVCjWPKNESTIfG2sczHHJprdwHRRwT5xoC1dQQAvD_BwE&hvadid=398059830388&hvdev=c&hvlocphy=1007825&hvnetw=g&hvqmt=e&hvrand=14800052695484305710&hvtargid=kwd-833491980676&hydadcr=24568_1971427&tag=googinhydr1-21&ref=pd_sl_c98ju3aa4_e");414});415onEvent("rice_buy_b", "click", function( ) {416  playSound("sound://category_whoosh/animation_whoosh10deep.mp3", false);417  open("https://www.amazon.in/s?k=best+rice+seeds&adgrpid=66369839430&ext_vrnc=hi&gclid=CjwKCAjwiY6MBhBqEiwARFSCPiOfrEP8PQ3uvyUxog7mFDSVCjWPKNESTIfG2sczHHJprdwHRRwT5xoC1dQQAvD_BwE&hvadid=398059830388&hvdev=c&hvlocphy=1007825&hvnetw=g&hvqmt=e&hvrand=14800052695484305710&hvtargid=kwd-833491980676&hydadcr=24568_1971427&tag=googinhydr1-21&ref=pd_sl_c98ju3aa4_e");418});419onEvent("gram_buy", "click", function( ) {420  playSound("sound://category_whoosh/animation_whoosh10deep.mp3", false);421  open("https://www.amazon.in/s?k=best+gram+seeds&crid=3R43AD4XANWDV&sprefix=best+gram+seeds%2Caps%2C372&ref=nb_sb_noss");422});423onEvent("gram_buy_b", "click", function( ) {424  playSound("sound://category_whoosh/animation_whoosh10deep.mp3", false);425  open("https://www.amazon.in/s?k=best+gram+seeds&crid=3R43AD4XANWDV&sprefix=best+gram+seeds%2Caps%2C372&ref=nb_sb_noss");426});427onEvent("tip_1", "click", function( ) {428  open("https://www.growveg.com/plants/us-and-canada/how-to-grow-wheat/");429});430onEvent("tip_2", "click", function( ) {431  open("https://www.gardeningknowhow.com/edible/grains/rice/how-to-grow-rice.htm");432});433onEvent("tip_3", "click", function( ) {434  open("https://www.gardeners.com/how-to/building-healthy-soil/5060.html");435});436onEvent("tip_4", "click", function( ) {437  open("https://www.cseindia.org/removing-pesticides-from-fruits-and-vegetables-2681#:~:text=Washing%20with%202%25%20of%20salt,removed%20by%20cold%20water%20washing.");438});439onEvent("hint", "click", function( ) {440  playSpeech("Welcome!", "female", "English");441  setScreen("hint");442});443onEvent("return_buy", "click", function( ) {444  setScreen("Home_main");445});446onEvent("return_calculate", "click", function( ) {447  setScreen("Home_main");448});449onEvent("return_hints", "click", function( ) {450  setScreen("Home_main");451});452onEvent("return_sell", "click", function( ) {453  setScreen("Home_main");454});455onEvent("return_news", "click", function( ) {456  setScreen("Home_main");457});458onEvent("return_tools", "click", function( ) {459  setScreen("Home_main");460});461onEvent("return_tips", "click", function( ) {462  setScreen("Home_main");463});464onEvent("login_info", "click", function( ) {465  setScreen("login_info_s");466});467onEvent("home_info", "click", function( ) {468  setScreen("home_info_s");469});470onEvent("buy_info", "click", function( ) {471  setScreen("buy_info_s");472});473onEvent("sell_info", "click", function( ) {474  setScreen("sell_info_s");475});476onEvent("news_info", "click", function( ) {477  setScreen("news_info_s");478});479onEvent("calculate_info", "click", function( ) {480  setScreen("calculate_info_s");481});482onEvent("tools_info", "click", function( ) {483  setScreen("tools_info_s");484});485onEvent("tips_info", "click", function( ) {486  setScreen("tips_info_s");487});488onEvent("safe_info", "click", function( ) {489  setScreen("safe_info_s");490});491onEvent("feedback_buton", "click", function( ) {492  setScreen("feedback_s");493});494onEvent("hint", "click", function( ) {495  setScreen("hints");496});497onEvent("submit_feedback", "click", function( ) {498  var feeddata = {};499  feeddata.main = getText("feedback_int");500  feeddata.user = getText("user_int_feed")501  createRecord("feedback_data", feeddata , function(record) {502    console.log("record created with id:" + record.id);503  });504});505onEvent("sell_buton", "click", function( ) {506  open("https://kisanmandi.com/index.php/free-farmer-registration");507});508onEvent("button_sell_2", "click", function( ) {509  open("https://kisanmandi.com/index.php/free-farmer-registration");510});511onEvent("buy_tools", "click", function( ) {512  open("https://www.amazon.in/Kraft-Seeds-Garden-Gardening-Gloves/dp/B07WJVSRSH/ref=sr_1_6?crid=170WWG4A4FZ8I&keywords=tools%2Bfor%2Bagriculture%2Bwork&qid=1636697600&sprefix=Tools%2BFor%2Bagri%2Caps%2C732&sr=8-6&th=1");513});514onEvent("buy_pipe", "click", function( ) {515  open("https://www.amazon.in/CINAGROTM-Layered-Braided-Sprayer-Connect/dp/B07M85WTTK/ref=sr_1_6?keywords=hose+pipe&qid=1636697685&sr=8-6");516});517onEvent("buy_weeder", "click", function( ) {518  open("https://www.amazon.in/SPAARK-NX212-Power-Weeder/dp/B09KT6T88G/ref=sr_1_23_sspa?keywords=Agriculture+Tools&qid=1636697269&sr=8-23-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEzS0tZRVBaTEwzOVdVJmVuY3J5cHRlZElkPUEwNTkzMTEwMVJIMEkzTzVBOFBZOSZlbmNyeXB0ZWRBZElkPUEwOTI4MDk4MjdCRkNWSFlPMDVNOSZ3aWRnZXROYW1lPXNwX210ZiZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU=");519});520onEvent("get_id", "click", function( ) {521  setScreen("get_id_s");522  setText("idprint", getUserId());523});524onEvent("policy_b", "click", function( ) {525  open("https://code.org/privacy");526});527onEvent("hint_b", "click", function( ) {528  setScreen("hints");529});530onEvent("problem_1", "click", function( ) {531  setScreen("feedback_s");532});533onEvent("problem_2", "click", function( ) {534  setScreen("feedback_s");535});536onEvent("problem_3", "click", function( ) {537  setScreen("feedback_s");538});539onEvent("problem_4", "click", function( ) {540  setScreen("feedback_s");541});542onEvent("problem_5", "click", function( ) {543  setScreen("feedback_s");544});545onEvent("problem_6", "click", function( ) {546  setScreen("feedback_s");547});548onEvent("problem_7", "click", function( ) {549  setScreen("feedback_s");550});551onEvent("problem_8", "click", function( ) {552  setScreen("feedback_s");...events_dispatcher_spec.js
Source:events_dispatcher_spec.js  
1describe("EventsDispatcher", function() {2  var dispatcher;3  beforeEach(function() {4    dispatcher = new Pusher.EventsDispatcher();5  });6  describe("#bind", function() {7    it("should add the listener to a specific event", function() {8      var onEvent = jasmine.createSpy("onEvent");9      dispatcher.bind("event", onEvent);10      dispatcher.emit("event", "test");11      dispatcher.emit("boop", "nope");12      expect(onEvent).toHaveBeenCalledWith("test");13      expect(onEvent.calls.length).toEqual(1);14    });15    it("should add the same listener to a specific event several times", function() {16      var onEvent = jasmine.createSpy("onEvent");17      dispatcher.bind("event", onEvent);18      dispatcher.bind("event", onEvent);19      dispatcher.emit("event", "test");20      expect(onEvent).toHaveBeenCalledWith("test");21      expect(onEvent.calls.length).toEqual(2);22    });23    it("should add the listener with different contexts", function() {24      var onEvent = jasmine.createSpy("onEvent");25      dispatcher.bind("event", onEvent);26      dispatcher.bind("event", onEvent, this);27      dispatcher.bind("event", onEvent, {});28      dispatcher.emit("event", "test");29      expect(onEvent).toHaveBeenCalledWith("test");30      expect(onEvent.calls.length).toEqual(3);31    });32  });33  describe("#bind_all", function() {34    it("should add the listener to all events", function() {35      var onAll = jasmine.createSpy("onAll");36      dispatcher.bind_all(onAll);37      dispatcher.emit("event", "test");38      dispatcher.emit("boop", []);39      expect(onAll).toHaveBeenCalledWith("event", "test");40      expect(onAll).toHaveBeenCalledWith("boop", []);41      expect(onAll.calls.length).toEqual(2);42    });43  });44  describe("#unbind", function() {45    it("should remove the listener", function() {46      var onEvent = jasmine.createSpy("onEvent");47      dispatcher.bind("event", onEvent);48      dispatcher.unbind("event", onEvent);49      dispatcher.emit("event");50      expect(onEvent).not.toHaveBeenCalled();51    });52    it("should remove the listener while emitting events (regression)", function() {53      var onEvent1 = jasmine.createSpy("onEvent1").andCallFake(function() {54        dispatcher.unbind("event", onEvent1);55      });56      var onEvent2 = jasmine.createSpy("onEvent2");57      dispatcher.bind("event", onEvent1);58      dispatcher.bind("event", onEvent2);59      dispatcher.emit("event");60      expect(onEvent1.calls.length).toEqual(1);61      expect(onEvent2.calls.length).toEqual(1);62      dispatcher.emit("event");63      expect(onEvent1.calls.length).toEqual(1);64      expect(onEvent2.calls.length).toEqual(2);65    });66    it("should not remove the last callback if unbinding a function that was not bound (regression)", function() {67      var onEvent = jasmine.createSpy("onEvent");68      var otherCallback = jasmine.createSpy("otherCallback");69      dispatcher.bind("event", onEvent);70      dispatcher.unbind("event", otherCallback);71      dispatcher.emit("event");72      expect(onEvent.calls.length).toEqual(1);73    });74    it("should remove all listeners on omitted arguments", function() {75      var onEvent1 = jasmine.createSpy("onEvent1");76      var onEvent2 = jasmine.createSpy("onEvent2");77      dispatcher.bind("event1", onEvent1);78      dispatcher.bind("event2", onEvent2);79      dispatcher.unbind();80      dispatcher.emit("event1");81      dispatcher.emit("event2");82      expect(onEvent1).not.toHaveBeenCalled();83      expect(onEvent2).not.toHaveBeenCalled();84    });85    it("should remove all event's listeners if only event name is given", function() {86      var onEvent1 = jasmine.createSpy("onEvent1");87      var onEvent2 = jasmine.createSpy("onEvent2");88      var onOther = jasmine.createSpy("onOther");89      dispatcher.bind("event", onEvent1);90      dispatcher.bind("event", onEvent2, {});91      dispatcher.bind("other", onOther);92      dispatcher.unbind("event");93      dispatcher.emit("event");94      dispatcher.emit("other");95      expect(onEvent1).not.toHaveBeenCalled();96      expect(onEvent2).not.toHaveBeenCalled();97      expect(onOther.calls.length).toEqual(1);98    });99    it("should remove all listeners with given callback", function() {100      var onEvent = jasmine.createSpy("onEvent");101      var onOther = jasmine.createSpy("onOther");102      dispatcher.bind("event", onEvent);103      dispatcher.bind("event2", onEvent, {});104      dispatcher.bind("event2", onOther);105      dispatcher.unbind(null , onEvent);106      dispatcher.emit("event");107      dispatcher.emit("event2");108      expect(onEvent).not.toHaveBeenCalled();109      expect(onOther.calls.length).toEqual(1);110    });111    it("should remove all event's listeners with given callback", function() {112      var onEvent = jasmine.createSpy("onEvent");113      dispatcher.bind("event", onEvent);114      dispatcher.bind("event2", onEvent);115      dispatcher.unbind("event" , onEvent);116      dispatcher.emit("event");117      expect(onEvent).not.toHaveBeenCalled();118      dispatcher.emit("event2");119      expect(onEvent.calls.length).toEqual(1);120    });121    it("should remove all event's listeners with given context", function() {122      var onEvent1 = jasmine.createSpy("onEvent1");123      var onEvent2 = jasmine.createSpy("onEvent2");124      var onEvent3 = jasmine.createSpy("onEvent3");125      var context = {};126      dispatcher.bind("event", onEvent1, context);127      dispatcher.bind("event", onEvent2, context);128      dispatcher.bind("event", onEvent3);129      dispatcher.unbind("event", null, context);130      dispatcher.emit("event");131      expect(onEvent1).not.toHaveBeenCalled();132      expect(onEvent2).not.toHaveBeenCalled();133      expect(onEvent3.calls.length).toEqual(1);134    });135    it("should remove all listeners with given context", function() {136      var onEvent1 = jasmine.createSpy("onEvent1");137      var onEvent2 = jasmine.createSpy("onEvent2");138      var onEvent3 = jasmine.createSpy("onEvent3");139      var context = {};140      dispatcher.bind("event1", onEvent1, context);141      dispatcher.bind("event2", onEvent2, context);142      dispatcher.bind("event3", onEvent3);143      dispatcher.unbind(null, null, context);144      dispatcher.emit("event1");145      dispatcher.emit("event2");146      dispatcher.emit("event3");147      expect(onEvent1).not.toHaveBeenCalled();148      expect(onEvent2).not.toHaveBeenCalled();149      expect(onEvent3.calls.length).toEqual(1);150    });151    it("should remove all event's listeners with given callback and context", function() {152      var onEvent = jasmine.createSpy("onEvent");153      var context = {};154      dispatcher.bind("event", onEvent, context);155      dispatcher.bind("event2", onEvent, context);156      dispatcher.unbind("event" , onEvent, context);157      dispatcher.emit("event");158      expect(onEvent).not.toHaveBeenCalled();159      dispatcher.emit("event2");160      expect(onEvent.calls.length).toEqual(1);161    });162    it("should remove all listeners with given callback and context", function() {163      var onEvent = jasmine.createSpy("onEvent");164      var onOther = jasmine.createSpy("onOther");165      var context = {};166      dispatcher.bind("event", onEvent, context);167      dispatcher.bind("event2", onEvent, context);168      dispatcher.bind("event3", onEvent);169      dispatcher.bind("other", onOther, context);170      dispatcher.unbind(null , onEvent, context);171      dispatcher.emit("event");172      dispatcher.emit("event2");173      expect(onEvent).not.toHaveBeenCalled();174      dispatcher.emit("event3");175      expect(onEvent.calls.length).toEqual(1);176      dispatcher.emit("other");177      expect(onOther.calls.length).toEqual(1);178    });179  });180  describe("#emit", function() {181    it("should call all listeners", function() {182      var callbacks = Pusher.Util.map([1, 2, 3], function(i) {183        return jasmine.createSpy("onTest" + i);184      });185      Pusher.Util.apply(callbacks, function(callback) {186        dispatcher.bind("test", callback);187      });188      dispatcher.emit("test", { x: 1 });189      Pusher.Util.apply(callbacks, function(callback) {190        expect(callback).toHaveBeenCalledWith({ x: 1 });191      });192    });193    it("should call all global listeners", function() {194      var callbacks = Pusher.Util.map([1, 2, 3], function(i) {195        return jasmine.createSpy("onGlobal" + i);196      });197      Pusher.Util.apply(callbacks, function(callback) {198        dispatcher.bind_all(callback);199      });200      dispatcher.emit("g", { y: 2 });201      Pusher.Util.apply(callbacks, function(callback) {202        expect(callback).toHaveBeenCalledWith("g", { y: 2 });203      });204    });205    it("should call fail through function when there are no listeners for an event", function() {206      var failThrough = jasmine.createSpy("failThrough");207      var dispatcher = new Pusher.EventsDispatcher(failThrough);208      dispatcher.emit("nothing", "data");209      expect(failThrough).toHaveBeenCalledWith("nothing", "data");210    });211    it("should call fail through function after removing all event's listeners", function() {212      var failThrough = jasmine.createSpy("failThrough");213      var onEvent = jasmine.createSpy("onEvent");214      var dispatcher = new Pusher.EventsDispatcher(failThrough);215      dispatcher.bind("event", onEvent);216      dispatcher.unbind("event", onEvent);217      dispatcher.emit("event", "data");218      expect(onEvent).not.toHaveBeenCalled();219      expect(failThrough).toHaveBeenCalledWith("event", "data");220    });221    it("should call listener with provided context", function() {222      var context = {};223      var boundContext, unboundContext;224      var onEventBound = jasmine.createSpy("onEventBound").andCallFake(function(){225        boundContext = this;226      });227      var onEventUnbound = jasmine.createSpy("onEventUnbound").andCallFake(function(){228        unboundContext = this;229      });230      dispatcher.bind("event", onEventBound, context);231      dispatcher.bind("event", onEventUnbound);232      dispatcher.emit("event");233      expect(boundContext).toEqual(context);234      expect(unboundContext).toEqual(window);235    });236  });...battery.tests.js
Source:battery.tests.js  
1/*2 *3 * Licensed to the Apache Software Foundation (ASF) under one4 * or more contributor license agreements.  See the NOTICE file5 * distributed with this work for additional information6 * regarding copyright ownership.  The ASF licenses this file7 * to you under the Apache License, Version 2.0 (the8 * "License"); you may not use this file except in compliance9 * with the License.  You may obtain a copy of the License at10 *11 *   http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing,14 * software distributed under the License is distributed on an15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY16 * KIND, either express or implied.  See the License for the17 * specific language governing permissions and limitations18 * under the License.19 *20*/21describe('Battery (navigator.battery)', function () {22    // used to keep the count of event listeners > 0, in order to avoid battery level being updated with the real value when adding the first listener during test cases23    var dummyOnEvent = jasmine.createSpy();24    beforeEach(function () {25        window.addEventListener("batterycritical", dummyOnEvent, false);26    });27    afterEach(function () {28        window.removeEventListener("batterystatus", dummyOnEvent, false);29    });30    it("battery.spec.1 should exist", function() {31        expect(navigator.battery).toBeDefined();32    });33    it("battery.spec.2 should fire batterystatus events", function () {34        // batterystatus35        var onEvent;36        37        runs(function () {38            onEvent = jasmine.createSpy().andCallFake(function () {39                window.removeEventListener("batterystatus", onEvent, false);40            });41            window.addEventListener("batterystatus", onEvent, false);42            navigator.battery._status({ level: 30, isPlugged: false });43        });44        waitsFor(function () { return onEvent.wasCalled; }, "batterystatus onEvent was not called", 100);45        runs(function () {46            expect(onEvent).toHaveBeenCalled();47        });48    });49    it("battery.spec.3 should fire batterylow events", function () {50        var onEvent;51        52        // batterylow 30 -> 2053        runs(function () {54            onEvent = jasmine.createSpy().andCallFake(function () {55                //console.log("batterylow fake callback called");56                window.removeEventListener("batterylow", onEvent, false);57            });58            window.addEventListener("batterylow", onEvent, false);59            navigator.battery._status({ level: 20, isPlugged: false });60        });61        waitsFor(function () { return onEvent.wasCalled; }, "batterylow onEvent was not called when level goes from 30->20", 100);62        runs(function () {63            expect(onEvent).toHaveBeenCalled();64        });65        // batterylow 30 -> 1966        runs(function () {67            onEvent = jasmine.createSpy().andCallFake(function () {68                //console.log("batterylow fake callback called");69                window.removeEventListener("batterylow", onEvent, false);70            });71            navigator.battery._status({ level: 30, isPlugged: false });72            window.addEventListener("batterylow", onEvent, false);73            navigator.battery._status({ level: 19, isPlugged: false });74        });75        waitsFor(function () { return onEvent.wasCalled; }, "batterylow onEvent was not called when level goes from 30->19", 100);76        runs(function () {77            expect(onEvent).toHaveBeenCalled();78        });79    });80    it("battery.spec.4 should fire batterycritical events", function () {81        var onEvent;82        // batterycritical 19->583        runs(function () {84            onEvent = jasmine.createSpy().andCallFake(function () {85                window.removeEventListener("batterycritical", onEvent, false);86            });87            window.addEventListener("batterycritical", onEvent, false);88            navigator.battery._status({ level: 5, isPlugged: false });89        });90        waitsFor(function () { return onEvent.wasCalled; }, "batterycritical onEvent was not called  when level goes from 19->5", 100);91        runs(function () {92            expect(onEvent).toHaveBeenCalled();93        });94        95        // batterycritical 19->496        runs(function () {97            onEvent = jasmine.createSpy().andCallFake(function () {98                window.removeEventListener("batterycritical", onEvent, false);99            });100            navigator.battery._status({ level: 19, isPlugged: false });101            window.addEventListener("batterycritical", onEvent, false);102            navigator.battery._status({ level: 4, isPlugged: false });103        });104        waitsFor(function () { return onEvent.wasCalled; }, "batterycritical onEvent was not called  when level goes from 19->4", 100);105        runs(function () {106            expect(onEvent).toHaveBeenCalled();107        });108    });109    it("battery.spec.5 should NOT fire events when charging or level is increasing", function () {110       var onEvent;111       // setup: batterycritical should fire when level decreases (100->4) ( CB-4519 )112       runs(function () {113            onEvent = jasmine.createSpy("onbatterycritical");114            navigator.battery._status({ level: 100, isPlugged: false });115            window.addEventListener("batterycritical", onEvent, false);116            navigator.battery._status({ level: 4, isPlugged: false });117            });118       waits(100);119       runs(function () {120            expect(onEvent).toHaveBeenCalled();121            });122       123       // batterycritical should not fire when level increases (4->5)( CB-4519 )124       runs(function () {125            onEvent = jasmine.createSpy("onbatterycritical");126            navigator.battery._status({ level: 4, isPlugged: false });127            window.addEventListener("batterycritical", onEvent, false);128            navigator.battery._status({ level: 5, isPlugged: false });129            });130       waits(100);131       runs(function () {132            expect(onEvent).not.toHaveBeenCalled();133            });134        // batterylow should not fire when level increases (5->20) ( CB-4519 )135        runs(function () {136            onEvent = jasmine.createSpy("onbatterylow");137            window.addEventListener("batterylow", onEvent, false);138            navigator.battery._status({ level: 20, isPlugged: false });139        });140        waits(100);141        runs(function () {142            expect(onEvent).not.toHaveBeenCalled();143        });144        // batterylow should NOT fire if we are charging   ( CB-4520 )145        runs(function () {146            onEvent = jasmine.createSpy("onbatterylow");147            navigator.battery._status({ level: 21, isPlugged: true });148            window.addEventListener("batterylow", onEvent, false);149            navigator.battery._status({ level: 20, isPlugged: true });150        });151        waits(100);152        runs(function () {153            expect(onEvent).not.toHaveBeenCalled();154        });155        // batterycritical should NOT fire if we are charging   ( CB-4520 )156        runs(function () {157            onEvent = jasmine.createSpy("onbatterycritical");158            navigator.battery._status({ level: 6, isPlugged: true });159            window.addEventListener("batterycritical", onEvent, false);160            navigator.battery._status({ level: 5, isPlugged: true });161            162        });163        waits(100);164        runs(function () {165            expect(onEvent).not.toHaveBeenCalled();166        });167    });...code.js
Source:code.js  
1onEvent("button1", "click", function( ) {2  setScreen("screen2");3});4onEvent("button2", "click", function( ) {5  setScreen("screen3");6});7onEvent("image1", "click", function( ) {8  open("https://www.facebook.com/");9});10onEvent("image2", "click", function( ) {11  open("https://www.snapchat.com/");12});13onEvent("image3", "click", function( ) {14  open("https://byjus.com/?utm_source=Google&utm_medium=CPC&utm_campaign=K12-Byjus-Brand-Desktop-India&utm_term=byjus&gclid=Cj0KCQjwsLWDBhCmARIsAPSL3_0X2Fc8rs0NLjgP0qEMDbhTJ_fMeIiI_HqmuqSmSVNnHSlYnDGywzEaAl2vEALw_wcB");15});16onEvent("image4", "click", function( ) {17  open("https://www.instagram.com/");18});19onEvent("image5", "click", function( ) {20  open("https://twitter.com/?lang=en");21});22onEvent("image6", "click", function( ) {23  open("https://gaana.com/");24});25onEvent("image7", "click", function( ) {26  open("https://www.hotstar.com/in");27});28onEvent("image8", "click", function( ) {29  open("https://www.wikipedia.org/");30});31onEvent("image9", "click", function( ) {32  open("https://www.apple.com/in/?afid=p238%7CsdUuvv563-dc_mtid_187079nc38483_pcrid_507827787007_pgrid_109516736379_&cid=aos-IN-kwgo-brand--slid---product-");33});34onEvent("image10", "click", function( ) {35  open("https://scratch.mit.edu/");36});37onEvent("image11", "click", function( ) {38  open("https://www.google.com/");39});40onEvent("button3", "click", function( ) {41  setScreen("screen2");42});43onEvent("image12", "click", function( ) {44  open("https://www.amazon.com/");45});46onEvent("image13", "click", function( ) {47  open("https://www.phonepe.com/");48});49onEvent("image14", "click", function( ) {50  open("https://www.youtube.com/");51});52onEvent("button4", "click", function( ) {53  setScreen("screen3");54});55onEvent("button5", "click", function( ) {56  setScreen("screen4");57  58});59onEvent("button8", "click", function( ) {60  setScreen("screen5");61  62});63onEvent("button6", "click", function( ) {64  setScreen("screen4");65  66});67onEvent("button7", "click", function( ) {68  setScreen("screen6");69  70});71onEvent("button9", "click", function( ) {72  setScreen("screen5");73  74});75onEvent("button10", "click", function( ) {76  setScreen("screen1");77  78});79onEvent("button11", "click", function( ) {80  setScreen("screen7");81  82});83onEvent("button12", "click", function( ) {84  setScreen("screen8");85  86});87onEvent("button13", "click", function( ) {88  setScreen("screen6");89  90});91onEvent("button14", "click", function( ) {92  setScreen("screen7");93  94});95onEvent("button15", "click", function( ) {96  setScreen("screen9");97  98});99onEvent("button16", "click", function( ) {100  setScreen("screen8");101  102});103onEvent("button17", "click", function( ) {104  setScreen("screen10");105  106});107onEvent("button18", "click", function( ) {108  setScreen("screen9");109  110});111onEvent("image20", "click", function( ) {112  open("https://watch.tatasky.com/");113});114onEvent("image21", "click", function( ) {115  open("https://www.prabhatkids.edu.in/");116});117onEvent("image22", "click", function( ) {118  open("https://brainly.in/");119});120onEvent("image23", "click", function( ) {121  open("https://www.remove.bg/");122});123onEvent("image24", "click", function( ) {124  open("https://spark.adobe.com/");125});126onEvent("image25", "click", function( ) {127  open("https://meet.google.com/");128});129onEvent("image26", "click", function( ) {130  open("https://translate.google.co.in/");131});132onEvent("image27", "click", function( ) {133  open("https://classroom.google.com/");134});135onEvent("image28", "click", function( ) {136  open("https://drive.google.com/");137});138onEvent("image29", "click", function( ) {139  open("https://docs.google.com/");140});141onEvent("image30", "click", function( ) {142  open("https://duo.google.com/");143});144onEvent("image31", "click", function( ) {145  open("https://docs.google.com/");146});147onEvent("image32", "click", function( ) {148  open("https://docs.google.com/");149});150onEvent("image33", "click", function( ) {151  open("https://photos.google.com/");152});153onEvent("image34", "click", function( ) {154  open("https://calendar.google.com/");155});156onEvent("image35", "click", function( ) {157  open("https://www.google.co.in/shopping");158});159onEvent("image36", "click", function( ) {160  open("https://news.google.com/");161});162onEvent("image37", "click", function( ) {163  open("https://play.google.com/");164});165onEvent("image38", "click", function( ) {166  open("https://www.google.co.in/");167});168onEvent("image39", "click", function( ) {169  open("https://earth.google.com/web");170});171onEvent("image40", "click", function( ) {172  open("https://mail.google.com/");173});174onEvent("image41", "click", function( ) {175  open("https://mail.google.com/");176});177onEvent("image42", "click", function( ) {178  open("https://keep.google.com/");179});180onEvent("image43", "click", function( ) {181  open("https://docs.google.com/");182});183onEvent("image44", "click", function( ) {184  open("https://mahakosh.gov.in/m/");185});186onEvent("image45", "click", function( ) {187  open("https://www.google.co.in/maps/");188});189onEvent("image46", "click", function( ) {190  open("https://firebase.google.com/");191});192onEvent("image47", "click", function( ) {193  open("https://github.com/");194});195onEvent("image48", "click", function( ) {196  open("https://zoom.us/");197});198onEvent("image49", "click", function( ) {199  open("https://piyushlandge750.whjr.site/");200});201onEvent("image15", "click", function( ) {202  open("https://code.whitehatjr.com/s/login");203});204onEvent("image17", "click", function( ) {205  open("https://pay.google.com/gp/w/u/0/home/signup");206});207onEvent("image18", "click", function( ) {208  open("https://web.whatsapp.com/");209});210onEvent("image19", "click", function( ) {211  open("https://www.flipkart.com/");212});213onEvent("button19", "click", function( ) {214  setScreen("screen11");215  216});217onEvent("button20", "click", function( ) {218  setScreen("screen12");219  220});221onEvent("button21", "click", function( ) {222  setScreen("screen13");223  224});225onEvent("button22", "click", function( ) {226  setScreen("screen11");227  228});229onEvent("button23", "click", function( ) {230  setScreen("screen11");231  232});233onEvent("button24", "click", function( ) {234  setScreen("screen10");235  236});237onEvent("image52", "click", function( ) {238  open("https://youtu.be/FrtlQWWzQnE");...Using AI Code Generation
1const chromeless = new Chromeless()2async function run() {3    .type('chromeless', 'input[name="q"]')4    .press(13)5    .wait('#resultStats')6    .screenshot()7  await chromeless.end()8}9run().catch(console.error.bind(console))10const chromeless = new Chromeless()11async function run() {12    .type('chromeless', 'input[name="q"]')13    .press(13)14    .wait('#resultStats')15    .screenshot()16  await chromeless.end()17}18run().catch(console.error.bind(console))19const chromeless = new Chromeless()20async function run() {21    .type('chromeless', 'input[name="q"]')22    .press(13)23    .wait('#resultStats')24    .screenshot()25  await chromeless.end()26}27run().catch(console.error.bind(console))28const chromeless = new Chromeless()29async function run() {30    .type('chromeless', 'input[name="q"]')31    .press(13)32    .wait('#resultStats')33    .screenshot()34  await chromeless.end()35}36run().catch(console.error.bind(console))37const chromeless = new Chromeless()38async function run() {39    .type('chromeless', 'input[name="q"]')40    .press(13Using AI Code Generation
1const chromeless = new Chromeless()2  .type('chromeless', 'input[name="q"]')3  .press(13)4  .wait('#resultStats')5  .evaluate(() => {6  })7  .then((title) => {8  })9  .catch((error) => {10    console.error('Search failed:', error)11  })12  .then(() => {13    return chromeless.end()14  })15const chromeless = new Chromeless()16  .type('chromeless', 'input[name="q"]')17  .press(13)18  .wait('#resultStats')19  .evaluate(() => {20  })21  .then((title) => {22  })23  .catch((error) => {24    console.error('Search failed:', error)25  })26  .then(() => {27    return chromeless.end()28  })29const chromeless = new Chromeless()30  .type('chromeless', 'input[name="q"]')31  .press(13)32  .wait('#resultStats')33  .evaluate(() => {34  })35  .then((title) => {36  })37  .catch((error) => {38    console.error('Search failed:', error)39  })40  .then(() => {41    return chromeless.end()42  })43const chromeless = new Chromeless()44  .type('chromeless', 'input[name="q"]')45  .press(13)46  .wait('#resultStats')47  .evaluate(() => {48  })49  .then((title) => {50  })Using AI Code Generation
1const chromeless = new Chromeless();2  .type('chromeless', 'input[name="q"]')3  .press(13)4  .wait('#resultStats')5  .evaluate(() => {6  })7  .then(title => {8    console.log('title is:', title)9  })10  .catch(console.error.bind(console))11chromeless.onEvent('Page.loadEventFired', () => {12  console.log('Page loaded');13});14chromeless.onEvent('Page.loadEventFired', () => {15  console.log('Page loaded');16});17chromeless.end();18const chromeless = new Chromeless();19  .type('chromeless', 'input[name="q"]')20  .press(13)21  .wait('#resultStats')22  .evaluate(() => {23  })24  .then(title => {25    console.log('title is:', title)26  })27  .catch(console.error.bind(console))28chromeless.onEvent('Page.loadEventFired', () => {29  console.log('Page loaded');30});31chromeless.onEvent('Page.loadEventFired', () => {32  console.log('Page loaded');33});34chromeless.end();35const chromeless = new Chromeless();36  .type('chromeless', 'input[name="q"]')37  .press(13)38  .wait('#resultStats')39  .evaluate(() => {40  })41  .then(title => {42    console.log('title is:', title)43  })44  .catch(console.error.bind(console))45chromeless.onEvent('Page.loadEventFired', () => {46  console.log('Page loaded');47});48chromeless.onEvent('Page.loadEventFired', () => {49  console.log('Page loaded');50});Using AI Code Generation
1const chromeless = new Chromeless({ remote: true })2  .type('chromeless', 'input[name="q"]')3  .press(13)4  .wait('#resultStats')5  .screenshot()6await chromeless.end()7const chromeless = new Chromeless({ remote: true })8  .type('chromeless', 'input[name="q"]')9  .press(13)10  .wait('#resultStats')11  .screenshot()12await chromeless.end()13const chromeless = new Chromeless({ remote: true })14  .type('chromeless', 'input[name="q"]')15  .press(13)16  .wait('#resultStats')17  .screenshot()18await chromeless.end()19const chromeless = new Chromeless({ remote: true })20  .type('chromeless', 'input[name="q"]')21  .press(13)22  .wait('#resultStats')23  .screenshot()24await chromeless.end()25const chromeless = new Chromeless({ remote: true })26  .type('chromeless', 'input[name="q"]')27  .press(13)28  .wait('#resultStats')29  .screenshot()30await chromeless.end()Using AI Code Generation
1const chromeless = new Chromeless()2  .type('chromeless', 'input[name="q"]')3  .press(13)4  .wait('#resultStats')5  .onEvent('Page.frameStartedLoading', () => console.log('frameStartedLoading'))6  .onEvent('Page.frameStoppedLoading', () => console.log('frameStoppedLoading'))7  .screenshot()8await chromeless.end()9const chromeless = new Chromeless()10  .type('chromeless', 'input[name="q"]')11  .press(13)12  .wait('#resultStats')13  .onEvent('Page.frameStartedLoading', () => console.log('frameStartedLoading'))14  .onEvent('Page.frameStoppedLoading', () => console.log('frameStoppedLoading'))15  .screenshot()16await chromeless.end()17const chromeless = new Chromeless()18  .type('chromeless', 'input[name="q"]')19  .press(13)20  .wait('#resultStats')21  .onEvent('Page.frameStartedLoading', () => console.log('frameStartedLoading'))22  .onEvent('Page.frameStoppedLoading', () => console.log('frameStoppedLoading'))23  .screenshot()24await chromeless.end()25const chromeless = new Chromeless()26  .type('chromeless', 'input[name="q"]')27  .press(13)28  .wait('#resultStats')29  .onEvent('Page.frameStartedLoading',Using AI Code Generation
1const Chromeless = require('chromeless').Chromeless2async function run() {3  const chromeless = new Chromeless()4    .type('chromeless', 'input[name="q"]')5    .press(13)6    .wait('#resultStats')7    .evaluate(() => {8      return document.querySelector('.gLFyf').value9    })10  await chromeless.end()11}12run().catch(console.error.bind(console))13const Chromeless = require('chromeless').Chromeless14async function run() {15  const chromeless = new Chromeless()16    .type('chromeless', 'input[name="q"]')17    .press(13)18    .wait('#resultStats')19    .evaluate(() => {20      return document.querySelector('.gLFyf').value21    })22  await chromeless.end()23}24run().catch(console.error.bind(console))25const Chromeless = require('chromeless').Chromeless26async function run() {27  const chromeless = new Chromeless()28    .type('chromeless', 'input[name="q"]')29    .press(13)30    .wait('#resultStats')31    .evaluate(() => {32      return document.querySelector('.gLFyf').value33    })34  await chromeless.end()35}36run().catch(console.error.bind(console))37const Chromeless = require('chromeless').Chromeless38async function run() {Using AI Code Generation
1const chromeless = require('chromeless').default2const fs = require('fs')3const c = chromeless()4c.on('error', (error) => {5  console.error(error)6})7c.on('request', (request) => {8  console.log(request)9})10c.on('response', (response) => {11  console.log(response)12})13c.on('console', (message) => {14  console.log(message)15})16c.on('requestfailed', (request) => {17  console.log(request)18})19c.on('requestfinished', (request) => {20  console.log(request)21})22c.on('response', (response) => {23  console.log(response)24})25  .type('chromeless', 'input[name="q"]')26  .press(13)27  .wait('#resultStats')28  .evaluate(() => {29  })30  .end()31  .then((title) => {32  })33  .catch((error) => {34    console.error(error)35  })36const chromeless = require('chromeless').default37const fs = require('fs')38const c = chromeless()39c.on('error', (error) => {40  console.error(error)41})42c.on('request', (request) => {43  console.log(request)44})45c.on('response', (response) => {46  console.log(response)47})48c.on('console', (message) => {49  console.log(message)50})51c.on('requestfailed', (request) => {52  console.log(request)53})54c.on('requestfinished', (request) => {55  console.log(request)56})57c.on('response', (response) => {58  console.log(response)59})60  .type('chromeless', 'input[name="q"]')61  .press(13)62  .wait('#resultStats')63  .evaluate(() => {64  })65  .end()66  .then((title) => {67  })68  .catch((error) => {69    console.error(error)70  })Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
