How to use isSauce method in Webdriverio

Best JavaScript code snippet using webdriverio-monorepo

hotdogger.js

Source:hotdogger.js Github

copy

Full Screen

1/**2 * Takes in allFood array and displays the upgrade quantities on the HTML3 * @param {*} arrayObject Takes in array of objects allFood4 */5const displayUpgrades = (arrayObject, displayScores) => {6 document.getElementById('total-clicks').innerHTML = displayScores.clicked;7 document.getElementById('condiment-multi').innerHTML = displayScores.clickMultiplier.toFixed(2);8 if (arrayObject[0].owned !== 0 || arrayObject[1].owned !== 0) { //Clever, This makes the dog total an integer unless you have upgrades that would dictate otherwise.9 document.getElementById('total').innerHTML = (displayScores.total).toFixed(2); 10 } else {11 document.getElementById('total').innerHTML = parseInt(displayScores.total);12 }13 for (let i=0; i<arrayObject.length; i++) { //lets look through our array14 document.getElementById(`${arrayObject[i].name}-score`).innerHTML = arrayObject[i].owned;15 document.getElementById(`${arrayObject[i].name}-cost`).innerHTML = arrayObject[i].cost;16 }17}18/**19 * Adds score to topping upgrade20 * @param {*} toppingParam id of relavent upgrade.21 */22const addToppingScore = (allFood) => { // instead of DOM #foodName-score I want to updated allFood.owned23 let addScore = allFood.owned;24 addScore++;25 allFood.owned = addScore;26}27/**28* This turns on food that is affordable.29*/30const checkUnlocked = (arrayObject, displayScores) => {31 let totalDogs = parseFloat(displayScores.total);32 for (let i=0; i<arrayObject.length; i++) {33 if (totalDogs >= arrayObject[i].reqDogs) {34 document.getElementById(`${arrayObject[i].name}-click`).style.display = 'block';35 } else if (totalDogs == 0){ //clears upgrades on reset36 document.getElementById(`${arrayObject[i].name}-click`).style.display = 'none';37 }38 }39}40/**41* Takes condiment clicks and turns them into increase click multipliers.42* @param {string} condi this is a string of the condiment name.43* @param {number} clickMultiplier this is the click multiplier .01 == 1%. additive not compounding.44*/45const addCondiScore = (arrayObject, displayScores) => { 46 let addScore = arrayObject.owned;47 addScore++;48 arrayObject.owned = addScore;49 displayScores.clickMultiplier += arrayObject.multiplier;50 }51// /**52// * This updates the hotdogs per hotdog click, first multiplying the condiment multiplier53// * @param {number} singleClick independently scale the value of a click by increasing this. 1 = 100% clickpower54// */55// const addDogScoreOld = (singleClick) => { //I want to make this an object in a main function that holds all the scores instead of storing them in html56// let addScore = parseFloat(document.getElementById('total').innerHTML);57// addScore += singleClick * document.getElementById('condiment-multi').innerHTML;58// document.getElementById('total').innerHTML = addScore.toFixed(2);59// }60const addToppingDPS = (arrayObject, displayScores) => {61 arrayObject.forEach((element) => {62 let speedPower = 0;63 if (!element.isSauce) {64 speedPower = element.multiplier*element.owned*parseFloat(displayScores.clickMultiplier.toFixed(2));65 displayScores.total += parseFloat(speedPower/10);66 }67 });68}69const addDogScore = (scoreObject) => { 70 let numOne = 1 * scoreObject.clickMultiplier; 71 let numTwo = scoreObject.total;72 let numThree = parseFloat((numOne + numTwo).toFixed(2));73 scoreObject.total = numThree; //update total74}75/**76* Add this to anything you want to count as a click. Clicks are for unlocks and highscores etc.77*/78const addClicksScore = (displayScores) => { 79 displayScores.clicked += 1;80 }81const checkCost = (allFood, displayScores) => { 82 let checkedCost = allFood.cost;83 let checkedMoney = displayScores.total;84 if (checkedCost <= checkedMoney) {85 return true;86 } else {87 return false;88 } 89} 90const updateCost = (arrayObject, displayScores) => {91 displayScores.total -= parseFloat(arrayObject.cost); //Pay for current cost92 arrayObject.cost = (arrayObject.cost*arrayObject.costInc).toFixed(2); //Update the cost of the next item93}94const checkCostStyle = (idPrefix) => {95 let checkedCost = parseFloat(document.getElementById(`${idPrefix}-cost`).innerHTML);96 let checkedMoney = parseFloat(document.getElementById('total').innerHTML);97 if (checkedCost <= checkedMoney) { 98 document.getElementById(`${idPrefix}-background`).style.background = 'rgb(228, 138, 220)';99 return true;100 } else {101 document.getElementById(`${idPrefix}-background`).style.background = 'rgb(167, 84, 160)';102 return false;103 }104}105/**106 * This is the main function that runs most of the stuff.107 */108const main = () => {109 let allFood = [ //I am beginning to make all upgrade related data live here.110 {name: 'ketchup' , reqDogs: 5, isSauce: true, multiplier: 0.01, cost: 1, costInc: 1.05, owned: 0}, 111 {name: 'mustard' , reqDogs: 15, isSauce: true, multiplier: 0.02, cost: 2, costInc: 1.10, owned: 0}, 112 {name: 'relish' , reqDogs: 25, isSauce: true, multiplier: 0.05, cost: 3, costInc: 1.25, owned: 0}, 113 {name: 'bbq' , reqDogs: 35, isSauce: true, multiplier: 0.10, cost: 4, costInc: 1.50, owned: 0}, 114 {name: 'cheese' , reqDogs: 1000, isSauce: true, multiplier: 1.00, cost: 1000, costInc: 3.00, owned: 0}, 115 {name: 'onions' , reqDogs: 10, isSauce: false, multiplier: 1.00, cost: 10, costInc: 1.05, owned: 0}, 116 {name: 'pickles' , reqDogs: 20, isSauce: false, multiplier: 2.00, cost: 20, costInc: 1.10, owned: 0}, 117 {name: 'tomatoes', reqDogs: 50, isSauce: false, multiplier: 3.00, cost: 50, costInc: 1.25, owned: 0}, 118 {name: 'peppers' , reqDogs: 100, isSauce: false, multiplier: 4.00, cost: 100, costInc: 1.50, owned: 0}119 ];120 let displayScores = { //Store all scores121 total: 0,122 clicked: 0,123 eaten: 0,124 clickMultiplier: 1125 };126 let currentStoryIndex = 0; // Current Index of pop up story127 const milestone = [0,5,50,100,250,500,1000,2000,3000,4000,5000]; // Total dogs required to trigger Story128 const stories = [129 '<p>Welcome to Hot Dogger! </br> The game where you click a giant hot dog. </br> Give it a try, click that dog! Get 5 hot dogs and I bet you can afford some delicious ketchup.</ p>',130 `Congratulations you have ${milestone[1]} dogs! You unlocked ketchup! Ketchup increases your clicking power! Load up on ketechup!`,131 `Congratulations you have ${milestone[2]} dogs`,132 `Congratulations you have ${milestone[3]} dogs!`,133 `Congratulations you have ${milestone[4]} dogs!`,134 `Congratulations you have ${milestone[5]} dogs!`,135 `Congratulations you have ${milestone[6]} dogs!`,136 `Congratulations you have ${milestone[7]} dogs!`,137 `Congratulations you have ${milestone[8]} dogs!`,138 `Congratulations you have ${milestone[9]} dogs!`,139 `Congratulations you have ${milestone[10]} dogs!`140 ];141 142 143 document.getElementById("exit").addEventListener('click',(e) => { //Listens for exit button" to close story pop-up144 e.preventDefault();145 document.getElementById("story-container").style.display = 'none'; 146 });147 148 // if (document.cookie) { //if there are no cookies to set dog count set it to zero149 // displayScores.total = document.cookie;150 // } else {151 // document.getElementById('total').innerHTML = 0;152 // }153 154 window.setInterval(function(){ //RUNNING LOOP155 addToppingDPS(allFood, displayScores);156 if (displayScores.total >= milestone[currentStoryIndex]) { //Pops up story if you have the milestone amount of Hotdogs157 document.getElementById("story-box").innerHTML = stories[currentStoryIndex];158 document.getElementById("story-container").style.display = 'block';159 currentStoryIndex++ 160 }161 document.getElementById('total').innerHTML = displayScores.total;162 for (let i=0; i<allFood.length; i++) { //Checking what is affordable to grey it out or not. maybe loop should be in function.163 checkCostStyle(allFood[i].name);164 }165 166 checkUnlocked(allFood, displayScores); //turn display:block; on of unlocked food.167 displayUpgrades(allFood, displayScores);168 169 170 // document.cookie = document.getElementById('total').innerHTML; //store dogs in cookies171 },100); //We are refreshing 10 times a second 172 document.getElementById("the-hotdog").addEventListener('click',(e) => {173 let checkedMoney = parseFloat(document.getElementById('total').innerHTML); //look into this.174 if (checkedMoney > 0){175 e.preventDefault();176 } else {177 navigator.vibrate(250);178 }179 addDogScore(displayScores);180 addClicksScore(displayScores); 181 });182 183 document.getElementById("reset").addEventListener('click',(e) => { //Resets all quantities owned in the allFood.184 displayScores.total = 0; 185 displayScores.clicked = 0;186 displayScores.eaten = 99;187 displayScores.clickMultiplier = 1;188 189 allFood.forEach((element) => { //This is my first functioning forEach loop 3/13/2020190 element.owned = 0;191 document.getElementById(`${element.name}-score`).innerHTML = element.owned;192 });193 });194 195 196 document.getElementById("eat").addEventListener('click',(e) => {197 e.preventDefault();198 let addScore = parseInt(document.getElementById('eaten').innerHTML);199 addScore += 1;200 document.getElementById('eaten').innerHTML = addScore;201 displayScores.total -= 1; //Is this ok?202 addClicksScore(displayScores); 203 });204 205 document.getElementById("save").addEventListener('click',(e) => { //Resets all quantities owned in the allFood.206 console.log('saving');207 let food = JSON.stringify(allFood);208 let scores = JSON.stringify(displayScores);209 document.cookie = food + "#" + scores;210 console.log('saved');211 });212 213 document.getElementById("load").addEventListener('click',(e) => { //Resets all quantities owned in the allFood.214 console.log('loaded scores');215 let cookieToParse = document.cookie;216 let split = cookieToParse.split('#');217 allFood = JSON.parse(split[0]);218 displayScores = JSON.parse(split[1]);219 });220 for (let i=0; i<allFood.length; i++) { //Toppings Event Listeners221 let sourceTopping = allFood[i];222 let targetElement = document.getElementById(`${sourceTopping.name}-click`);223 if (!sourceTopping.isSauce){224 targetElement.addEventListener("click",(e) => {225 e.preventDefault();226 if (checkCost(allFood[i], displayScores)) {227 addToppingScore(allFood[i]);228 addClicksScore(displayScores);229 updateCost(allFood[i], displayScores);230 }231 });//event function232 }//close isSauce233 }//for loop234 235 for (let i=0; i<allFood.length; i++) { //Sauces Event Listeners236 let sourceSauce = allFood[i]; 237 let targetElement = document.getElementById(`${sourceSauce.name}-click`);238 if(sourceSauce.isSauce){239 targetElement.addEventListener("click",(e) => {240 e.preventDefault();241 if (checkCost(allFood[i], displayScores)) {242 addCondiScore(allFood[i], displayScores);243 addClicksScore(displayScores);244 updateCost(allFood[i], displayScores);245 }246 }); //event function247 } // close isSauce248 } //for loop249 250}// close main function...

Full Screen

Full Screen

Admin.js

Source:Admin.js Github

copy

Full Screen

1function manageFields(sauceName, sel) {2 const input = document.createElement("input");3 const invisibleInput = document.createElement("input");4 invisibleInput.style.display = "none";5 invisibleInput.value = selector.value;6 invisibleInput.name = "invisibleOptionInput"7 const ul = document.getElementById("chosenSauce");8 const li = document.createElement("li");9 li.className = "sauceNameList"10 input.type = "number";11 input.required = true;12 input.autocomplete = "off";13 input.min = "0";14 input.name = "optionInput";15 input.className = "sauceAmount";16 const checkbox = document.createElement("input");17 checkbox.type = "checkbox";18 checkbox.className = "deleteBox";19 //! Dynamic input20 if (sauceName !== "Choose Sauce") {21 li.appendChild(document.createTextNode(sauceName));22 li.appendChild(invisibleInput);23 li.appendChild(input);24 li.appendChild(checkbox);25 ul.appendChild(li);26 checkbox.addEventListener("click", () => {27 for (let i = 1; i < sel.length; ++i) {28 if (sel[i].value === checkbox.parentElement.textContent) {29 sel[i].disabled = false;30 }31 }32 checkbox.parentElement.remove();33 })34 }35}36const isSauce = document.getElementById("isSauce");37//! Add filter to dish38const checkboxFilter = document.getElementsByClassName("checkboxFilter");39for(let i = 0; i < checkboxFilter.length; ++i){40 checkboxFilter[i].addEventListener("click",()=>{41 if(i === 0){42 if(!(checkboxFilter[i+1].disabled)){43 checkboxFilter[i+1].disabled = "true";44 checkboxFilter[i+2].disabled = "true";45 isSauce.disabled = "true";46 }else{47 checkboxFilter[i+1].removeAttribute("disabled");48 checkboxFilter[i+2].removeAttribute("disabled");49 isSauce.removeAttribute("disabled");50 }51 }52 if(i === 1){53 if(!(checkboxFilter[i+1].disabled)){54 checkboxFilter[i+1].disabled = "true";55 checkboxFilter[i-1].disabled = "true";56 isSauce.disabled = "true";57 }else{58 checkboxFilter[i+1].removeAttribute("disabled");59 checkboxFilter[i-1].removeAttribute("disabled");60 isSauce.removeAttribute("disabled");61 }62 }63 if(i === 2){64 if(!(checkboxFilter[i-1].disabled)){65 checkboxFilter[i-1].disabled = "true";66 checkboxFilter[i-2].disabled = "true";67 isSauce.disabled = "true";68 }else{69 checkboxFilter[i-1].removeAttribute("disabled");70 checkboxFilter[i-2].removeAttribute("disabled");71 isSauce.removeAttribute("disabled");72 }73 }74 })75}76//!Make input fields appear, dissapear and grayed out.77const ing = document.getElementsByClassName("ingredient")78const quantity = document.getElementsByClassName("ingredientQuantity");79//! Make fields enabled and make empty fields dissapear on post req 80document.getElementById("submit").addEventListener("mousedown", () => {81 const checkbox = document.getElementById("isSauce");82 if (checkbox.checked) {83 document.getElementById("isSauceHidden").disabled = true;84 }85 for (let i = 1; i < selector.length; ++i) {86 selector[i].disabled = false;87 }88})89//! By choosing sauce adding number inputfield. By clicking checkbox removing inputfield 90const selector = document.getElementById("sauceSelector");91const sauceName = [];92selector.addEventListener("change", () => {93 if (selector.value !== "Choose Sauce") {94 sauceName.push(selector.value);95 selector[selector.selectedIndex].disabled = true;96 }97 manageFields(selector.value, selector);98})99isSauce.addEventListener("click", () => {100 if (isSauce.checked) {101 selector.disabled = true;102 for(let i = 0; i < checkboxFilter.length; ++i){103 checkboxFilter[i].disabled="true";104 }105 const ul = document.getElementById("chosenSauce");106 ul.innerHTML = "";107 for (let i = 1; i < selector.length; ++i) {108 selector[i].disabled = false;109 }110 } else {111 selector.disabled = false;112 for(let i = 0; i < checkboxFilter.length; ++i){113 checkboxFilter[i].removeAttribute("disabled")114 }115 }116})117let counter = 1;118let addIngredient = document.getElementsByClassName("addIngredient")[0];119addIngredient.addEventListener("click", () => {120 let remove = document.createElement("input");121 remove.type = "checkbox";122 remove.className = "removeBox" + counter++;123 const container = document.getElementById("container");124 const div = document.createElement("div");125 div.className = "dishIngredients";126 const inputIngredient = document.createElement("input");127 const inputQuantity = document.createElement("input");128 inputIngredient.className = "ingredient";129 inputIngredient.id = "myInput"130 inputIngredient.name = "ingredient";131 inputIngredient.placeholder = "Enter Ingredient";132 inputIngredient.required = true;133 inputIngredient.autocomplete = "off";134 inputQuantity.className = "ingredientQuantity";135 inputQuantity.name = "ingredientQuantity";136 inputQuantity.type = "number";137 inputQuantity.placeholder = "Enter Quantity";138 inputQuantity.required = true;139 inputQuantity.autocomplete = "off";140 inputQuantity.min = "0";141 container.appendChild(div);142 div.appendChild(remove);143 div.appendChild(inputIngredient);144 div.appendChild(inputQuantity);145 remove.addEventListener("click", (e) => {146 div.innerHTML = ""147 --counter;148 })149})150//////////////////////////////////////////////////!151function autocomplete(inp, arr) {152 /*the autocomplete function takes two arguments,153 the text field element and an array of possible autocompleted values:*/154 var currentFocus;155 /*execute a function when someone writes in the text field:*/156 inp.addEventListener("input", function(e) {157 var a, b, i, val = this.value;158 /*close any already open lists of autocompleted values*/159 closeAllLists();160 if (!val) { return false;}161 currentFocus = -1;162 /*create a DIV element that will contain the items (values):*/163 a = document.createElement("DIV");164 a.setAttribute("id", this.id + "autocomplete-list");165 a.setAttribute("class", "autocomplete-items");166 /*append the DIV element as a child of the autocomplete container:*/167 this.parentNode.appendChild(a);168 /*for each item in the array...*/169 for (i = 0; i < arr.length; i++) {170 /*check if the item starts with the same letters as the text field value:*/171 if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {172 /*create a DIV element for each matching element:*/173 b = document.createElement("DIV");174 /*make the matching letters bold:*/175 b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";176 b.innerHTML += arr[i].substr(val.length);177 /*insert a input field that will hold the current array item's value:*/178 b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";179 /*execute a function when someone clicks on the item value (DIV element):*/180 b.addEventListener("click", function(e) {181 /*insert the value for the autocomplete text field:*/182 inp.value = this.getElementsByTagName("input")[0].value;183 /*close the list of autocompleted values,184 (or any other open lists of autocompleted values:*/185 closeAllLists();186 });187 a.appendChild(b);188 }189 }190 });191 /*execute a function presses a key on the keyboard:*/192 inp.addEventListener("keydown", function(e) {193 var x = document.getElementById(this.id + "autocomplete-list");194 if (x) x = x.getElementsByTagName("div");195 if (e.keyCode == 40) {196 /*If the arrow DOWN key is pressed,197 increase the currentFocus variable:*/198 currentFocus++;199 /*and and make the current item more visible:*/200 addActive(x);201 } else if (e.keyCode == 38) { //up202 /*If the arrow UP key is pressed,203 decrease the currentFocus variable:*/204 currentFocus--;205 /*and and make the current item more visible:*/206 addActive(x);207 } else if (e.keyCode == 13) {208 /*If the ENTER key is pressed, prevent the form from being submitted,*/209 e.preventDefault();210 if (currentFocus > -1) {211 /*and simulate a click on the "active" item:*/212 if (x) x[currentFocus].click();213 }214 }215 });216 function addActive(x) {217 /*a function to classify an item as "active":*/218 if (!x) return false;219 /*start by removing the "active" class on all items:*/220 removeActive(x);221 if (currentFocus >= x.length) currentFocus = 0;222 if (currentFocus < 0) currentFocus = (x.length - 1);223 /*add class "autocomplete-active":*/224 x[currentFocus].classList.add("autocomplete-active");225 }226 function removeActive(x) {227 /*a function to remove the "active" class from all autocomplete items:*/228 for (var i = 0; i < x.length; i++) {229 x[i].classList.remove("autocomplete-active");230 }231 }232 function closeAllLists(elmnt) {233 /*close all autocomplete lists in the document,234 except the one passed as an argument:*/235 var x = document.getElementsByClassName("autocomplete-items");236 for (var i = 0; i < x.length; i++) {237 if (elmnt != x[i] && elmnt != inp) {238 x[i].parentNode.removeChild(x[i]);239 }240 }241 }242 /*execute a function when someone clicks in the document:*/243 document.addEventListener("click", function (e) {244 closeAllLists(e.target);245 });246 }247 248 arrIngredients = JSON.parse(arrIngredients) //arrIngredients from admin.ejs file249 let addButton = document.getElementById("addIngredient")250 autocomplete(ing[0],arrIngredients); 251 addButton.addEventListener("click",()=>{252 for(let i = 0; i < ing.length; ++i){253 autocomplete(ing[i],arrIngredients);254 }255 });256 ...

Full Screen

Full Screen

geofence_test.js

Source:geofence_test.js Github

copy

Full Screen

1import protractor from "protractor";2import net from "net";3const EC = protractor.ExpectedConditions;4describe("Geofence test", () => {5 let emuConnection;6 let isSauce = false;7 let isLocal = true;8 beforeAll((done) => {9 browser.getProcessedConfig()10 .then((config) => {11 isLocal = config.sauceUser === undefined;12 isSauce = config.sauceUser !== undefined;13 })14 .then(() => {15 if (!isSauce) {16 emuConnection = net.connect("5554", "localhost");17 emuConnection.on("connect", done);18 } else {19 done();20 }21 });22 });23 function addGeofence(notificationText) {24 const addGeofenceButton = element(by.css(".ion-plus"));25 const saveGeofenceButton = element(by.css(".ion-checkmark"));26 const notificationTextInput = element(by.model("geofence.notification.text"));27 geoFix(50.28, 18.67);28 addGeofenceButton.click();29 //workaround protractor doesn't wait for html geolocation API to resolve30 browser.wait(EC.presenceOf(notificationTextInput), 20000);31 notificationTextInput.sendKeys(notificationText);32 saveGeofenceButton.click();33 }34 function geoFix(longitude, latitude) {35 if (isSauce) {36 wdBrowser.setGeoLocation(longitude, latitude);37 } else {38 //telnet geofix works on most of emulators, wdBrowser.setGeoLocation only on android-639 emuConnection.write(`geo fix ${longitude} ${latitude}\n`);40 }41 }42 afterAll(() => {43 if (emuConnection) {44 emuConnection.destroy();45 }46 });47 it("should add geofence", (done) => {48 const geofenceList = element.all(by.repeater("geofence in geofences"));49 const firstGeofence = element(by.cssContainingText("ion-item", "Tested geofence region"));50 addGeofence("Tested geofence region");51 browser.wait(EC.presenceOf(firstGeofence), 3000);52 expect(geofenceList.count()).toBe(1);53 expect(geofenceList.first().getText()).toContain("Tested geofence region");54 done();55 });56 it("should remove added geofence", (done) => {57 const removeButton = element(by.css(".ion-trash-b"));58 const geofenceList = element.all(by.repeater("geofence in geofences"));59 const firstGeofence = element(by.cssContainingText("ion-item", "Tested geofence region"));60 expect(geofenceList.count()).toBe(1);61 removeButton.click();62 browser.wait(EC.stalenessOf(firstGeofence), 3000);63 expect(geofenceList.count()).toBe(0);64 done();65 });66 it("should remove all added geofences", (done) => {67 const moreOptionsButton = element(by.css(".ion-more"));68 const removeAllButton = element(by.buttonText("Delete all geofences"));69 const geofenceList = element.all(by.repeater("geofence in geofences"));70 const secondGeofence = element(by.cssContainingText("ion-item", "Second geofence"));71 addGeofence("First geofence");72 addGeofence("Second geofence");73 browser.wait(EC.presenceOf(secondGeofence), 3000);74 expect(geofenceList.count()).toBe(2);75 moreOptionsButton.click();76 browser.wait(EC.presenceOf(removeAllButton), 1000);77 removeAllButton.click();78 browser.wait(EC.stalenessOf(secondGeofence), 3000);79 expect(geofenceList.count()).toBe(0);80 done();81 });...

Full Screen

Full Screen

envDetector.js

Source:envDetector.js Github

copy

Full Screen

...40 return false;41 }42 return Boolean(caps.platformName && caps.platformName.match(/Android/i) || caps.browserName && caps.browserName.match(/Android/i));43}44function isSauce(caps) {45 return Boolean(caps.extendedDebugging || caps['sauce:options'] && caps['sauce:options'].extendedDebugging);46}47function isSeleniumStandalone(caps) {48 if (!caps) {49 return false;50 }51 return Boolean(caps['webdriver.remote.sessionid']);52}53function capabilitiesEnvironmentDetector(capabilities, automationProtocol) {54 return automationProtocol === 'devtools' ? devtoolsEnvironmentDetector(capabilities) : webdriverEnvironmentDetector(capabilities);55}56function sessionEnvironmentDetector({57 capabilities,58 requestedCapabilities59}) {60 return {61 isW3C: isW3C(capabilities),62 isChrome: isChrome(capabilities),63 isMobile: isMobile(capabilities),64 isIOS: isIOS(capabilities),65 isAndroid: isAndroid(capabilities),66 isSauce: isSauce(requestedCapabilities),67 isSeleniumStandalone: isSeleniumStandalone(capabilities)68 };69}70function devtoolsEnvironmentDetector({71 browserName72}) {73 return {74 isDevTools: true,75 isW3C: true,76 isMobile: false,77 isIOS: false,78 isAndroid: false,79 isChrome: browserName === 'chrome',80 isSauce: false,81 isSeleniumStandalone: false82 };83}84function webdriverEnvironmentDetector(capabilities) {85 return {86 isChrome: isChrome(capabilities),87 isMobile: isMobile(capabilities),88 isIOS: isIOS(capabilities),89 isAndroid: isAndroid(capabilities),90 isSauce: isSauce(capabilities)91 };...

Full Screen

Full Screen

karma.conf.js

Source:karma.conf.js Github

copy

Full Screen

1const noLaunch = process.argv.includes('--no-launch')2const testMinified = process.argv.includes('--minified')3const isSauce = process.argv.includes('--sauce')4const isNetlify = process.argv.includes('--netlify')5if (isNetlify) {6 process.env.CHROME_BIN = require('puppeteer').executablePath()7}8const webpackConfig = {9 devtool: 'inline-source-map',10 module: {11 rules: [12 {13 test: /\.js$/,14 exclude: /(node_modules|dist)/,15 use: {16 loader: 'babel-loader',17 options: {/* babel options */}18 }19 }20 ]21 }22}23const karmaPlugins = [24 'karma-webpack',25 'karma-qunit',26 'karma-spec-reporter',27 'karma-sourcemap-loader',28 'karma-chrome-launcher',29 'karma-firefox-launcher',30 'karma-ie-launcher',31 'karma-sauce-launcher'32]33const preprocessors = {34 'test/qunit/**/*.js': [35 'webpack',36 'sourcemap'37 ],38}39const sauceLabsLaunchers = {40 safari: {41 base: 'SauceLabs',42 browserName: 'Safari',43 browserVersion: 'latest',44 platformName: 'macOS 10.15'45 },46 edge: {47 base: 'SauceLabs',48 browserName: 'MicrosoftEdge',49 browserVersion: '18.17763',50 platformName: 'Windows 10',51 },52 ie: {53 base: 'SauceLabs',54 browserName: 'internet explorer',55 browserVersion: 'latest',56 platformName: 'Windows 7'57 },58}59function checkSauceCredentials () {60 if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {61 console.error('SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables must be set')62 process.exit(1)63 }64}65function getFiles () {66 let files67 if (testMinified) {68 files = [69 'dist/sweetalert2.all.min.js'70 ]71 } else {72 files = [73 'dist/sweetalert2.css',74 'dist/sweetalert2.js'75 ]76 }77 return files.concat([78 'node_modules/promise-polyfill/dist/polyfill.min.js',79 'node_modules/@webcomponents/template/template.js',80 'test/qunit/**/*.js'81 ])82}83function getBrowsers () {84 if (noLaunch) {85 return []86 }87 let browsers = ['ChromeHeadless']88 // Cron on GitHub Actions or check:qunit --sauce89 if (isSauce) {90 checkSauceCredentials()91 browsers = Object.keys(sauceLabsLaunchers)92 // GitHub Actions93 } else if (process.env.GITHUB_ACTION) {94 browsers = ['ChromeHeadless', 'FirefoxHeadless']95 }96 return browsers97}98function getReporters () {99 return isSauce ? ['spec', 'saucelabs'] : ['spec']100}101module.exports = function (config) {102 config.set({103 port: 3000,104 plugins: karmaPlugins,105 frameworks: ['qunit'],106 qunit: { reorder: false },107 customLaunchers: sauceLabsLaunchers,108 files: getFiles(),109 browsers: getBrowsers(),110 reporters: getReporters(),111 preprocessors,112 webpack: webpackConfig,113 webpackMiddleware: {114 stats: 'errors-only'115 },116 captureTimeout: 360000,117 browserNoActivityTimeout: 360000118 })...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1/**2 * Set the test context3 *4 * @param {object} data5 * @param {object} data.user6 * @param {string} data.user.username7 * @param {string} data.user.password8 * @param {string} data.path9 * @param {array} data.products10 */11export function setTestContext(data = {}) {12 const isSauce = browser.config.hostname && browser.config.hostname.includes('saucelabs');13 const {path, products = [], user} = data;14 const {username} = user;15 const userCookies = `document.cookie="session-username=${username}";`;16 // We initially used `sessionStorage` in the browsers but that one didn't work properly and got lost after a new17 // `browser.url('{some-url}')`. `localStorage` is more stable18 const productStorage = products.length > 0 ? `localStorage.setItem("cart-contents", "[${products.toString()}]");` : '';19 if(isSauce) {20 // Log extra context in Sauce21 browser.execute('sauce:context=#### Start `setTestContext` ####');22 }23 // Go to the domain24 browser.url('');25 // Clear the cookies and storage26 browser.deleteAllCookies();27 browser.execute('localStorage.clear();');28 // Set the new cookies and storage29 browser.execute(`${userCookies} ${productStorage}`);30 browser.pause(1000);31 // Now got to the page32 browser.url(path);33 if(isSauce) {34 // Log extra context in Sauce35 browser.execute('sauce:context=#### End `setTestContext` ####');36 }...

Full Screen

Full Screen

SauceData.js

Source:SauceData.js Github

copy

Full Screen

1export const SauceData = [2 {name: 'ketchup' , reqDogs: 5, isSauce: true, multiplier: 0.01, cost: 1, costInc: 1.05, owned: 0}, 3 {name: 'mustard' , reqDogs: 15, isSauce: true, multiplier: 0.02, cost: 2, costInc: 1.10, owned: 0}, 4 {name: 'relish' , reqDogs: 25, isSauce: true, multiplier: 0.05, cost: 3, costInc: 1.25, owned: 0}, 5 {name: 'bbq' , reqDogs: 35, isSauce: true, multiplier: 0.10, cost: 4, costInc: 1.50, owned: 0},...

Full Screen

Full Screen

demo.js

Source:demo.js Github

copy

Full Screen

1var fs = require('fs')2var browserMocha = require('./')3var code = fs.readFileSync('./assets/test.js', 'utf8')4var isSauce = process.argv[2] == 'sauce'5console.log(isSauce)6var opt = {}7if (isSauce) {8 opt = {9 sauceLabs: true,10 browser: {11 name: 'internet explorer',12 version: '6',13 //platform: 'Windows XP'14 }15 }16}17browserMocha(code, opt, function(err, val) {18 if (err) return console.error(err, val)19 browserMocha.print(val.logs)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4client.init()5 .getTitle().then(function(title) {6 console.log('Title was: ' + title);7 })8 .end();9var webdriverio = require('webdriverio');10var options = { desiredCapabilities: { browserName: 'chrome' } };11var client = webdriverio.remote(options);12client.init()13 .getTitle().then(function(title) {14 console.log('Title was: ' + title);15 })16 .end();17var webdriverio = require('webdriverio');18var options = { desiredCapabilities: { browserName: 'chrome' } };19var client = webdriverio.remote(options);20client.init()21 .getTitle().then(function(title) {22 console.log('Title was: ' + title);23 })24 .end();25var webdriverio = require('webdriverio');26var options = { desiredCapabilities: { browserName: 'chrome' } };27var client = webdriverio.remote(options);28client.init()29 .getTitle().then(function(title) {30 console.log('Title was: ' + title);31 })32 .end();33var webdriverio = require('webdriverio');34var options = { desiredCapabilities: { browserName: 'chrome' } };35var client = webdriverio.remote(options);36client.init()37 .getTitle().then(function(title) {38 console.log('Title was: ' + title);39 })40 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4 .init()5 .isSauce(function(err, isSauce) {6 })7 .end();8var webdriverio = require('webdriverio');9var options = { desiredCapabilities: { browserName: 'chrome' } };10var client = webdriverio.remote(options);11 .init()12 .isSauce(function(err, isSauce) {13 })14 .end();15var webdriverio = require('webdriverio');16var options = { desiredCapabilities: { browserName: 'chrome', 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER, build: process.env.TRAVIS_BUILD_NUMBER } };17var client = webdriverio.remote(options);18 .init()19 .isSauce(function(err, isSauce) {20 })21 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 console.log('Title was: ' + title);8}).end();9var webdriverio = require('webdriverio');10var options = {11 desiredCapabilities: {12 }13};14var client = webdriverio.remote(options);15 console.log('Title was: ' + title);16}).end();

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriverio = require('webdriverio');2const options = {3 desiredCapabilities: {4 }5};6const client = webdriverio.remote(options);7client.isSauce().then(function(isSauce) {8 console.log('isSauce: ' + isSauce);9});10client.end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var client = webdriverio.remote({ desiredCapabilities: { browserName: 'chrome' } });3client.init();4client.getTitle().then(function(title) {5 console.log('Title was: ' + title);6});7client.end();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { isSauce } from 'wdio-sauce-service';2import { isSauce } from 'wdio-sauce-service';3import { isSauce } from 'wdio-sauce-service';4if (isSauce) {5}6import { isSauce } from 'wdio-sauce-service';7if (isSauce) {8}9import { isSauce } from 'wdio-sauce-service';10if (isSauce) {11}12import { isSauce } from 'wdio-sauce-service';13if (isSauce) {14}

Full Screen

WebdriverIO Tutorial

Wondering what could be a next-gen browser and mobile test automation framework that is also simple and concise? Yes, that’s right, it's WebdriverIO. Since the setup is very easy to follow compared to Selenium testing configuration, you can configure the features manually thereby being the center of attraction for automation testing. Therefore the testers adopt WedriverIO to fulfill their needs of browser testing.

Learn to run automation testing with WebdriverIO tutorial. Go from a beginner to a professional automation test expert with LambdaTest WebdriverIO tutorial.

Chapters

  1. Running Your First Automation Script - Learn the steps involved to execute your first Test Automation Script using WebdriverIO since the setup is very easy to follow and the features can be configured manually.

  2. Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.

  3. Browser Commands For Selenium Testing - Understand more about the barriers faced while working on your Selenium Automation Scripts in WebdriverIO, the ‘browser’ object and how to use them?

  4. Handling Alerts & Overlay In Selenium - Learn different types of alerts faced during automation, how to handle these alerts and pops and also overlay modal in WebdriverIO.

  5. How To Use Selenium Locators? - Understand how Webdriver uses selenium locators in a most unique way since having to choose web elements very carefully for script execution is very important to get stable test results.

  6. Deep Selectors In Selenium WebdriverIO - The most popular automation testing framework that is extensively adopted by all the testers at a global level is WebdriverIO. Learn how you can use Deep Selectors in Selenium WebdriverIO.

  7. Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.

  8. Automated Monkey Testing with Selenium & WebdriverIO - Understand how you can leverage the amazing quality of WebdriverIO along with selenium framework to automate monkey testing of your website or web applications.

  9. JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.

  10. Cross Browser Testing With WebdriverIO - Learn more with this step-by-step tutorial about WebdriverIO framework and how cross-browser testing is done with WebdriverIO.

Run Webdriverio automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful