How to use isExisting method in Webdriverio

Best JavaScript code snippet using webdriverio-monorepo

Utils.js

Source:Utils.js Github

copy

Full Screen

...40 //--------------Filling Field41 this.Then(/^I enter "([^"]*)" as "([^"]*)"$/, function(arg1, arg2) {42 var value = objGeneral.analyzeValue(arg2); var x;43 var arg1 = objGeneral.analyzeValue(arg1);44 if(browser.isExisting("(//descendant::label[text()=\""+arg1+"\"])[1]/following::input[1]")) {45 x = "(//descendant::label[text()=\""+arg1+"\"])[1]/following::input[1]";46 }else if (browser.isExisting("(//descendant::td[text()=\""+arg1+"\"])[1]/following::input[1]")) {47 x = "(//descendant::td[text()=\""+arg1+"\"])[1]/following::input[1]";48 }else if (browser.isExisting("(//descendant::td//*[text()=\""+arg1+"\"])[1]/following::input[1]")) {49 x = "(//descendant::td//*[text()=\""+arg1+"\"])[1]/following::input[1]";50 }else if (browser.isExisting("(//descendant::*[text()=\""+arg1+"\"])[1]/following::input[1]")) {51 x = "(//descendant::*[text()=\""+arg1+"\"])[1]/following::input[1]";52 }else {53 x = "(//descendant::*[contains(text(),\""+arg1+"\")])[1]/following::input[1]";54 }55 console.log(x);56 browser.setValue(x,value); 57 });58 //--------------[OFFSHOOT]Filling Fields of [Another Section Same Field]59 this.Then(/^I enter "([^"]*)""([^"]*)" as "([^"]*)"$/, function(arg1, arg2, arg3) {60 var value = objGeneral.analyzeValue(arg3); var x;61 62 if(browser.isExisting("(//descendant::label[text()=\""+arg1+"\"])"+arg2+"/following::input[1]")) {63 x = "(//descendant::label[text()=\""+arg1+"\"])"+arg2+"/following::input[1]";64 }else if (browser.isExisting("(//descendant::td[text()=\""+arg1+"\"])"+arg2+"/following::input[1]")) {65 x = "(//descendant::td[text()=\""+arg1+"\"])"+arg2+"/following::input[1]";66 }else if (browser.isExisting("(//descendant::td//*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]")) {67 x = "(//descendant::td//*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]";68 }else if (browser.isExisting("(//descendant::*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]")) {69 x = "(//descendant::*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]";70 }else {71 x = "(//descendant::*[contains(text(),\""+arg1+"\")])"+arg2+"/following::input[1]";72 }73 console.log(x);74 browser.setValue(x,value);75 });76 //--------------Filling Fields of [Single Label Multiple Fields] e.g. Name(First/Last)77 this.Then(/^I enter "([^"]*)" field"([^"]*)" as "([^"]*)"$/, function(arg1, arg2, arg3) {78 var value = objGeneral.analyzeValue(arg3); var x;79 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"][1]/following::input"+arg2)) {80 x = "//descendant::label[text()=\""+arg1+"\"][1]/following::input"+arg2;81 }else if (browser.isExisting("//descendant::td[text()=\""+arg1+"\"][1]/following::input"+arg2)) {82 x = "//descendant::td[text()=\""+arg1+"\"][1]/following::input"+arg2;83 }else if (browser.isExisting("//descendant::td//*[text()=\""+arg1+"\"][1]/following::input"+arg2)) {84 x = "//descendant::td//*[text()=\""+arg1+"\"][1]/following::input"+arg2;85 }else if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::input"+arg2)) {86 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::input"+arg2;87 }else {88 x = "//descendant::*[contains(text(),\""+ arg1 + "\")][1]/following::input" + arg2;89 }90 console.log(x);91 browser.setValue(x,value);92 });93 //--------------[OFFSHOOT]Filling Fields of [Single Label Multiple Fields] [In Another section] e.g. Name(First/Last)94 this.Then(/^I enter "([^"]*)""([^"]*)" field"([^"]*)" as "([^"]*)"$/, function(arg1,arg2, arg3,arg4) {95 var value = objGeneral.analyzeValue(arg4); var x;96 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"]"+arg2+"/following::input"+arg3)) {97 x = "//descendant::label[text()=\""+arg1+"\"]"+arg2+"/following::input"+arg3;98 }else if (browser.isExisting("//descendant::td[text()=\""+arg1+"\"]"+arg2+"/following::input"+arg3)) {99 x = "//descendant::td[text()=\""+arg1+"\"]"+arg2+"/following::input"+arg3;100 }else if (browser.isExisting("//descendant::td//*[text()=\""+arg1+"\"]"+arg2+"/following::input"+arg3)) {101 x = "//descendant::td//*[text()=\""+arg1+"\"]"+arg2+"/following::input"+arg3;102 }else if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"]"+arg2+"/following::input"+arg3)) {103 x = "//descendant::*[text()=\""+arg1+"\"]"+arg2+"/following::input"+arg3;104 }else {105 x = "//descendant::*[contains(text(),\""+ arg1 + "\")]"+arg2+"/following::input" + arg3;106 }107 console.log(x);108 browser.setValue(x,value);109 });110 //--------------Filling Fields based on placeholder (hint)111 this.Then(/^I enter placeholder "([^"]*)" as "([^"]*)"$/, function(arg1, arg2) {112 var x = "//input[@placeholder=\""+arg1+"\"]";113 console.log(x);114 browser.setValue(x,objGeneral.analyzeValue(arg2));115 });116 //--------------Filling Fields based on button position (preceding)117 this.Then(/^I enter "([^"]*)" preceding "([^"]*)" button$/, function (arg1, arg2) {118 var x = "//input[@type='submit' and @value=\""+arg2+"\"]/preceding-sibling::input[@type='text']";119 console.log(x);120 browser.setValue(x,objGeneral.analyzeValue(arg1));121 }); 122 //--------------Filling Fields retrieving from File123 this.Then(/^I enter extracted "([^"]*)" from file "([^"]*)" preceding "([^"]*)" button$/, function (arg1, arg2, arg3) {124 var x = "//input[@type='submit' and @value=\""+arg3+"\"]/preceding-sibling::input[@type='text']";125 console.log(x);126 127 var value = prop.createEditor(arg2).get(arg1);128 console.log("The value to be entered is");129 console.log(value);130 browser.setValue(x, value);131 });132 //------------ENTER VALUE in INPUT RETRIEVED from FILE133 this.Then(/^I enter "([^"]*)" field"([^"]*)" from file "([^"]*)"$/, function(arg1, arg2, arg3) {134 var value = arg3; var x;135 if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::input"+arg2)) {136 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::input"+arg2;137 }else {138 x = "//descendant::*[contains(text(),\""+ arg1 + "\")][1]/following::input" + arg2;139 }140 console.log(x);141 var value=objGeneral.retrieveDataFromFile(arg3);142 console.log(value);143 browser.setValue(x,value);144 });145 146 //--------------Enter text with ID147 this.When(/^I enter "([^"]*)" in textbox having id as "([^"]*)"$/, function(arg1, arg2) {148 try{149 var x = "//*[contains(@id, '"+arg2+"')]";150 browser.setValue(x,objGeneral.analyzeValue(arg1));151 }catch(err){152 console.log(err);153 }154 });155 //--------------Clicking Textbox (to keep cursor inside)156 this.Then(/^I click on Textbox "([^"]*)"$/, function(arg1) {157 var x;158 arg1 = objGeneral.analyzeValue(arg1);159 if(browser.isExisting("(//descendant::label[text()=\""+arg1+"\"])[1]/following::input[1]")) {160 x = "(//descendant::label[text()=\""+arg1+"\"])[1]/following::input[1]";161 }else if (browser.isExisting("(//descendant::td[text()=\""+arg1+"\"])[1]/following::input[1]")) {162 x = "(//descendant::td[text()=\""+arg1+"\"])[1]/following::input[1]";163 }else if (browser.isExisting("(//descendant::td//*[text()=\""+arg1+"\"])[1]/following::input[1]")) {164 x = "(//descendant::td//*[text()=\""+arg1+"\"])[1]/following::input[1]";165 }else if (browser.isExisting("(//descendant::*[text()=\""+arg1+"\"])[1]/following::input[1]")) {166 x = "(//descendant::*[text()=\""+arg1+"\"])[1]/following::input[1]";167 }else {168 x = "(//descendant::*[contains(text(),\""+arg1+"\")])[1]/following::input[1]";169 }170 console.log(x);171 browser.click(x);172 browser.keys(['Enter']);173 });174 //--------------Clicking any INPUT item175 this.Then(/^I click on "([^"]*)" input field"([^"]*)"$/, function(arg1,arg2) {176 var x;177 if (browser.isExisting("(//descendant::*[text()=\""+arg1+"\"])[1]/following::input" + arg2)) {178 x = "(//descendant::*[text()=\""+arg1+"\"])[1]/following::input" + arg2;179 }else {180 x = "(//descendant::*[contains(text(),\""+arg1+"\")])[1]/following::input" + arg2;181 }182 console.log(x);183 browser.click(x);184 });185 //--------------Clicking any SELECT item186 this.Then(/^I click on "([^"]*)" combo field"([^"]*)"$/, function(arg1,arg2) {187 var x;188 if (browser.isExisting("(//descendant::*[text()=\""+arg1+"\"])[1]/following::select" + arg2)) {189 x = "(//descendant::*[text()=\""+arg1+"\"])[1]/following::select" + arg2;190 }else {191 x = "(//descendant::*[contains(text(),\""+arg1+"\")])[1]/following::select" + arg2;192 }193 console.log(browser.getLocation(x));194 console.log(x);195 browser.click(x);196 });197 198 //--------------Clicking Textbox (using placeholder)199 this.Then(/^I click on Textbox having placeholder "([^"]*)"$/, function(arg1) {200 var x = "//input[@placeholder=\""+arg1+"\"]";201 console.log(x);202 browser.click(x);203 browser.keys(['Enter']);204 });205 206 //##############-TEXT FIELD - VERIFY-##########################207 //--------------Text field - Verify208 this.Then(/^I verify from textbox "([^"]*)" as "([^"]*)"$/, function(arg1, arg2) {209 var arg2 = objGeneral.analyzeValue(arg2); var x;210 211 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"][1]/following::input[1]")) {212 x = "//descendant::label[text()=\""+arg1+"\"][1]/following::input[1]";213 }else if (browser.isExisting("//descendant::td[text()=\""+arg1+"\"][1]/following::input[1]")) {214 x = "//descendant::td[text()=\""+arg1+"\"][1]/following::input[1]";215 }else if (browser.isExisting("//descendant::td//*[text()=\""+arg1+"\"][1]/following::input[1]")) {216 x = "//descendant::td//*[text()=\""+arg1+"\"][1]/following::input[1]";217 }else if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::input[1]")) {218 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::input[1]";219 }else {220 x = "//descendant::*[contains(text(),\""+arg1+"\")][1]/following::input[1]";221 }222 console.log(x);223 expect(browser.getValue(x)).to.be.eql(arg2);224 });225 //--------------[OFFSHOOT-VERIFY]Verify Fields of [Another Section Same Field]226 this.Then(/^I verify from textbox "([^"]*)""([^"]*)" as "([^"]*)"$/, function(arg1, arg2, arg3) {227 var arg3 = objGeneral.analyzeValue(arg3); var x;228 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"]"+arg2+"/following::input[1]")) {229 x = "//descendant::label[text()=\""+arg1+"\"]"+arg2+"/following::input[1]";230 }else if (browser.isExisting("(//descendant::td[text()=\""+arg1+"\"])"+arg2+"/following::input[1]")) {231 x = "(//descendant::td[text()=\""+arg1+"\"])"+arg2+"/following::input[1]";232 }else if (browser.isExisting("(//descendant::td//*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]")) {233 x = "(//descendant::td//*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]";234 }else if (browser.isExisting("(//descendant::*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]")) {235 x = "(//descendant::*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]";236 }else {237 x = "(//descendant::*[contains(text(),\""+arg1+"\")])"+arg2+"/following::input[1]";238 }239 console.log(x);240 expect(browser.getValue(x)).to.be.eql(arg3);241 });242 243 //--------------Verify Fields of [Single Label Multiple Fields]244 this.Then(/^I verify from textbox "([^"]*)" field "([^"]*)" as "([^"]*)"$/, function(arg1, arg2, arg3) {245 var arg3 = objGeneral.analyzeValue(arg3); var x;246 247 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"][1]/following::input"+arg2)) {248 x = "//descendant::label[text()=\""+arg1+"\"][1]/following::input"+arg2;249 }else if (browser.isExisting("//descendant::td[text()=\""+arg1+"\"][1]/following::input"+arg2)) {250 x = "//descendant::td[text()=\""+arg1+"\"][1]/following::input"+arg2;251 }else if (browser.isExisting("//descendant::td//*[text()=\""+arg1+"\"][1]/following::input"+arg2)) {252 x = "//descendant::td//*[text()=\""+arg1+"\"][1]/following::input"+arg2;253 }else if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::input"+arg2)) {254 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::input"+arg2;255 }else {256 x = "//descendant::*[contains(text(),\""+ arg1 + "\")][1]/following::input" + arg2;257 }258 console.log(x);259 expect(browser.getValue(x)).to.be.eql(arg3);260 });261 //--------------Text field - VERIFY text field does not have the value262 this.Then(/^I verify from textbox "([^"]*)" does not have "([^"]*)"$/, function(arg1, arg2) {263 var x;264 var value = objGeneral.analyzeValue(arg2);265 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"][1]/following::input[1]")) {266 x = "//descendant::label[text()=\""+arg1+"\"][1]/following::input[1]";267 }else if (browser.isExisting("//descendant::td[text()=\""+arg1+"\"][1]/following::input[1]")) {268 x = "//descendant::td[text()=\""+arg1+"\"][1]/following::input[1]";269 }else if (browser.isExisting("//descendant::td//*[text()=\""+arg1+"\"][1]/following::input[1]")) {270 x = "//descendant::td//*[text()=\""+arg1+"\"][1]/following::input[1]";271 }else if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::input[1]")) {272 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::input[1]";273 }else{274 x = "//descendant::*[contains(text(),\""+arg1+"\")][1]/following::input[1]";275 }276 console.log(x);277 expect(browser.getValue(x)).to.not.eql(value);278 });279 //-------------Verifying value present in a property file against a hard-coded value280 this.Then(/^I verify value "([^"]*)" to be equal to value from saved FileProp "([^"]*)"$/, function(arg1, arg2){281 objGeneral.delay();282 var fileName = arg2.split("/")[0];283 var strProp = arg2.split("/")[1];284 var value = prop.createEditor(fileName).get(strProp);285 console.log("Valueeeeee :"+value);286 expect(prop.createEditor(fileName).get(strProp)).to.be.eql(arg1);287 });288 289 //##############-COMBO-##########################290 //--------------Selecting Text from Combo291 this.When(/^I select from "([^"]*)" as "([^"]*)"$/, function(arg1, arg2) {292 var x;293 var value = objGeneral.analyzeValue(arg2);294 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"][1]/following::select[1]")) {295 x = "//descendant::label[text()=\""+arg1+"\"][1]/following::select[1]";296 }else if (browser.isExisting("//descendant::td[text()=\""+arg1+"\"][1]/following::select[1]")) {297 x = "//descendant::td[text()=\""+arg1+"\"][1]/following::select[1]";298 }else if (browser.isExisting("//descendant::td//*[text()=\""+arg1+"\"][1]/following::select[1]")) {299 x = "//descendant::td//*[text()=\""+arg1+"\"][1]/following::select[1]";300 }else if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::select[1]")) {301 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::select[1]";302 }else {303 x = "//descendant::*[contains(text(),\""+arg1+"\")][1]/following::select[1]";304 }305 console.log(x);306 try{307 //browser.click(x);308 objGeneral.delay();309 browser.selectByVisibleText(x,value);310 }catch(err) {311 console.log("COMBO SELECT by VAL");312 //browser.click(x);313 objGeneral.delay();314 browser.selectByValue(x,value);315 }316 objGeneral.delay();317 });318 //--------------Selecting Combo [Another Section Same Field]319 this.When(/^I select from "([^"]*)""([^"]*)" as "([^"]*)"$/, function(arg1, arg2, arg3) {320 var x;321 var value = objGeneral.analyzeValue(arg3);322 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"]"+arg2+"/following::select[1]")) {323 x = "//descendant::label[text()=\""+arg1+"\"]"+arg2+"/following::select[1]";324 }else if (browser.isExisting("(//descendant::td[text()=\""+arg1+"\"])"+arg2+"/following::select[1]")) {325 x = "(//descendant::td[text()=\""+arg1+"\"])"+arg2+"/following::select[1]";326 }else if (browser.isExisting("(//descendant::td//*[text()=\""+arg1+"\"])"+arg2+"/following::select[1]")) {327 x = "(//descendant::td//*[text()=\""+arg1+"\"])"+arg2+"/following::select[1]";328 }else if (browser.isExisting("(//descendant::*[text()=\""+arg1+"\"])"+arg2+"/following::select[1]")) {329 x = "(//descendant::*[text()=\""+arg1+"\"])"+arg2+"/following::select[1]";330 }else {331 x = "(//descendant::*[contains(text(),\""+arg1+"\")])"+arg2+"/following::select[1]";332 }333 console.log(x);334 browser.selectByVisibleText(x,value);335 objGeneral.delay();336 }); 337 //--------------Selecting Combo [Single Label Multiple Fields] e.g. DOB338 this.When(/^I select from "([^"]*)" field"([^"]*)" as "([^"]*)"$/, function(arg1, arg2, arg3) {339 var value = objGeneral.analyzeValue(arg3);340 try{341 objGeneral.delay();342 var x = "//descendant::*[text()='"+arg1+"'][1]/following::select"+arg2;343 console.log(x);344 browser.selectByVisibleText(x,value);345 objGeneral.delay();346 }catch(err){347 objGeneral.delay();348 var x = "//descendant::*[contains(.,'"+arg1+"')][1]/following::select"+arg2;349 console.log(x);350 browser.selectByVisibleText(x,value);351 objGeneral.delay();352 }353 });354 //--------------[OFFSHOOT]Selecting Combo [Single Label Multiple Fields] [Another Section] e.g. DOB (Principal2)355 this.When(/^I select from "([^"]*)""([^"]*)" field"([^"]*)" as "([^"]*)"$/, function(arg1, arg2, arg3,arg4) {356 var value = objGeneral.analyzeValue(arg4);357 try{358 objGeneral.delay();359 var x = "//descendant::*[text()='"+arg1+"']"+arg2+"/following::select"+arg3;360 console.log(x);361 browser.selectByVisibleText(x,value);362 objGeneral.delay();363 }catch(err){364 objGeneral.delay();365 var x = "//descendant::*[text()='"+arg1+"']"+arg2+"/following::select"+arg3;366 console.log(x);367 browser.selectByVisibleText(x,value);368 objGeneral.delay();369 }370 });371 //--------------[COMBO ID]Select value from Combo using ID372 this.When(/^I select from dropdown having id "([^"]*)" as "([^"]*)"$/, function(arg1, arg2) {373 var value = objGeneral.analyzeValue(arg2);374 var x = "//descendant::select[contains(@id, \""+arg1+"\")]";375 console.log(x);376 browser.selectByVisibleText(x,value);377 objGeneral.delay();378 });379 //--------------Selecting Value from Combo (Sometimes, the TEXT would have special characters)380 this.When(/^I select from "([^"]*)" value as "([^"]*)"$/, function(arg1, arg2) {381 var x;382 var value = objGeneral.analyzeValue(arg2);383 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"][1]/following::select[1]")) {384 x = "//descendant::label[text()=\""+arg1+"\"][1]/following::select[1]";385 }else if (browser.isExisting("//descendant::td[text()=\""+arg1+"\"][1]/following::select[1]")) {386 x = "//descendant::td[text()=\""+arg1+"\"][1]/following::select[1]";387 }else if (browser.isExisting("//descendant::td//*[text()=\""+arg1+"\"][1]/following::select[1]")) {388 x = "//descendant::td//*[text()=\""+arg1+"\"][1]/following::select[1]";389 }else if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::select[1]")) {390 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::select[1]";391 }else {392 x = "//descendant::*[contains(text(),\""+arg1+"\")][1]/following::select[1]";393 }394 console.log(x);395 browser.selectByValue(x,value);396 objGeneral.delay();397 });398 //##############-COMBO-VERIFY##########################399 //--------------Verifying Combo Value - Simple400 this.When(/^I verify from combobox "([^"]*)" as "([^"]*)"$/, function(arg1, arg2) {401 var x;402 var value = objGeneral.analyzeValue(arg2);403 404 if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::select[1]")) {405 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::select[1]";406 }else{407 x = "//descendant::*[contains(text(),\""+arg1+"\")][1]/following::select[1]";408 }409 console.log(x+"-val-"+browser.getValue(x));410 console.log("-ToVerify-"+value);411 expect(browser.getValue(x)).to.be.eql(value);412 objGeneral.delay();413 });414 //--------------Verifying Combo Value - [Single Label Multiple Fields]415 this.When(/^I verify from combobox "([^"]*)" field "([^"]*)" as "([^"]*)"$/, function(arg1, arg2, arg3) {416 var x;417 var value = objGeneral.analyzeValue(arg3);418 if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::select"+arg2)) {419 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::select"+arg2+"/option[@selected]";420 }else{421 x = "//descendant::*[contains(text(),\""+arg1+"\")][1]/following::select"+arg2+"/option[@selected]";422 }423 console.log(x);424 expect(browser.getText(x)).to.be.eql(value);425 objGeneral.delay();426 });427 428 //--------------Verify Fields of [Another Section Same Fields]429 this.Then(/^I verify from combobox "([^"]*)""([^"]*)" as "([^"]*)"$/, function(arg1, arg2, arg3) {430 var x;431 var value = objGeneral.analyzeValue(arg3);432 if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"]"+arg2+"/following::select[1]")) {433 x = "//descendant::*[text()=\""+arg1+"\"]"+arg2+"/following::select[1]/option[@selected]";434 }else{435 x = "//descendant::*[contains(text(),\""+arg1+"\")]"+arg2+"/following::select[1]/option[@selected]";436 }437 console.log(x);438 expect(browser.getText(x)).to.be.eql(value);439 objGeneral.delay();440 });441 442 //--------------Verify Fields of [Another Section Same Fields]443 this.Then(/^I verify from combolist "([^"]*)""([^"]*)" as "([^"]*)"$/, function(arg1, arg2, arg3) {444 var x = "//descendant::*[text()='"+arg1+"']"+arg2+"/following::select[1]/option[1]";445 var value = objGeneral.analyzeValue(arg3);446 console.log(x);447 console.log(browser.getText(x));448 expect(browser.getText(x)).to.be.eql(value);449 });450 //##############-COMBO-EXISTS##########################451 //--------------Verifying Combo Exists452 this.When(/^I verify dropdown "([^"]*)" exists$/, function(arg1) {453 var x;454 if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::select[1]")) {455 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::select[1]";456 }else {457 x = "//descendant::*[contains(text(),\""+arg1+"\")][1]/following::select[1]";458 }459 console.log(x);460 expect(x).to.exist;461 objGeneral.delay();462 });463 464 //##############-RADIO BUTTON-##########################465 //--------------Selecting value for Radio Group466 this.Then(/^I select the radio button "([^"]*)" as "([^"]*)"$/, function(arg1, arg2) {467 var x;468 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding-sibling::input[@type=\"radio\"][1]")) {469 x = "//descendant::label[text()=\""+arg1+"\"][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding-sibling::input[@type=\"radio\"][1]";470 }else if (browser.isExisting("//descendant::td[text()=\""+arg1+"\"][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding-sibling::input[@type=\"radio\"][1]")) {471 x = "//descendant::td[text()=\""+arg1+"\"][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding-sibling::input[@type=\"radio\"][1]";472 }else if (browser.isExisting("//descendant::td//*[text()=\""+arg1+"\"][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding-sibling::input[@type=\"radio\"][1]")) {473 x = "//descendant::td//*[text()=\""+arg1+"\"][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding-sibling::input[@type=\"radio\"][1]";474 }else if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding-sibling::input[@type=\"radio\"][1]")) {475 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding-sibling::input[@type=\"radio\"][1]";476 }else if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding::input[@type=\"radio\"][1]")) {477 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding::input[@type=\"radio\"][1]";478 }else {479 x = "//descendant::*[contains(text(),\""+arg1+"\")][1]/following::*[contains(text(),\"" + arg2 + "\")][1]/preceding::input[@type=\"radio\"][1]";480 }481 console.log(x);482 browser.click(x);483 });484 485 //##############-CHECKBOX-##########################486 //--------------Clicking checkbox with ID487 this.When(/^I click on checkbox having id as "([^"]*)"$/, function(arg1) {488 489 try{490 var x = "//*[contains(@id, '"+arg1+"')]";491 browser.click(x);492 }catch(err){493 console.log(err);494 }495 });496 497 //--------------CHECKBOX: Taking action on checkbox498 this.When(/^I "([^"]*)" the checkbox present "([^"]*)" the "([^"]*)"$/, function(arg1, arg2, arg3) {499 var x; var action = arg1;500 arg3 = objGeneral.analyzeValue(arg3);501 502 if(arg2 == 'after'){ 503 if(browser.isExisting("(//descendant::label[text()=\""+arg3+"\"])[1]/following::*[@type = \"checkbox\"][1]")) {504 x = "(//descendant::label[text()=\""+arg3+"\"])[1]/following::*[@type = \"checkbox\"][1]";505 }else if (browser.isExisting("(//descendant::td[text()=\""+arg3+"\"])[1]/following::*[@type = \"checkbox\"][1]")) {506 x = "(//descendant::td[text()=\""+arg3+"\"])[1]/following::*[@type = 'checkbox'][1]";507 }else if (browser.isExisting("(//descendant::td//*[text()=\""+arg3+"\"])[1]/following::*[@type = \"checkbox\"][1]")) {508 x = "(//descendant::td//*[text()=\""+arg3+"\"])[1]/following::*[@type = 'checkbox'][1]";509 }else if (browser.isExisting("(//descendant::*[text()=\""+arg3+"\"])[1]/following::*[@type = \"checkbox\"][1]")) {510 x = "(//descendant::*[text()=\""+arg3+"\"])[1]/following::*[@type = 'checkbox'][1]";511 }else {512 x = "(//descendant::*[contains(text(),\""+arg3+"\")])[1]/following::*[@type = 'checkbox'][1]";513 }514 console.log(x);515 objGeneral.OperateCheckbox(x, action);516 }517 else if(arg2 == 'before'){ 518 if(browser.isExisting("(//descendant::label[text()=\""+arg3+"\"])[1]/preceding::*[@type = \"checkbox\"][1]")) {519 x = "(//descendant::label[text()=\""+arg3+"\"])[1]/preceding::*[@type = \"checkbox\"][1]";520 }else if (browser.isExisting("(//descendant::td[text()=\""+arg3+"\"])[1]/preceding::*[@type = \"checkbox\"][1]")) {521 x = "(//descendant::td[text()=\""+arg3+"\"])[1]/preceding::*[@type = 'checkbox'][1]";522 }else if (browser.isExisting("(//descendant::td//*[text()=\""+arg3+"\"])[1]/preceding::*[@type = \"checkbox\"][1]")) {523 x = "(//descendant::td//*[text()=\""+arg3+"\"])[1]/preceding::*[@type = 'checkbox'][1]";524 }else if (browser.isExisting("(//descendant::*[text()=\""+arg3+"\"])[1]/preceding::*[@type = \"checkbox\"][1]")) {525 x = "(//descendant::*[text()=\""+arg3+"\"])[1]/preceding::*[@type = 'checkbox'][1]";526 }else {527 x = "(//descendant::*[contains(text(),\""+arg3+"\")])[1]/preceding::*[@type = 'checkbox'][1]";528 }529 console.log(x);530 objGeneral.OperateCheckbox(x, action);531 }532 }); 533 534 //--------------CHECKBOX: Taking action on multiple checkbox with same label535 this.When(/^I "([^"]*)" the checkbox present "([^"]*)" the "([^"]*)""([^"]*)"$/, function(arg1, arg2, arg3, arg4) {536 arg3 = objGeneral.analyzeValue(arg3);537 var x; var action = arg1;538 arg3 = objGeneral.analyzeValue(arg3);539 if(arg2 == 'after'){ 540 if(browser.isExisting("(//descendant::label[text()=\""+arg3+"\"])"+arg4+"/following::*[@type = \"checkbox\"][1]")) {541 x = "(//descendant::label[text()=\""+arg3+"\"])"+arg4+"/following::*[@type = \"checkbox\"][1]";542 }else if (browser.isExisting("(//descendant::td[text()=\""+arg3+"\"])"+arg4+"/following::*[@type = \"checkbox\"][1]")) {543 x = "(//descendant::td[text()=\""+arg3+"\"])"+arg4+"/following::*[@type = 'checkbox'][1]";544 }else if (browser.isExisting("(//descendant::td//*[text()=\""+arg3+"\"])"+arg4+"/following::*[@type = \"checkbox\"][1]")) {545 x = "(//descendant::td//*[text()=\""+arg3+"\"])"+arg4+"/following::*[@type = 'checkbox'][1]";546 }else if (browser.isExisting("(//descendant::*[text()=\""+arg3+"\"])"+arg4+"/following::*[@type = \"checkbox\"][1]")) {547 x = "(//descendant::*[text()=\""+arg3+"\"])"+arg4+"/following::*[@type = 'checkbox'][1]";548 }else {549 x = "(//descendant::*[contains(text(),\""+arg3+"\")])"+arg4+"/following::*[@type = 'checkbox'][1]";550 }551 console.log(x);552 objGeneral.OperateCheckbox(x, action);553 554 }else if(arg2 == 'before'){ 555 if(browser.isExisting("(//descendant::label[text()=\""+arg3+"\"])"+arg4+"/preceding::*[@type = \"checkbox\"][1]")) {556 x = "(//descendant::label[text()=\""+arg3+"\"])"+arg4+"/preceding::*[@type = \"checkbox\"][1]";557 }else if (browser.isExisting("(//descendant::td[text()=\""+arg3+"\"])"+arg4+"/preceding::*[@type = \"checkbox\"][1]")) {558 x = "(//descendant::td[text()=\""+arg3+"\"])"+arg4+"/preceding::*[@type = 'checkbox'][1]";559 }else if (browser.isExisting("(//descendant::td//*[text()=\""+arg3+"\"])"+arg4+"/preceding::*[@type = \"checkbox\"][1]")) {560 x = "(//descendant::td//*[text()=\""+arg3+"\"])"+arg4+"/preceding::*[@type = 'checkbox'][1]";561 }else if (browser.isExisting("(//descendant::*[text()=\""+arg3+"\"])"+arg4+"/preceding::*[@type = \"checkbox\"][1]")) {562 x = "(//descendant::*[text()=\""+arg3+"\"])"+arg4+"/preceding::*[@type = 'checkbox'][1]";563 }else {564 x = "(//descendant::*[contains(text(),\""+arg3+"\")])"+arg4+"/preceding::*[@type = 'checkbox'][1]";565 }566 console.log(x);567 objGeneral.OperateCheckbox(x, action);568 }569 });570 571 //##############-BUTTON CLICKS-########################## 572 //--------------Clicking Button573 this.Then(/^I click button "([^"]*)"$/, function(arg1,callback) { 574 var x;575 if(browser.isExisting("(//input[@type='submit' and @value='"+arg1+"'])[1]")){576 x = "(//input[@type='submit' and @value='"+arg1+"'])[1]";577 }else if(browser.isExisting("(//input[@type='button' and @value=\""+arg1+"\"])[1]")){578 x = "(//input[@type='button' and @value='"+arg1+"'])[1]";579 }else if(browser.isExisting("(//button[contains(text(),\""+arg1+"\")])[1]")){580 x = "(//button[contains(text(),\""+arg1+"\")])[1]";581 //For ACM buttons "text()" is not working: VIJAY582 }else if(browser.isExisting("(//button[contains(.,\""+arg1+"\")])[1]")){583 x = "(//button[contains(.,\""+arg1+"\")])[1]";584 //For identifying button based on its attribute that has meaningful name (e.g. class="right")585 }else if(browser.isExisting("(//button//@*[contains(.,\""+arg1+"\")])[1]/..")){586 x = "(//button//@*[contains(.,\""+arg1+"\")])[1]/..";587 }else if(browser.isExisting("(//*[text() = \""+arg1+"\"])[1]")){588 x = "(//*[text() = \""+arg1+"\"])[1]";589 }else if(browser.isExisting("(//*[contains(text(),\""+ arg1 +"\")])[1]")){590 x = "(//*[contains(text(),\""+ arg1 +"\")])[1]";591 }else{592 //At times when it displays all caps but having InitCap inside HTML593 arg1 = arg1[0].toUpperCase() + arg1.substr(1).toLowerCase();594 x = "//input[@type='submit' and @value='"+arg1+"']";595 }596 console.log(x);597 browser.click(x); 598 objGeneral.bigdelay();599 callback();600 });601 602 //--------------[OFFSHOOT-Occurrence] Clicking Button of nth Occurrence603 this.Then(/^I click button "([^"]*)" occurrence "([^"]*)"$/, function(arg1, arg2) {604 var x; 605 if(browser.isExisting("(//input[@type='submit' and @value='"+arg1+"'])"+arg2)){606 x = "(//input[@type='submit' and @value='"+arg1+"'])" + arg2;607 }else if(browser.isExisting("(//input[@type='button' and @value=\""+arg1+"\"])" + arg2)){608 x = "(//input[@type='button' and @value='"+arg1+"'])" + arg2;609 }else if(browser.isExisting("(//button[contains(text(),\""+arg1+"\")])" + arg2)){610 x = "(//button[contains(text(),\""+arg1+"\")])" + arg2;611 //For ACM buttons "text()" is not working: VIJAY612 }else if(browser.isExisting("(//button[contains(.,\""+arg1+"\")])" + arg2)){613 x = "(//button[contains(.,\""+arg1+"\")])" + arg2;614 //For identifying button based on its attribute that has meaningful name (e.g. class="right")615 }else if(browser.isExisting("(//button//@*[contains(.,\""+arg1+"\")])" + arg2 + "/..")){616 x = "(//button//@*[contains(.,\""+arg1+"\")])" + arg2 + "/..";617 }else if(browser.isExisting("(//*[text() = \""+arg1+"\"])" + arg2)){618 x = "(//*[text() = \""+arg1+"\"])" + arg2;619 }else {620 x = "(//*[contains(text(),\""+ arg1 +"\")])" + arg2;621 }622 console.log(x);623 browser.click(x); 624 objGeneral.bigdelay();625 });626 627 //--------------Clicking Image Button [Mostly in DM]628 this.Then(/^I click Image button "([^"]*)"$/, function(arg1) { 629 var x;630 if(browser.isExisting("(//descendant::*[contains(@title , \""+arg1+"\")])[1]//img")){631 x = "(//descendant::*[contains(@title , \""+arg1+"\")])[1]//img";632 }else {633 x = "(//img[contains(@title , \""+arg1+"\")])[1]";634 }635 console.log(x);636 browser.click(x); 637 objGeneral.bigdelay();638 }); 639 //--------------[OFFSHOOT]Clicking Image Button Occurrence [Mostly in DM]640 this.Then(/^I click Image button "([^"]*)" occurrence "([^"]*)"$/, function(arg1,arg2) { 641 var x;642 if(browser.isExisting("(//descendant::*[contains(@title , \""+arg1+"\")])"+arg2+"//img")){643 x = "(//descendant::*[contains(@title, \""+arg1+"\")])"+arg2+"//img";644 }else {645 x = "(//img[contains(@title , \""+arg1+"\")])" + arg2;646 }647 console.log(x);648 browser.click(x); 649 objGeneral.bigdelay();650 }); 651 //--------------Clicking nth occurrence Button with type not submit---Courtesy:Kriti, PNC652 this.Then(/^I click on "([^"]*)" occurrence "([^"]*)"$/, function(arg1, arg2) {653 var arg1=objGeneral.analyzeValue(arg1);654 var x;655 x = "(//*[contains(text(),\""+arg1+"\")])"+arg2;656 console.log(x);657 browser.click(x);658 objGeneral.bigdelay();659 });660 //--------------Clicking button that has link - LOGIN button on home page661 this.Then(/^I click on "([^"]*)" button$/, function(arg1) {662 var x;663 objGeneral.delay();664 if(browser.isExisting("//*[text()=\""+arg1+"\"]")) {665 x = "//*[text()=\""+arg1+"\"]";666 }else if (browser.isExisting("//*[contains(text(),\""+arg1+"\")]")) {667 x = "//*[contains(text(),\""+arg1+"\")]";668 }else {669 x = "//*[contains(@*,\""+arg1+"\")]";670 }671 console.log(x);672 browser.click(x);673 browser.pause(3000);674 });675 //--------------Clicking button with ID676 this.When(/^I click on button having id as "([^"]*)"$/, function(arg1) { 677 try{678 var x = "//*[contains(@id, '"+arg1+"')]";679 browser.click(x);680 }catch(err){681 console.log(err);682 }683 });684 //##############-BUTTON VERIFY-########################## 685 //--------------Verify BUTTON STATUS is enabled686 this.Then(/^I verify button "([^"]*)" is enabled$/, function(arg1) {687 objGeneral.delay();688 var x;689 if(browser.isExisting("(//input[@type='submit' and @value='"+arg1+"'])[1]")){690 x = "(//input[@type='submit' and @value='"+arg1+"'])[1]";691 }else if(browser.isExisting("(//input[@type='button' and @value=\""+arg1+"\"])[1]")){692 x = "(//input[@type='button' and @value='"+arg1+"'])[1]";693 }else if(browser.isExisting("(//button[contains(text(),\""+ arg1 +"\")])[1]")){694 x = "(//button[contains(text(),\""+ arg1 +"\")])[1]";695 }else if(browser.isExisting("(//*[contains(text(),\""+ arg1 +"\")])[1]")){696 x = "(//*[contains(text(),\""+ arg1 +"\")])[1]";697 }else if(browser.isExisting("(//*[contains(.,\""+ arg1 +"\")])[1]")){698 x = "(//*[contains(.,\""+ arg1 +"\")])[1]";699 }else{700 //At times when it displays all caps but having InitCap inside HTML701 arg1 = arg1[0].toUpperCase() + arg1.substr(1).toLowerCase();702 x = "//input[@type='submit' and @value='"+arg1+"']";703 }704 console.log(x);705 //Once XPath is held, check if it is ENABLED706 try{707 expect(browser.isEnabled(x)).be.true;708 }catch(err){709 console.log(err);710 throw err;711 }712 });713 714 //--------------[OFFSHOOT-Occurrence]Verify BUTTON STATUS is enabled715 this.Then(/^I verify button "([^"]*)" occurrence "([^"]*)" is enabled$/, function(arg1, arg2) {716 objGeneral.delay();717 var x;718 if(browser.isExisting("(//input[@type='submit' and @value='"+arg1+"'])" + arg2)){719 x = "(//input[@type='submit' and @value='"+arg1+"'])" + arg2;720 }else if(browser.isExisting("(//input[@type='button' and @value=\""+arg1+"\"])" + arg2)){721 x = "(//input[@type='button' and @value='"+arg1+"'])" + arg2;722 }else if(browser.isExisting("(//button[contains(text(),\""+ arg1 +"\")])" + arg2)){723 x = "(//button[contains(text(),\""+ arg1 +"\")])" + arg2;724 }else if(browser.isExisting("(//*[contains(text(),\""+ arg1 +"\")])" + arg2)){725 x = "(//*[contains(text(),\""+ arg1 +"\")])" + arg2;726 }else if(browser.isExisting("(//*[contains(.,\""+ arg1 +"\")])" + arg2)){727 x = "(//*[contains(.,\""+ arg1 +"\")])" + arg2;728 }else{729 //At times when it displays all caps but having InitCap inside HTML730 arg1 = arg1[0].toUpperCase() + arg1.substr(1).toLowerCase();731 x = "(//input[@type='submit' and @value='"+arg1+"'])" + arg2;732 console.log("In final call");733 }734 console.log(x);735 //Once XPath is held, check if it is ENABLED736 try{737 expect(browser.isEnabled(x)).be.true;738 }catch(err){739 console.log(err);740 throw err;741 }742 });743 744 //--------------Verify BUTTON STATUS is disabled745 this.Then(/^I verify button "([^"]*)" is disabled$/, function(arg1) {746 objGeneral.delay();747 var x;748 if(browser.isExisting("(//input[@type='submit' and @value='"+arg1+"'])[1]")){749 x = "(//input[@type='submit' and @value='"+arg1+"'])[1]";750 }else if(browser.isExisting("(//input[@type='button' and @value=\""+arg1+"\"])[1]")){751 x = "(//input[@type='button' and @value='"+arg1+"'])[1]";752 }else if(browser.isExisting("(//button[contains(text(),\""+ arg1 +"\")])[1]")){753 x = "(//button[contains(text(),\""+ arg1 +"\")])[1]";754 }else if(browser.isExisting("(//*[contains(text(),\""+ arg1 +"\")])[1]")){755 x = "(//*[contains(text(),\""+ arg1 +"\")])[1]";756 }else if(browser.isExisting("(//*[contains(.,\""+ arg1 +"\")])[1]")){757 x = "(//*[contains(.,\""+ arg1 +"\")])[1]";758 }else{759 //At times when it displays all caps but having InitCap inside HTML760 arg1 = arg1[0].toUpperCase() + arg1.substr(1).toLowerCase();761 x = "//input[@type='submit' and @value='"+arg1+"']";762 }763 console.log(x); 764 765 //Once XPath is held, check if it is DISABLED766 try{767 expect(browser.isEnabled(x)).be.false;768 }catch(err){769 console.log(err);770 throw err;771 }772 });773 //--------------[OFFSHOOT-Occurrence]Verify BUTTON STATUS is disabled774 this.Then(/^I verify button "([^"]*)" occurrence "([^"]*)" is disabled$/, function(arg1, arg2) {775 objGeneral.delay();776 var x;777 if(browser.isExisting("(//input[@type='submit' and @value='"+arg1+"'])" + arg2)){778 x = "(//input[@type='submit' and @value='"+arg1+"'])" + arg2;779 }else if(browser.isExisting("(//input[@type='button' and @value=\""+arg1+"\"])" + arg2)){780 x = "(//input[@type='button' and @value='"+arg1+"'])" + arg2;781 }else if(browser.isExisting("(//button[contains(text(),\""+ arg1 +"\")])" + arg2)){782 x = "(//button[contains(text(),\""+ arg1 +"\")])" + arg2;783 }else if(browser.isExisting("(//*[contains(text(),\""+ arg1 +"\")])" + arg2)){784 x = "(//*[contains(text(),\""+ arg1 +"\")])" + arg2;785 }else if(browser.isExisting("(//*[contains(.,\""+ arg1 +"\")])" + arg2)){786 x = "(//*[contains(.,\""+ arg1 +"\")])" + arg2;787 }else{788 //At times when it displays all caps but having InitCap inside HTML789 arg1 = arg1[0].toUpperCase() + arg1.substr(1).toLowerCase();790 x = "(//input[@type='submit' and @value='"+arg1+"'])" + arg2;791 }792 console.log(x); 793 794 //Once XPath is held, check if it is DISABLED795 try{796 expect(browser.isEnabled(x)).be.false;797 }catch(err){798 console.log(err);799 throw err;800 }801 });802 803 //--------------Verify BUTTON EXISTS804 this.Then(/^I verify "([^"]*)" button exists$/, function(arg1) {805 var x;806 if(browser.isExisting("(//input[@type='submit' and @value='"+arg1+"'])[1]")){807 x = "(//input[@type='submit' and @value='"+arg1+"'])[1]";808 }else if(browser.isExisting("(//input[@type='button' and @value=\""+arg1+"\"])[1]")){809 x = "(//input[@type='button' and @value='"+arg1+"'])[1]";810 }else if(browser.isExisting("(//button[contains(text(),\""+ arg1 +"\")])[1]")){811 x = "(//button[contains(text(),\""+ arg1 +"\")])[1]";812 }else if(browser.isExisting("(//*[contains(text(),\""+ arg1 +"\")])[1]")){813 x = "(//*[contains(text(),\""+ arg1 +"\")])[1]";814 }else if(browser.isExisting("(//*[contains(.,\""+ arg1 +"\")])[1]")){815 x = "(//*[contains(.,\""+ arg1 +"\")])[1]";816 }else if(browser.isExisting("(//button//@*[contains(.,\""+arg1+"\")])[1]/..")){817 x = "(//button//@*[contains(.,\""+arg1+"\")])[1]/.."; 818 }else{819 //At times when it displays all caps but having InitCap inside HTML820 arg1 = arg1[0].toUpperCase() + arg1.substr(1).toLowerCase();821 x = "//input[@type='submit' and @value='"+arg1+"']";822 }823 console.log(x);824 expect(x).to.exist;825 objGeneral.delay();826 });827 //--------------[OFFSHOOT-Occurrence]Verify BUTTON EXISTS828 this.Then(/^I verify "([^"]*)" button exists occurrence "([^"]*)"$/, function(arg1,arg2) {829 objGeneral.delay();830 var x;831 if(browser.isExisting("(//input[@type='submit' and @value='"+arg1+"'])"+arg2)){832 x = "(//input[@type='submit' and @value='"+arg1+"'])"+arg2;833 }else if(browser.isExisting("(//input[@type='button' and @value=\""+arg1+"\"])"+arg2)){834 x = "(//input[@type='button' and @value='"+arg1+"'])"+arg2;835 }else if(browser.isExisting("(//button[contains(text(),\""+ arg1 +"\")])"+arg2)){836 x = "(//button[contains(text(),\""+ arg1 +"\")])"+arg2;837 }else if(browser.isExisting("(//*[contains(.,\""+ arg1 +"\")])"+arg2)){838 x = "(//*[contains(.,\""+ arg1 +"\")])"+arg2;839 }else if(browser.isExisting("(//*[contains(text(),\""+ arg1 +"\")])"+arg2)){840 x = "(//*[contains(text(),\""+ arg1 +"\")])"+arg2;841 //At times when it displays all caps but having InitCap inside HTML842 }else{843 arg1 = arg1[0].toUpperCase() + arg1.substr(1).toLowerCase();844 x = "//input[@type='submit' and @value='"+arg1+"']"+arg2;845 }846 console.log(x);847 expect(x).to.exist; 848 });849 //##############-LINK-CLICK-########################## 850 //--------------Clicking Hyper Link851 this.When(/^I click on "([^"]*)"$/, function (arg1) {852 arg1 = objGeneral.analyzeValue(arg1);853 var x;854 if(browser.isExisting("//a//*[contains(text(),\""+arg1+"\")][1]")) {855 x = "//a//*[contains(text(),\""+arg1+"\")][1]";856 }else if(browser.isExisting("//descendant::a[contains(.,\""+arg1+"\")][1]")) {857 x = "//descendant::a[contains(.,\""+arg1+"\")][1]";858 }else if(browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]")) {859 x = "//descendant::*[text()=\""+arg1+"\"][1]";860 }else {861 x = "(//descendant::*[contains(text(),\""+arg1+"\")])[1]";862 }863 console.log(x);864 browser.click(x);865 objGeneral.delay();866 });867 //--------------[OFFSHOOT-Occurrence]Clicking Hyper Link - thro OFFSET868 this.When(/^I click "([^"]*)" field"([^"]*)"$/, function (arg1, arg2) {869 var x;870 if(browser.isExisting("//descendant::*[text()=\""+arg1+"\"]/following::input" + arg2)) {871 x = "//descendant::*[text()=\""+arg1+"\"]/following::input" + arg2;872 }else {873 x = "(//descendant::*[contains(text(),\""+arg1+"\")])/following::input" + arg2;874 }875 console.log(x);876 browser.click(x);877 });878 879 //--------------Clicking Hyper Link (nth Occurrence)880 this.Then(/^I click on "([^"]*)" link occurrence "([^"]*)"$/, function(arg1, arg2) {881 var x;882 if(browser.isExisting("(//descendant::a[text()=\""+arg1+"\"])"+arg2)) {883 x = "(//descendant::a[text()=\""+arg1+"\"])"+arg2;884 }else if (browser.isExisting("(//descendant::a[contains(text(),\""+arg1+"\")])"+arg2)) {885 x = "(//descendant::a[contains(text(),\""+arg1+"\")])"+arg2;886 }else {887 x = "(//descendant::a[contains(.,\""+arg1+"\")])"+arg2;888 }889 console.log(x);890 browser.click(x);891 });892 893 //--------------Move to Hyper Link894 this.When(/^I move to link "([^"]*)"$/, function (arg1) {895 var x;896 if(browser.isExisting("//descendant::a[text()=\""+arg1+"\"]")) {897 x = "//descendant::a[text()=\""+arg1+"\"]";898 }else if(browser.isExisting("//descendant::*[text()=\""+arg1+"\"]")) {899 x = "//descendant::*[text()=\""+arg1+"\"]";900 }else {901 x = "//descendant::*[contains(text(),\""+arg1+"\")]";902 }903 console.log(x);904 browser.moveToObject(x,0,0);905 });906 //--------------Move to Hyper Link (nth Occurrence)907 this.When(/^I move to link "([^"]*)" occurrence "([^"]*)"$/, function (arg1, arg2) {908 var x;909 if(browser.isExisting("(//descendant::a[text()=\""+arg1+"\"])"+arg2)) {910 x = "(//descendant::a[text()=\""+arg1+"\"])"+arg2;911 }else if(browser.isExisting("(//descendant::*[text()=\""+arg1+"\"])"+arg2)) {912 x = "(//descendant::*[text()=\""+arg1+"\"])"+arg2;913 }else {914 x = "(//descendant::*[contains(text(),\""+arg1+"\")])"+arg2;915 }916 console.log(x);917 browser.moveToObject(x,0,0);918 });919 //--------------Click in HYPERLINK following label920 this.When(/^I click on link following "([^"]*)" text$/, function (arg1) {921 arg1 = objGeneral.analyzeValue(arg1);922 var x;923 if(browser.isExisting("(//*[text()= \""+arg1+"\"]/following::a)[1]")) {924 x = "(//*[text()= \""+arg1+"\"]/following::a)[1]";925 } else {926 x = "(//*[contains(text(), \""+arg1+"\")]/following::a)[1]";927 }928 console.log(x);929 browser.click(x);930 });931 //--------------[OFFSHOOT-Occurrence]Click in HYPERLINK following label932 this.When(/^I click on link following "([^"]*)" occurrence "([^"]*)" text$/, function (arg1, arg2) {933 var x;934 if(browser.isExisting("(//*[text()= \""+arg1+"\"]) " + arg2 + " /following::a[1]")) {935 x = "(//*[text()= \""+arg1+"\"]) " + arg2 + " /following::a[1]";936 } else {937 x = "(//*[contains(text(), \""+arg1+"\")])" + arg2 + "/following::a[1]";938 }939 console.log(x);940 browser.click(x);941 });942 943 //------------Click element that is before text944 this.Then(/^I click element before the text "([^"]*)"$/, function(arg1) {945 arg1 = objGeneral.analyzeValue(arg1);946 if(browser.isExisting("(//*[contains(text(),\""+arg1+"\")])[1]//preceding::*[1]")){947 var x = "(//*[contains(text(),\""+arg1+"\")])[1]//preceding::*[1]";948 }else {949 var x = "(//*[contains(.,\""+arg1+"\")])[1]//preceding::*[1]";950 } 951 console.log(x);952 browser.click(x);953 objGeneral.delay();954 });955 //------------[OFFSHOOT-Occurrence]Click element that is after text956 this.Then(/^I click element after the text "([^"]*)"$/, function(arg1) {957 arg1 = objGeneral.analyzeValue(arg1);958 if(browser.isExisting("(//*[contains(text(),\""+arg1+"\")])[1]//following::*[1]")){959 var x = "(//*[contains(text(),\""+arg1+"\")])[1]//following::*[1]";960 }else {961 var x = "(//*[contains(.,\""+arg1+"\")])[1]//following::*[1]";962 } 963 console.log(x);964 browser.click(x);965 objGeneral.delay();966 });967 968 //--------------Click in ICON preceding label e.g. expand icon before Status969 this.When(/^I click on icon preceding "([^"]*)" text$/, function (arg1) {970 var x;971 972 if(browser.isExisting("//*[contains(text(),\""+arg1+"\")]/preceding::icon")) {973 x = "//*[contains(text(),\""+arg1+"\")]/preceding::icon";974 } else {975 x = "//*[contains(.,\""+arg1+"\")]/preceding::icon";976 }977 console.log(x);978 browser.click(x);979 });980 //--------------Click in <BELL> ICON e.g. Bell, Folder981 this.When(/^I click on "([^"]*)" icon$/, function (arg1) {982 var x;983 if(browser.isExisting("(//a//*[contains(@class,\""+arg1+"\")])[1]")) {984 x = "(//a//*[contains(@class,\""+arg1+"\")])[1]";985 }else {986 x = "(//*[contains(@class,\""+arg1+"\")])[1]";987 }988 console.log(x);989 browser.click(x);990 });991 992 //--------------Click in HYPERLINK following ICON e.g. Calendar Date icon993 this.When(/^I click on link following "([^"]*)" icon$/, function (arg1) {994 var x;995 if(browser.isExisting("//*[contains(@*,\""+arg1+"\")]/following::a")) {996 x = "//*[contains(@*,\""+arg1+"\")]/following::a";997 console.log(x);998 browser.click(x);999 }else {1000 console.log("Link does not exist");1001 expect(true).to.be.true;1002 }1003 });1004 1005 //--------------Click in a <value> inside a field. e.g. Date that shows calendar and user clicks a date in it.1006 this.When(/^I click "([^"]*)" in "([^"]*)" field$/, function (arg1, arg2) {1007 var x;1008 if(browser.isExisting("//*[contains(text(),\""+arg2+"\")]/following::*[text()=\""+arg1+"\"][1]")) {1009 x = "//*[contains(text(),\""+arg2+"\")]/following::*[text()=\""+arg1+"\"][1]";1010 }else{1011 x = "//*[contains(text(),\""+arg2+"\")]/following::*[contains(text(),\""+arg1+"\")][1]";1012 }1013 console.log(x);1014 browser.click(x);1015 });1016 1017 //##############-PAGE-VERIFY-########################## 1018 //--------------Verify Page Title1019 this.Then(/^I verify the page title "([^"]*)"$/, function(arg1) {1020 objGeneral.delay();1021 expect(browser.getTitle()).to.contain(arg1);1022 console.log("I got title: "+ browser.getTitle());1023 });1024 1025 this.Then(/^I wait until "([^"]*)" appears$/, function(arg1) {1026 var x;1027 objGeneral.delay();1028 x = "(//*[contains(text(),\""+arg1+"\")])[1]";1029 browser.waitUntil(function (x, arg1) {return browser.getText("(//*[contains(text(),\""+arg1+"\")])[1]") === arg1}, 55000, 'Expec 5s', 500);1030 });1031 1032 //--------------Verify Page Text1033 this.Then(/^I verify the page text to contain "([^"]*)"$/, function(arg1) {1034 var x;1035 arg1 = objGeneral.analyzeValue(arg1);1036 objGeneral.delay();1037 //x = "(//*[contains(text(),\""+arg1+"\")])[1]";1038 if(browser.isExisting("(//*[contains(text(),\""+arg1+"\")])[1]")) {1039 x = "(//*[contains(text(),\""+arg1+"\")])[1]";1040 }else{1041 x = "(//*[contains(.,\""+arg1+"\")])[last()]";1042 }1043 console.log(x);1044 try{1045 var str = browser.getText(x);1046 console.log(str);1047 try {1048 expect(str).to.contain(arg1);1049 } catch (err) {1050 throw err;1051 }1052 }catch(err){ //Goes here only if object is not there1053 //const doesExist = browser.waitForExist(x);1054 var error = new Error(arg1);1055 error.name = "Assertion Failed";1056 throw error;1057 //expect(doesExist).toBe(true); 1058 }1059 });1060 //--------------[OFFSHOOT-Occurrence] Verify Page Text ON OCCURRENCE1061 this.Then(/^I verify the page text to contain "([^"]*)" occurrence "([^"]*)"$/, function(arg1,arg2) {1062 objGeneral.delay();1063 arg1 = objGeneral.analyzeValue(arg1);1064 var x = "(//*[contains(text(),\""+arg1+"\")])"+arg2;1065 console.log(x);1066 var str = browser.getText(x);1067 console.log(str);1068 try{1069 expect(str).to.contain(arg1);1070 } catch(err){1071 expect(str[0]).to.contain(arg1);1072 }1073 });1074 1075 //--------------Verify Page Text not contains1076 this.Then(/^I verify the page text to not contain "([^"]*)"$/, function(arg1) {1077 objGeneral.delay();1078 arg1 = objGeneral.analyzeValue(arg1);1079 var x = "(//*[contains(text(),\""+arg1+"\")])[1]";1080 var str = "xxxx";1081 try{1082 str = browser.getText(x);1083 expect(str).to.not.exist;1084 }catch(err){1085 console.log("Text not found: " + arg1);1086 }1087 });1088 1089 //--------------Verify value of field on the page (not a TextBox)1090 this.Then(/^I verify value "([^"]*)" for label "([^"]*)"$/, function(arg1, arg2) {1091 arg2 = objGeneral.analyzeValue(arg2);1092 arg1 = objGeneral.analyzeValue(arg1);1093 if(browser.isExisting("(//descendant::*[text()='"+arg2+"'])[1]/following::*[1]")){1094 var x = "(//*[text()='"+arg2+"'])[1]/following::*[1]";1095 }else if(browser.isExisting("//*[contains(text(),'"+arg2+"')]//following::*[1]")){1096 var x="(//*[contains(text(),'"+arg2+"')]//following::*)[1]";1097 }else {1098 var x = "(//descendant::*[contains(.,'"+arg2+"')])[1]/following::*[1]";1099 }1100 console.log(x);1101 var value = objGeneral.analyzeValue(arg1);1102 try{1103 expect(browser.getText(x)).to.be.eql(value);1104 }catch(err){1105 console.log("contains and not exact match: " + browser.getText(x));1106 expect(browser.getText(x)).to.have.string(value);1107 }1108 });1109 //--------------Verify value of field NOT TO BE on the page (not a TextBox)1110 this.Then(/^I verify value "([^"]*)" not found for label "([^"]*)"$/, function(arg1, arg2) {1111 if(browser.isExisting("(//descendant::*[text()='"+arg2+"'])[1]/following::*[1]")){1112 var x = "(//*[text()='"+arg2+"'])[1]/following::*[1]";1113 }else if(browser.isExisting("//*[contains(text(),'"+arg2+"')]//following::*[1]")){1114 var x="(//*[contains(text(),'"+arg2+"')]//following::*)[1]";1115 }else {1116 var x = "(//descendant::*[contains(.,'"+arg2+"')])[1]/following::*[1]";1117 }1118 console.log(x);1119 var value = objGeneral.analyzeValue(arg1);1120 expect(browser.getText(x)).to.not.eql(value);1121 });1122 1123 //--------------Extract value of field on the page (not a TextBox) to Save1124 this.Then(/^I extract value for label "([^"]*)" and save to "([^"]*)"$/, function(arg1, arg2) {1125 if(browser.isExisting("(//descendant::*[text()='"+arg1+"'])[1]/following::*[1]")){1126 var x = "(//*[text()='"+arg1+"'])[1]/following::*[1]";1127 }else if(browser.isExisting("//*[contains(text(),'"+arg1+"')]//following::*[1]")){1128 var x="(//*[contains(text(),'"+arg1+"')]//following::*)[1]";1129 }else {1130 var x = "(//descendant::*[contains(.,'"+arg1+"')])[1]/following::*[1]";1131 }1132 console.log(x);1133 console.log(browser.getText(x));1134 objGeneral.saveDataToFile(arg2,browser.getText(x));1135 });1136 //--------------Verifying text in a page section1137 this.Then(/^In section "([^"]*)" I verify existence of text "([^"]*)"$/, function(arg1, arg2){1138 objGeneral.delay();1139 arg2 = objGeneral.analyzeValue(arg2);1140 if(browser.isExisting("//*[contains(text(), \""+arg1+"\")]//../following-sibling::*/descendant::*[contains(text(), \""+arg2+"\")][1]")){1141 var x = "//*[contains(text(), \""+arg1+"\")]//../following-sibling::*/descendant::*[contains(text(), \""+arg2+"\")][1]";1142 } else{1143 var x = "//*[contains(text(), \""+ arg1 +"\")]//../following-sibling::*[contains(text(), \""+arg2+"\")][1]";1144 }1145 console.log(browser.getText(x));1146 expect(browser.getText(x)).to.contain(arg2);1147 });1148 //--------------[OFFSHOOT-Occurrence]Verifying text in a page section occurrence1149 this.Then(/^In section "([^"]*)" I verify existence of text "([^"]*)" occurrence "([^"]*)"$/, function(arg1, arg2, arg3){1150 objGeneral.delay();1151 arg2 = objGeneral.analyzeValue(arg2);1152 if(browser.isExisting("//*[contains(text(), \""+arg1+"\")]//../following-sibling::*/descendant::*[contains(text(), \""+arg2+"\")]" + arg3)){1153 var x = "//*[contains(text(), \""+arg1+"\")]//../following-sibling::*/descendant::*[contains(text(), \""+arg2+"\")]" + arg3;1154 } else{1155 var x = "//*[contains(text(), \""+ arg1 +"\")]//../following-sibling::*[contains(text(), \""+arg2+"\")]" + arg3;1156 }1157 console.log(browser.getText(x));1158 expect(browser.getText(x)).to.contain(arg2);1159 });1160 1161 //--------------Extract value from an Textbox and SAVE to File :udhay1162 //[e.g.] from Name text box and save to "1.txt/prop1"1163 this.Then(/^I extract from textbox "([^"]*)" and save to "([^"]*)"$/, function(arg1, arg2) {1164 var x;1165 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"][1]/following::input[1]")) {1166 x = "//descendant::label[text()=\""+arg1+"\"][1]/following::input[1]";1167 }else if (browser.isExisting("//descendant::td[text()=\""+arg1+"\"][1]/following::input[1]")) {1168 x = "//descendant::td[text()=\""+arg1+"\"][1]/following::input[1]";1169 }else if (browser.isExisting("//descendant::td//*[text()=\""+arg1+"\"][1]/following::input[1]")) {1170 x = "//descendant::td//*[text()=\""+arg1+"\"][1]/following::input[1]";1171 }else if (browser.isExisting("//descendant::*[text()=\""+arg1+"\"][1]/following::input[1]")) {1172 x = "//descendant::*[text()=\""+arg1+"\"][1]/following::input[1]";1173 }else {1174 x = "//descendant::*[contains(text(),\""+arg1+"\")][1]/following::input[1]";1175 }1176 console.log(x);1177 console.log(browser.getValue(x));1178 objGeneral.saveDataToFile(arg2,browser.getValue(x));1179 }); 1180 1181 //--------------[OFFSHOOT-Occurrence] Extract value from an Textbox and SAVE to File: OCCURRENCE 1182 //[e.g.] from Name[2] text box and save to "1.txt/prop1"1183 this.Then(/^I extract from textbox "([^"]*)" occurrence "([^"]*)" and save to "([^"]*)"$/, function(arg1, arg2, arg3) {1184 var x;1185 if(browser.isExisting("//descendant::label[text()=\""+arg1+"\"]"+arg2+"/following::input[1]")) {1186 x = "//descendant::label[text()=\""+arg1+"\"]"+arg2+"/following::input[1]";1187 }else if (browser.isExisting("(//descendant::td[text()=\""+arg1+"\"])"+arg2+"/following::input[1]")) {1188 x = "(//descendant::td[text()=\""+arg1+"\"])"+arg2+"/following::input[1]";1189 }else if (browser.isExisting("(//descendant::td//*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]")) {1190 x = "(//descendant::td//*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]";1191 }else if (browser.isExisting("(//descendant::*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]")) {1192 x = "(//descendant::*[text()=\""+arg1+"\"])"+arg2+"/following::input[1]";1193 }else {1194 x = "(//descendant::*[contains(text(),\""+arg1+"\")])"+arg2+"/following::input[1]";1195 } 1196 console.log(x);1197 console.log(browser.getValue(x));1198 objGeneral.saveDataToFile(arg3,browser.getValue(x));1199 }); 1200 //--------------Extract value between LB and RB and SAVE to File1201 //[e.g.] getCount of Roles created LB: "SYSTEM(" and ")"1202 ////*[contains(text(),"System (")]1203 this.Then(/^I extract the text between "([^"]*)" and "([^"]*)" and save to "([^"]*)"$/, function(arg1, arg2, arg3) {1204 arg1 = objGeneral.analyzeValue(arg1);1205 if(browser.isExisting("(//*[contains(text(),\""+ arg1 +"\")])[1]")){1206 var x = "(//*[contains(text(),\""+ arg1 +"\")])[1]";1207 }else {1208 var x = "(//*[contains(text(),\""+ arg1 +"\")])[1]";1209 }1210 console.log(x);1211 console.log("***** "+browser.getText(x));1212 var s1 = browser.getText(x).split(arg1)[1];1213 var s2 = s1.split(arg2)[0];1214 console.log('***** '+s2);1215 objGeneral.saveDataToFile(arg3,s2);1216 });1217 1218 //--------------[OFFSHOOT-Occurrence]Extract value between LB and RB and SAVE to File with OCCURRENCE1219 ////*[contains(text(),"SAR-2017")]1220 this.Then(/^I extract the text between "([^"]*)""([^"]*)" and "([^"]*)" and save to "([^"]*)"$/, function(arg1, arg2, arg3, arg4) {1221 arg1 = objGeneral.analyzeValue(arg1);1222 if(browser.isExisting("(//*[contains(text(),\""+ arg1 +"\")])" + arg2)){1223 var x = "(//*[contains(text(),\""+ arg1 +"\")])" + arg2;1224 }else {1225 var x = "(//*[contains(text(),\""+ arg1 +"\")])" + arg2;1226 }1227 console.log(x);1228 console.log(browser.getText(x));1229 var s1 = browser.getText(x).split(arg1)[1];1230 var s2 = s1.split(arg3)[0];1231 console.log(s2);1232 objGeneral.saveDataToFile(arg4,s2);1233 });1234 //--------------Verify text between LB and RB (that follows a text) to a value (that follows a TEXT)1235 //[e.g.] getCount of Auditor: "Number of permissions: 2"1236 //(//*[contains(text(),"AUDITOR")])[1]/following::*[contains(text(),"No. of permissions:")]1237 1238 this.Then(/^I verify for "([^"]*)" the text between "([^"]*)" and "([^"]*)" to be "([^"]*)"$/, function(arg1, arg2, arg3, arg4) {1239 if(browser.isExisting("((//*[contains(text(),\""+ arg1 +"\")])[1]/following::*[contains(text(),\""+arg2+"\")])[1]")){1240 var x = "((//*[contains(text(),\""+ arg1 +"\")])[1]/following::*[contains(text(),\""+arg2+"\")])[1]";1241 }else {1242 var x = "((//*[contains(text(),\""+ arg1 +"\")])[1]/following::*[contains(.,\""+arg2+"\")])[1]";1243 }1244 console.log(x);1245 console.log(browser.getText(x));1246 var s1 = browser.getText(x).split(arg2)[1];1247 var s2 = s1.split(arg3)[0];1248 console.log(s2);1249 expect(s2).to.contain(arg4);1250 });1251 1252 //--------------Extract value between LB and RB and SAVE to File (that follows a TEXT)1253 //[e.g.] getCount of "Number of permissions: 2"1254 //(//*[contains(text(),"AUDITOR")])[1]/following::*[contains(text(),"No. of permissions:")]1255 1256 this.Then(/^I extract for "([^"]*)" the text between "([^"]*)" and "([^"]*)" and save to "([^"]*)"$/, function(arg1, arg2, arg3, arg4) {1257 arg1 = objGeneral.analyzeValue(arg1);1258 if(browser.isExisting("((//*[contains(text(),\""+ arg1 +"\")])[1]/following::*[contains(text(),\""+arg2+"\")])[1]")){1259 var x = "((//*[contains(text(),\""+ arg1 +"\")])[1]/following::*[contains(text(),\""+arg2+"\")])[1]";1260 }else {1261 var x = "((//*[contains(text(),\""+ arg1 +"\")])[1]/following::*[contains(.,\""+arg2+"\")])[1]";1262 }1263 console.log(x);1264 console.log(browser.getText(x));1265 var extracted = browser.getText(x).split(arg2)[1];1266 console.log(extracted);1267 objGeneral.saveDataToFile(arg4,extracted);1268 });1269 1270 //##############-EXTRACT AND VERIFY-########################## 1271 //-------------Extract and Verify1272 this.Then(/^I extract "([^"]*)" from file "([^"]*)" and verify as "([^"]*)"$/, function(arg1,arg2,arg3) {1273 try{1274 objGeneral.delay();1275 var value = prop.createEditor(arg2).get(arg1);1276 console.log("I got UI:*****************"+ value);1277 console.log("Value passed:*****************"+ arg3);1278 expect(arg3).to.contain(value);1279 }catch(err){1280 console.log(err);1281 }1282 }); 1283 //--------------Verify Page Title Contains1284 this.Then(/^I enter extracted "([^"]*)" from file "([^"]*)" and verify the page title contains the same$/, function(arg1, arg2) {1285 objGeneral.delay();1286 var value = prop.createEditor(arg2).get(arg1); 1287 expect(browser.getTitle()).to.contain(value);1288 console.log("I got title: "+ browser.getTitle());1289 }); 1290 1291 //-------------Verifying text in a page section with extracted property from a file1292 this.Then(/^in section "([^"]*)" I verify existence of extracted text "([^"]*)"$/, function(arg1, arg2){1293 objGeneral.delay();1294 var fileName = arg2.split("/")[0];1295 console.log("fileName is "+fileName);1296 var strProp = arg2.split("/")[1];1297 console.log("key is "+strProp);1298 var value = prop.createEditor(fileName).get(strProp);1299 console.log("value is "+value);1300 var x = "//*[contains(text(), \""+arg1+"\")]//../following-sibling::*/descendant::*[contains(text(), \""+value+"\")][1]";1301 console.log(x);1302 console.log(browser.getText(x));1303 expect(browser.getText(x)).to.contain(value);1304 });1305 //##############-FILE EXTRACTS ALONE AND VERIFY-########################## 1306 //-------------File Extract and Verify1307 this.Then(/^I verify "([^"]*)" of "([^"]*)" and "([^"]*)" to be "([^"]*)"$/, function (arg1, arg2, arg3, arg4) {1308 var value=parseInt(objGeneral.retrieveDataFromFile(arg2));1309 var value1=parseInt(objGeneral.retrieveDataFromFile(arg3));1310 if (arg1 === "difference"){1311 var result = value - value1;1312 console.log("result:" + result);1313 expect(result).to.equal(parseInt(arg4));1314 }else if (arg1 === "similarity") {1315 expect(value).to.be.eql(value1);1316 }else if (arg1 === "dissimilarity") {1317 expect(arg2).to.not.eql(arg3);1318 }1319 objGeneral.delay();1320 });1321 //##############-PAGE-EXTRACT-##########################1322 //-------------Extracting value before a pattern and SAVING to file1323 this.Then(/^I extract "([^"]*)" before the pattern "([^"]*)" and save to "([^"]*)"$/, function (arg1, arg2, arg3) {1324 1325 objGeneral.delay();1326 var x = "//*[1][contains(text(), '"+arg2+"')]";1327 console.log(x);1328 var str = browser.getText(x)1329 1330 var res = str.split("'");1331 var value = res[1];1332 console.log(res);1333 console.log(value);1334 1335 var editor1 = prop.createEditor();1336 editor1.set(arg1,value);1337 editor1.save(arg3);1338 });1339 1340 //-------------Extracting value after a pattern (with occurrence) and SAVING to file1341 this.Then(/^I extract text after the pattern "([^"]*)" occurrence "([^"]*)" and save to file "([^"]*)"$/, function (arg1, arg2, arg3) {1342 if(browser.isExisting("((//*[contains(text(), \""+arg1+"\")])"+ arg2 + "/descendant::*)[1]")){1343 var x = "((//*[contains(text(), \""+arg1+"\")])"+ arg2 + "/descendant::*)[1]";1344 }else {1345 var x = "((//*[contains(text(), \""+arg1+"\")])"+ arg2 + "/following::*)[1]";1346 }1347 objGeneral.delay();1348 console.log(x);1349 var str = browser.getText(x)1350 objGeneral.saveDataToFile(arg3,browser.getText(x));1351 });1352 //##############-MISCELLANEOUS-##########################1353 //-------------Delete Cookies1354 this.Then(/^I delete Cookies$/, function () {1355 browser.deleteCookie();1356 objGeneral.delay();1357 });1358 //-------------Just a casual wait1359 this.Then(/^Browser Ending Actions$/, function () {1360 objGeneral.delay();1361 });1362 //-------------Explicit sleep from Feature file author1363 this.Then(/^I wait for "([^"]*)"$/, function (arg1) {1364 arg1 = objGeneral.analyzeValue(arg1);1365 sleep(arg1);1366 });1367 //-------------Moving the focus to new iFRAME1368 this.Then(/^Set the focus on new frame$/, function () {1369 browser.frame(0);1370 });1371 //-------------Scroll to a 'Y' position----1372 this.Then(/^Scroll the window to "([^"]*)"$/, function (arg1) { 1373 var y=Number(arg1);1374 browser.scroll(0,y);1375 });1376 //-------------Scroll to a Web element----1377 this.Then(/^Scroll the window to field "([^"]*)"$/, function (arg1) { 1378 var x;1379 if(browser.isExisting("(//descendant::*[text()='"+arg1+"'])[1]")) {1380 x = "(//descendant::*[text()='"+arg1+"'])[1]";1381 console.log(x);1382 browser.scroll(x);1383 }else if (browser.isExisting("(//descendant::*[contains(text(),\""+arg1+"\")])[1]")) {1384 x = "(//descendant::*[contains(text(),\""+arg1+"\")])[1]";1385 console.log(x);1386 browser.scroll(x);1387 }1388 });1389 //-------------Print Screenshot----1390 this.Then(/^I take screenshot to file "([^"]*)"$/, function (arg1) { 1391 objscreencapture(arg1, function (err, imagePath) {1392 console.log('Screenshot taken to ' + imagePath); 1393 })1394 });1395 //-------------Upload a File and ATTACHMENTS----1396 this.Then(/^I upload file "([^"]*)" to "([^"]*)"$/, function (arg1, arg2) {1397 arg1 = objGeneral.analyzeValue(arg1);1398 browser.chooseFile("//*[contains(text(),\""+ arg2 +"\")]/descendant::input[contains(@type,\"file\")]",arg1);1399 objGeneral.delay();1400 });1401 //-------------Download a File and ATTACHMENT----1402 this.Then(/^I download file "([^"]*)" to "([^"]*)"$/, function (arg1, arg2) {1403 browser.chooseFile("//*[contains(text(),\""+ arg2 +"\")]/descendant::input[contains(@type,\"file\")]",arg1);1404 objGeneral.delay();1405 });1406 //-------------Passing a Key e.g. ENTER, BACKSPACE----1407 this.Then(/^I key press "([^"]*)"$/, function (arg1) { 1408 arg1 = objGeneral.analyzeValue(arg1);1409 browser.keys(arg1);1410 objGeneral.delay();1411 });1412 //-------------Getting a count of collection (of XPATH output) and save to file1413 this.Then(/^I get count of "([^"]*)" and save to "([^"]*)"$/, function (arg1, arg2) { 1414 var x;1415 var outArray;1416 try{1417 x = "//*[contains(text(),\"" + arg1 + "\")]";1418 console.log(x);1419 outArray = browser.getText(x);1420 console.log("The count is " + outArray.length);1421 objGeneral.saveDataToFile(arg2, outArray.length);1422 }catch(err){1423 console.log("The count is 0");1424 objGeneral.saveDataToFile(arg2, 0);1425 }1426 });1427 1428 //##############-MULTILINE TEXT-##########################1429 //-------------Filling Multiline Text-----//1430 this.Then(/^I enter multiline text in "([^"]*)" as "([^"]*)"$/, function(arg1, arg2) {1431 var value = objGeneral.analyzeValue(arg2); var x;1432 if(browser.isExisting("//descendant::label[text()='"+arg1+"'][1]/following::textarea[1]")) {1433 x = "//descendant::label[text()='"+arg1+"'][1]/following::textarea[1]";1434 }else if (browser.isExisting("//descendant::td[text()='"+arg1+"'][1]/following::textarea[1]")) {1435 x = "//descendant::td[text()='"+arg1+"'][1]/following::textarea[1]";1436 }else if (browser.isExisting("//descendant::td//*[text()='"+arg1+"'][1]/following::textarea[1]")) {1437 x = "//descendant::td//*[text()='"+arg1+"'][1]/following::textarea[1]";1438 }else if (browser.isExisting("//descendant::*[text()='"+arg1+"'][1]/following::textarea[1]")) {1439 x = "//descendant::*[text()='"+arg1+"'][1]/following::textarea[1]";1440 }else {1441 x = "//descendant::*[contains(text(),'"+arg1+"')][1]/following::textarea[1]";1442 }1443 console.log(x);1444 browser.setValue(x,value);1445 });1446 1447 //-------------[OFFSHOOT-Occurrence] Filling Multiline Text-----//1448 this.Then(/^I enter multiline text in "([^"]*)" occurrence of "([^"]*)" as "([^"]*)"$/, function(arg1, arg2,arg3) {1449 var value = objGeneral.analyzeValue(arg3); var x;1450 if(browser.isExisting("//descendant::label[text()='"+arg1+"']"+arg2+"/following::textarea[1]")) {1451 x = "//descendant::label[text()='"+arg1+"']"+arg2+"/following::textarea[1]";1452 }else if (browser.isExisting("//descendant::td[text()='"+arg1+"']"+arg2+"/following::textarea[1]")) {1453 x = "//descendant::td[text()='"+arg1+"']"+arg2+"/following::textarea[1]";1454 }else if (browser.isExisting("//descendant::td//*[text()='"+arg1+"']"+arg2+"/following::textarea[1]")) {1455 x = "//descendant::td//*[text()='"+arg1+"']"+arg2+"/following::textarea[1]";1456 }else if (browser.isExisting("//descendant::*[text()='"+arg1+"']"+arg2+"/following::textarea[1]")) {1457 x = "//descendant::*[text()='"+arg1+"']"+arg2+"/following::textarea[1]";1458 }else {1459 x = "//descendant::*[contains(text(),'"+arg1+"')]"+arg2+"/following::textarea[1]";1460 }1461 console.log(x);1462 browser.setValue(x,value);1463 });1464 1465 //-------------TO VERIFY Multiline TEXTAREA item exists-----//1466 this.Then(/^I verify multiline text "([^"]*)" exists$/, function(arg1) {1467 var x;1468 if (browser.isExisting("//descendant::*[text()='"+arg1+"'][1]/following::textarea[1]")) {1469 x = "//descendant::*[text()='"+arg1+"'][1]/following::textarea[1]";1470 }else {1471 x = "//descendant::*[contains(text(),'"+arg1+"')][1]/following::textarea[1]";1472 }1473 console.log(x);1474 expect(x).to.exist;1475 });1476 //-------------[OFFSHOOT-Occurrence]TO VERIFY Multiline TEXTAREA item exists-----//1477 this.Then(/^I verify multiline text "([^"]*)" occurrence "([^"]*)" exists$/, function(arg1, arg2) {1478 var x;1479 if (browser.isExisting("//descendant::*[text()='"+arg1+"']" + arg2 + "/following::textarea[1]")) {1480 x = "//descendant::*[text()='"+arg1+"']" + arg2 + "/following::textarea[1]";1481 }else {1482 x = "//descendant::*[contains(text(),'"+arg1+"')]" + arg2 + "/following::textarea[1]";1483 }1484 console.log(x);1485 expect(x).to.exist;1486 });1487 1488 //##############-ALERT-########################## 1489 //-------------Accept alert1490 this.When(/^I accept following alert$/, function() {1491 try{1492 browser.alertAccept();1493 }catch(err){...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

...36 var subtitle = yield browser.getText('#hp header h2')37 subtitle.should.be.equal(sandbox.general.subtitle);38 });39 it('should have a link to the home page', function *() {40 var link = yield browser.isExisting('#hp header a[href="/"]');41 link.should.be.equal(true);42 var linkText = yield browser.getText('#hp header a[href="/"]');43 linkText.should.be.equal(sandbox.general.title);44 });45 it('should have a link to the settings page', function *() {46 var link = yield browser.isExisting('ul.nav > li > a');47 link.should.be.equal(true);48 var linkText = yield browser.getText('ul.nav > li > a')49 linkText.should.be.equal('Settings');50 });51 it('should have a form to enable downloading a file', function *() {52 var form = yield browser.isExisting('.download form');53 form.should.be.equal(true);54 var action = yield browser.getAttribute('.download form', 'action');55 should.exist(action);56 action.should.be.equal(sandbox.general.baseUrl + '/download');57 var submit = yield browser.isExisting('.download form button[type=submit]');58 submit.should.be.equal(true);59 });60 it('should not have a form to enable downloading a file if this feature is disabled', function *() {61 var currentValue = sandbox.general.enableDownload;62 if(currentValue) {63 var enableDownload = yield browser.click('ul.nav > li > a')64 .click('input#enableDownload')65 .submitForm('.tab-pane.active form')66 .waitForExist('.tab-pane.active .alert strong', 5000)67 .isExisting('input#enableDownload:checked');68 enableDownload.should.be.equal(false);69 }70 var download = yield browser.url('/')71 .isExisting('.download');72 download.should.be.equal(false);73 var form = yield browser.url('/')74 .isExisting('.download form');75 form.should.be.equal(false);76 var submit = yield browser.url('/')77 .isExisting('.download form button[type=submit]');78 submit.should.be.equal(false);79 if(currentValue) {80 var enableDownload = yield browser.click('ul.nav > li > a')81 .click('input#enableDownload')82 .submitForm('.tab-pane.active form')83 .waitForExist('.tab-pane.active .alert strong', 5000)84 .isExisting('input#enableDownload:checked');85 enableDownload.should.be.equal(true);86 }87 });88 it('should have a form to enable downloading a file which throws an error when trying to exploit path traversal', function *() {89 var form = yield browser.isExisting('.download form');90 form.should.be.equal(true);91 var action = yield browser.getAttribute('.download form', 'action');92 should.exist(action);93 action.should.be.equal(sandbox.general.baseUrl + '/download');94 var submit = yield browser.isExisting('.download form button[type=submit]');95 submit.should.be.equal(true);96 var error = yield browser.setValue('input[name="token"]', '../config')97 .submitForm('.download form button[type=submit]')98 .waitForExist('.download form span.help-block span.text-danger')99 .getText('.download form span.help-block span.text-danger');100 error.should.equals('Oh my... something went terribly wrong!');101 });102 it('should have a dropzone', function *() {103 var dropzone = yield browser.isExisting('.dz-action-add.dz-clickable.dropzone');104 dropzone.should.be.equal(true);105 var previewTemplate = yield browser.isExisting('.dropzone .dz-preview-template');106 previewTemplate.should.be.equal(true);107 var message = yield browser.isExisting('.dropzone .dz-default.dz-message');108 message.should.be.equal(true);109 });110 it('should have a fallback to dropzone', function *() {111 var currentValue = sandbox.dropzone.fallback;112 var fallback = yield browser.click('ul.nav > li > a')113 .click('a[href="/settings/transfer"]')114 .click('input#forceFallback')115 .submitForm('.tab-pane.active form')116 .url('/')117 .isExisting('.fallback');118 fallback.should.be.equal(true);119 if(!currentValue) {120 fallback = yield browser.click('ul.nav > li > a')121 .click('a[href="/settings/transfer"]')122 .click('input#forceFallback')123 .submitForm('.tab-pane.active form')124 .url('/')125 .isExisting('.fallback');126 fallback.should.be.equal(false);127 }128 });129 it('should be possible to upload file and retrieve token', function *() {130 var currentValue = sandbox.dropzone.fallback;131 var fallback = yield browser.click('ul.nav > li > a')132 .click('a[href="/settings/transfer"]')133 .click('input#forceFallback')134 .submitForm('.tab-pane.active form')135 .url('/')136 .isExisting('.fallback');137 fallback.should.be.equal(true);138 if(!sandbox.storage.location === 'local') {139 var alert = yield browser.click('ul.nav > li > a')140 .click('a[href="/settings/storage"]')141 .selectByVisibleText('select#StorageLocation', 'Local file system')142 .submitForm('.tab-pane.active form')143 .waitForExist('.tab-pane.active .alert strong', 5000)144 .getText('.tab-pane.active .alert strong');145 alert.should.be.equal('Success!');146 }147 var preview = yield browser.url('/')148 .waitForExist('input#payload')149 .execute(function() {150 // The WebDriverIO chooseFile() method cannot target an invisible input151 // It also does not work well with multiple file input152 jQuery("input#payload").removeAttr('multiple')153 .show();154 })155 .waitForVisible('input#payload')156 .chooseFile('input#payload', path.join(__dirname, '../../../README.md'))157 .submitForm('.fallback form')158 .waitForExist('.dz-preview-template')159 .getText('.dz-preview-template .dz-preview-description span[data-dz-name]')160 preview.should.be.equal('README.md');161 var token = yield browser.getText('.dz-preview-item .dz-preview-description .dz-preview-result .text-success a')162 should.exist(token);163 var tokenLink = yield browser.getAttribute('.dz-preview-item .dz-preview-description .dz-preview-result .text-success a', 'href')164 tokenLink.should.be.equal(sandbox.general.baseUrl + '/download/' + token + '/');165 var emailHeader = yield browser.getText('#hp .dz-completed-container .dz-upload-complete h2');166 should.exist(emailHeader);167 var emailForm = yield browser.isExisting('#hp .dz-completed-container .dz-upload-complete form');168 emailForm.should.be.equal(true);169 var emailFrom = yield browser.isExisting('#hp .dz-completed-container .dz-upload-complete form input#from');170 emailFrom.should.be.equal(true);171 var emailTo = yield browser.isExisting('#hp .dz-completed-container .dz-upload-complete form input#to');172 emailTo.should.be.equal(true);173 var emailBody = yield browser.isExisting('#hp .dz-completed-container .dz-upload-complete form textarea[name="email[body]"]');174 emailBody.should.be.equal(true);175 var submit = yield browser.isExisting('#hp .dz-completed-container .dz-upload-complete form button[type="submit"]');176 submit.should.be.equal(true);177 if(!currentValue) {178 fallback = yield browser.click('ul.nav > li > a')179 .click('a[href="/settings/transfer"]')180 .click('input#forceFallback')181 .submitForm('.tab-pane.active form')182 .url('/')183 .isExisting('.fallback');184 fallback.should.be.equal(false);185 }186 });187 it('should be possible to upload encrypted file and retrieve token', function *() {188 var currentValue = sandbox.dropzone.fallback;189 if(!currentValue) {190 var fallback = yield browser.click('ul.nav > li > a')191 .click('a[href="/settings/transfer"]')192 .click('input#forceFallback')193 .submitForm('.tab-pane.active form')194 .url('/')195 .isExisting('.fallback');196 fallback.should.be.equal(true);197 }198 if(!sandbox.storage.location === 'local') {199 var alert = yield browser.url('/')200 .click('ul.nav > li > a')201 .click('a[href="/settings/storage"]')202 .selectByVisibleText('select#StorageLocation', 'Local file system')203 .submitForm('.tab-pane.active form')204 .waitForExist('.tab-pane.active .alert strong', 5000)205 .getText('.tab-pane.active .alert strong');206 alert.should.be.equal('Success!');207 }208 var encrypted = yield browser.url('/')209 .click('ul.nav > li > a')210 .click('a[href="/settings/security"]')211 .click('input#encryptionEnabled')212 .setValue('input#encryptionKey', 'MySecretEncryptionKey')213 .submitForm('.tab-pane.active form')214 .waitForExist('.tab-pane.active .alert strong', 5000)215 .isExisting('input#encryptionEnabled:checked');216 encrypted.should.be.equal(true);217 var preview = yield browser.url('/')218 .waitForExist('input#payload')219 .execute(function() {220 // The WebDriverIO chooseFile() method cannot target an invisible input221 // It also does not work well with multiple file input222 jQuery("input#payload").removeAttr('multiple')223 .show();224 })225 .waitForVisible('input#payload')226 .chooseFile('input#payload', path.join(__dirname, '../../../README.md'))227 .submitForm('.fallback form')228 .waitForExist('.dz-preview-template')229 .getText('.dz-preview-template .dz-preview-description span[data-dz-name]')230 preview.should.be.equal('README.md');231 var token = yield browser.getText('.dz-preview-item .dz-preview-description .dz-preview-result .text-success a')232 should.exist(token);233 var tokenLink = yield browser.getAttribute('.dz-preview-item .dz-preview-description .dz-preview-result .text-success a', 'href')234 tokenLink.should.be.equal(sandbox.general.baseUrl + '/download/' + token + '/');235 var emailHeader = yield browser.getText('#hp .dz-completed-container .dz-upload-complete h2');236 should.exist(emailHeader);237 var emailForm = yield browser.isExisting('#hp .dz-completed-container .dz-upload-complete form');238 emailForm.should.be.equal(true);239 var emailFrom = yield browser.isExisting('#hp .dz-completed-container .dz-upload-complete form input#from');240 emailFrom.should.be.equal(true);241 var emailTo = yield browser.isExisting('#hp .dz-completed-container .dz-upload-complete form input#to');242 emailTo.should.be.equal(true);243 var emailBody = yield browser.isExisting('#hp .dz-completed-container .dz-upload-complete form textarea[name="email[body]"]');244 emailBody.should.be.equal(true);245 var submit = yield browser.isExisting('#hp .dz-completed-container .dz-upload-complete form button[type="submit"]');246 submit.should.be.equal(true);247 if(!currentValue) {248 fallback = yield browser.click('ul.nav > li > a')249 .click('a[href="/settings/transfer"]')250 .click('input#forceFallback')251 .submitForm('.tab-pane.active form')252 .url('/')253 .isExisting('.fallback');254 fallback.should.be.equal(false);255 }256 });...

Full Screen

Full Screen

chatRealtimeActions.js

Source:chatRealtimeActions.js Github

copy

Full Screen

1const User = require("../models/user");2const Conversation = require("../models/conversation");3const Message = require("../models/message");4const { getOnlineUsersCache } = require("../utils/redisActions");5const checkRole = async (_id) => {6 try {7 const user = await User.findOne({ _id, verified: true }).select("role");8 if (!user) {9 return "Error";10 }11 return user.role;12 } catch (e) {13 return "Error";14 }15};16const setUnreadMessage = async (toUser) => {17 const receiver = await User.findOne({ _id: toUser }).select("unreadMessage");18 receiver.unreadMessage = true;19 await receiver.save();20};21const sendMessageToUser = async ({ _id, message, toUser }) => {22 try {23 const users = await getOnlineUsersCache();24 if (users) {25 const user = users.find((user) => user.userId === toUser);26 if (user) {27 const isExisting = await Conversation.findOne({ user: toUser }).select("_id");28 if (!isExisting) {29 const newConversation = new Conversation({30 user: toUser,31 lastMessageAt: Date.now(),32 });33 await newConversation.save();34 const newMsg = new Message({35 conversation: newConversation._id,36 user: toUser,37 from: _id,38 to: toUser,39 text: message,40 createdAt: Date.now(),41 });42 await newMsg.save();43 return user.socketId;44 } else {45 await Conversation.updateOne(46 { _id: isExisting._id },47 { lastMessageAt: Date.now() }48 );49 const newMsg = new Message({50 conversation: isExisting._id,51 user: toUser,52 from: _id,53 to: toUser,54 text: message,55 createdAt: Date.now(),56 });57 await newMsg.save();58 return user.socketId;59 }60 } else {61 setUnreadMessage(toUser);62 const isExisting = await Conversation.findOne({ user: toUser }).select("_id");63 if (!isExisting) {64 const newConversation = new Conversation({65 user: toUser,66 });67 await newConversation.save();68 const newMsg = new Message({69 conversation: newConversation._id,70 user: toUser,71 from: _id,72 to: toUser,73 text: message,74 createdAt: Date.now(),75 });76 await newMsg.save();77 } else {78 await Conversation.updateOne(79 { _id: isExisting._id },80 { lastMessageAt: Date.now() }81 );82 const newMsg = new Message({83 conversation: isExisting._id,84 user: toUser,85 from: _id,86 to: toUser,87 text: message,88 createdAt: Date.now(),89 });90 await newMsg.save();91 }92 return "OK";93 }94 } else {95 setUnreadMessage(toUser);96 const isExisting = await Conversation.findOne({ user: toUser }).select("_id");97 if (!isExisting) {98 const newConversation = new Conversation({99 user: toUser,100 });101 await newConversation.save();102 const newMsg = new Message({103 conversation: newConversation._id,104 user: toUser,105 from: _id,106 to: toUser,107 text: message,108 createdAt: Date.now(),109 });110 await newMsg.save();111 } else {112 await Conversation.updateOne(113 { _id: isExisting._id },114 { lastMessageAt: Date.now() }115 );116 const newMsg = new Message({117 conversation: isExisting._id,118 user: toUser,119 from: _id,120 to: toUser,121 text: message,122 createdAt: Date.now(),123 });124 await newMsg.save();125 }126 return "OK";127 }128 } catch (e) {129 return "Error";130 }131};132const setAdminUnreadMessage = async (id) => {133 await User.updateOne({ _id: id }, { unreadMessage: true });134};135const sendMessageToAdmin = async ({ _id, message }) => {136 try {137 const admin = await User.findOne({ role: "admin" }).select("_id unreadMessage");138 const users = await getOnlineUsersCache();139 if (users) {140 const user = users.find((user) => user.userId === admin._id.toString());141 if (user) {142 const isExisting = await Conversation.findOne({ user: _id })143 .select("_id user lastMessageAt isRead")144 .populate("user", "username profileImage");145 if (!isExisting) {146 const newConversation = new Conversation({147 user: _id,148 lastMessageAt: Date.now(),149 isRead: false,150 });151 await newConversation.save();152 const newMsg = new Message({153 conversation: newConversation._id,154 user: _id,155 from: _id,156 to: admin._id,157 text: message,158 createdAt: Date.now(),159 });160 await newMsg.save();161 return {162 conversation: newConversation,163 socketId: user.socketId,164 };165 } else {166 const newMsg = new Message({167 conversation: isExisting._id,168 user: _id,169 from: _id,170 to: admin._id,171 text: message,172 createdAt: Date.now(),173 });174 await newMsg.save();175 isExisting.lastMessageAt = Date.now();176 isExisting.isRead = false;177 await isExisting.save();178 }179 return {180 conversation: isExisting,181 socketId: user.socketId,182 };183 } else {184 setAdminUnreadMessage(admin._id);185 const isExisting = await Conversation.findOne({ user: _id }).select("_id");186 if (!isExisting) {187 const newConversation = new Conversation({188 user: _id,189 lastMessageAt: Date.now(),190 isRead: false,191 });192 await newConversation.save();193 const newMsg = new Message({194 conversation: newConversation._id,195 user: _id,196 from: _id,197 to: admin._id,198 text: message,199 createdAt: Date.now(),200 });201 await newMsg.save();202 } else {203 const newMsg = new Message({204 conversation: isExisting._id,205 user: _id,206 from: _id,207 to: admin._id,208 text: message,209 createdAt: Date.now(),210 });211 isExisting.lastMessageAt = Date.now();212 isExisting.isRead = false;213 await isExisting.save();214 await newMsg.save();215 }216 return "OK";217 }218 } else {219 setAdminUnreadMessage(admin._id);220 const isExisting = await Conversation.findOne({ user: _id }).select("_id");221 if (!isExisting) {222 const newConversation = new Conversation({223 user: _id,224 lastMessageAt: Date.now(),225 isRead: false,226 });227 await newConversation.save();228 const newMsg = new Message({229 conversation: newConversation._id,230 user: _id,231 from: _id,232 to: admin._id,233 text: message,234 createdAt: Date.now(),235 });236 await newMsg.save();237 } else {238 const newMsg = new Message({239 conversation: isExisting._id,240 user: _id,241 from: _id,242 to: admin._id,243 text: message,244 createdAt: Date.now(),245 });246 isExisting.lastMessageAt = Date.now();247 isExisting.isRead = false;248 await isExisting.save();249 await newMsg.save();250 }251 return "OK";252 }253 } catch (e) {254 console.log(e);255 return "Error";256 }257};...

Full Screen

Full Screen

test-app.js

Source:test-app.js Github

copy

Full Screen

...14 expect(title).to.be.equals('CodeFlask Test Page');15 expect(url).to.be.equals('http://localhost:8888/');16 });17 it('should create editor elements', function () {18 expect($('.codeflask').isExisting()).to.be.true;19 expect($('.codeflask__pre').isExisting()).to.be.true;20 expect($('.codeflask__textarea').isExisting()).to.be.true;21 expect($('.codeflask__code').isExisting()).to.be.true;22 expect($('.codeflask__flatten').isExisting()).to.be.true;23 expect($('.codeflask__flatten').isExisting()).to.be.true;24 });25 it('should enable syntax highlight', function () {26 expect($('.codeflask .token.punctuation').isExisting()).to.be.true;27 });28 it('should render lineNumbers', function () {29 expect($('.codeflask .codeflask__lines').isExisting()).to.be.true;30 expect($('.codeflask .codeflask__lines__line').isExisting()).to.be.true;31 });32 it('should have same lineNumbers as lines of code', function () {33 $('.codeflask__textarea').setValue('let it = "go";\nconst parrot = "bird";');34 expect($('.codeflask .codeflask__lines').isExisting()).to.be.true;35 const lines = $$('.codeflask .codeflask__lines__line');36 expect(lines.length).to.equal(2);37 });38 it('should update editor upon update', function () {39 $('.codeflask__textarea').setValue('let it = "go";');40 expect($('.codeflask .token.keyword').isExisting()).to.be.true;41 expect($('.codeflask .token.operator').isExisting()).to.be.true;42 expect($('.codeflask .token.string').isExisting()).to.be.true;43 expect($('.codeflask .token.punctuation').isExisting()).to.be.true;44 });45 it('should be instance of CodeFlask', function () {46 const isInstance = browser.execute(() => {47 return flask instanceof CodeFlask48 });49 expect(isInstance).to.be.true;50 });51 it('.updateCode(): should update lineNumbers', function () {52 browser.execute(() => { flask.updateCode("let age = 20"); });53 const lines = $$('.codeflask .codeflask__lines__line');54 expect(lines.length).to.equal(1);55 });56 it('.updateCode(): should update lineNumbers for multiple lines', function () {57 browser.execute(() => { flask.updateCode("let age = 20\nlet lines = 2"); });58 const lines = $$('.codeflask .codeflask__lines__line');59 expect(lines.length).to.equal(2);60 });61 it('.onUpdate(): should execute callback upon user interaction', function () {62 $('.codeflask__textarea').setValue('');63 browser.execute(() => { flask.onUpdate(code => document.title = code) });64 $('.codeflask__textarea').setValue('let it = "go";');65 const title = browser.getTitle();66 expect(title).to.be.equals('let it = "go";')67 });68 it('should enable rtl when rtl: true', function () {69 browser.execute(() => {70 const test_div = document.createElement('div');71 document.body.appendChild(test_div);72 const flask_test = new CodeFlask(test_div, { rtl: true });73 });74 expect($('.codeflask__textarea[dir="rtl"]').isExisting()).to.be.true;75 expect($('.codeflask__pre[dir="rtl"]').isExisting()).to.be.true;76 });77 it('should NOT enable rtl when rtl: false', function () {78 browser.execute(() => {79 const test_div = document.createElement('div');80 document.body.appendChild(test_div);81 const flask_test = new CodeFlask(test_div, { rtl: false });82 });83 expect($('.codeflask__textarea:not([dir="rtl"])').isExisting()).to.be.true;84 expect($('.codeflask__pre:not([dir="rtl"])').isExisting()).to.be.true;85 });86 it('should NOT enable rtl when rtl not set', function () {87 browser.execute(() => {88 const test_div = document.createElement('div');89 document.body.appendChild(test_div);90 const flask_test = new CodeFlask(test_div, { language: 'js' });91 });92 expect($('.codeflask__textarea:not([dir="rtl"])').isExisting()).to.be.true;93 expect($('.codeflask__pre:not([dir="rtl"])').isExisting()).to.be.true;94 });95 it('.getCode(): should return current code', function () {96 $('.codeflask__textarea').setValue('return "my code here"');97 const code = browser.execute(() => { return flask.getCode(); });98 expect(code).to.be.equals('return "my code here"');99 });100 it('should add an ID attribute with option', function () {101 browser.execute(() => {102 const test_div = document.createElement('div');103 document.body.appendChild(test_div);104 const flask_test = new CodeFlask(test_div, { areaId: 'thing1' });105 });106 expect($('.codeflask__textarea#thing1').isExisting()).to.be.true;107 });108 it('should add an aria-labelledby attribute with option', function () {109 browser.execute(() => {110 const test_div = document.createElement('div');111 document.body.appendChild(test_div);112 const flask_test = new CodeFlask(test_div, { ariaLabelledby: 'thing2' });113 });114 expect($('.codeflask__textarea[aria-labelledby="thing2"]').isExisting()).to.be.true;115 });116 it('should add a readonly attribute with option', function () {117 browser.execute(() => {118 const test_div = document.createElement('div');119 document.body.appendChild(test_div);120 const flask_test = new CodeFlask(test_div, { readonly: true });121 });122 expect($('.codeflask__textarea[readonly]').isExisting()).to.be.true;123 });124 it('should not add a readonly attribute with option if it is set to false', function () {125 browser.execute(() => {126 const test_div = document.createElement('div');127 document.body.appendChild(test_div);128 const flask_test = new CodeFlask(test_div, { readonly: false });129 });130 expect($('.codeflask__textarea:not([readonly])').isExisting()).to.be.true;131 });132 it('should not add a readonly attribute with option if it is not set', function () {133 browser.execute(() => {134 const test_div = document.createElement('div');135 document.body.appendChild(test_div);136 const flask_test = new CodeFlask(test_div, { });137 });138 expect($('.codeflask__textarea:not([readonly])').isExisting()).to.be.true;139 });140 it('should add a readonly attribute from a function call', function () {141 browser.execute(() => {142 const test_div = document.createElement('div');143 document.body.appendChild(test_div);144 const flask_test = new CodeFlask(test_div, {});145 flask_test.enableReadonlyMode();146 });147 expect($('.codeflask__textarea[readonly]').isExisting()).to.be.true;148 });149 it('should remove a readonly attribute from a function call', function () {150 browser.execute(() => {151 const test_div = document.createElement('div');152 document.body.appendChild(test_div);153 const flask_test = new CodeFlask(test_div, { readonly: true });154 flask_test.disableReadonlyMode();155 });156 expect($('.codeflask__textarea:not([readonly])').isExisting()).to.be.true;157 });158 it('should not add line by press enter when editor is readonly', function () {159 browser.execute(() => {160 // remove all existing editors161 document.body.innerHTML = '';162 const rootEl = document.createElement('div');163 document.body.appendChild(rootEl);164 new CodeFlask(rootEl, { readonly: true, lineNumbers: true });165 rootEl.querySelector('.codeflask .codeflask__textarea').dispatchEvent(new KeyboardEvent('keydown',{ key: 'Enter', keyCode: 13 }));166 });167 const lines = $$('.codeflask .codeflask__lines__line');168 expect(lines.length).to.equal(1);169 });170 xit('should handle the tab key in the editor', function () {...

Full Screen

Full Screen

WorkerData.js

Source:WorkerData.js Github

copy

Full Screen

1import StationInfo from './StationInfo';2import WorkerFormData from './WorkerFormData';3export default class WorkerData{4 constructor(stations, workerFormData, selectedStation, errors){5 this._stations = stations || [];6 this._workerFormData = workerFormData || new WorkerFormData();7 this._selectedStation = selectedStation || new StationInfo();8 this._errors = errors || {9 lat: undefined,10 lon: undefined,11 alt: undefined,12 siteId: undefined,13 start: undefined,14 stop: undefined15 };16 }17 withExistingStationData(){18 return new WorkerData(19 this._stations,20 new WorkerFormData(21 this._selectedStation.lat,22 this._selectedStation.lon,23 this._selectedStation.alt,24 this._selectedStation.siteId,25 this._workerFormData.start,26 this._workerFormData.stop27 ),28 this._selectedStation,29 this._errors30 );31 }32 withStations(stations){33 const stationsFormatted = stations.map(s => {34 return {35 siteId: s.id,36 lat: s.lat,37 lon: s.lon,38 alt: s.alt,39 name: s.name40 };41 });42 return new WorkerData(stationsFormatted, this._workerFormData, this._selectedStation,this._errors);43 }44 resetAndAddNewStation(station){45 return new WorkerData(this._stations.concat([station]));46 }47 get stations(){48 return this._stations;49 }50 get hasErrors(){51 const props = Object.keys(this._errors);52 return !!props.find(key => !!this._errors[key], this);53 }54 get errors(){55 return this._errors;56 }57 withUpdatedFormData(update){58 const key = update.propertyName;59 Object.assign(this._errors, {[key]: update.error});60 if (key) {61 const val = update.value;62 switch(key) {63 case "siteId":64 const existingStation = this._stations.find(station => station.siteId == val);65 if (existingStation) {66 return new WorkerData(this._stations, this._workerFormData.withUpdate(key, val), this._selectedStation.withSelectedStation(existingStation), this._errors);67 } else if (this.selectedStation.isExisting) {68 return new WorkerData(this._stations, this._workerFormData.withUpdate(key, val), undefined, this._errors);69 } else {70 return new WorkerData(this._stations, this._workerFormData.withUpdate(key, val), this._selectedStation, this._errors);71 }72 case "lat":73 return new WorkerData(this._stations, this._workerFormData.withUpdate(key, val), this._selectedStation.withLat(val), this._errors);74 case "lon":75 return new WorkerData(this._stations, this._workerFormData.withUpdate(key, val), this._selectedStation.withLon(val), this._errors);76 default:77 return new WorkerData(this._stations, this._workerFormData.withUpdate(key, val), this._selectedStation, this._errors);78 }79 } else {80 return this;81 }82 }83 withDates(dates){84 const withStart = this._workerFormData.withUpdate('start', dates.start);85 const withStartStop = withStart.withUpdate('stop', dates.stop);86 return new WorkerData(87 this._stations,88 withStartStop,89 this._selectedStation,90 Object.assign({}, this._errors, {start: dates.startError, stop: dates.stopError})91 );92 }93 get formData(){94 const isExisting = this.selectedStation.isExisting;95 return {96 siteId: getDataforForm(this._workerFormData, this._selectedStation, 'siteId', isExisting),97 lat: round(getDataforForm(this._workerFormData, this._selectedStation, 'lat', isExisting)),98 lon: round(getDataforForm(this._workerFormData, this._selectedStation, 'lon', isExisting)),99 alt: getDataforForm(this._workerFormData, this._selectedStation, 'alt', isExisting),100 start: this._workerFormData.start,101 stop: this._workerFormData.stop102 };103 }104 get jobDef(){105 const isExisting = this.selectedStation.isExisting;106 return this.isJobDefComplete107 ? {108 lat: round(getDataforForm(this._workerFormData, this._selectedStation, 'lat', isExisting)),109 lon: round(getDataforForm(this._workerFormData, this._selectedStation, 'lon', isExisting)),110 alt: getDataforForm(this._workerFormData, this._selectedStation, 'alt', isExisting),111 siteId: this._workerFormData.siteId,112 start: this._workerFormData.start,113 stop: this._workerFormData.stop114 }115 : {};116 }117 withSelectedStation(selectedStation, isSourceMapClick){118 const siteId = isSourceMapClick119 ? this.isFormSiteIdExisting(this._workerFormData.siteId)120 ? ''121 : this._workerFormData.siteId122 : selectedStation.siteId;123 const workerFormData = isSourceMapClick124 ? new WorkerFormData(125 selectedStation.lat,126 selectedStation.lon || selectedStation.lng,127 selectedStation.alt,128 siteId,129 this._workerFormData.start,130 this._workerFormData.stop)131 : selectedStation.isExisting && this._workerFormData.lat && this._workerFormData.lon132 ? this._workerFormData // Do not overwrite form if it has values133 : new WorkerFormData(134 selectedStation.lat,135 selectedStation.lon || selectedStation.lng,136 selectedStation.alt,137 siteId,138 this._workerFormData.start,139 this._workerFormData.stop);140 return new WorkerData(141 this._stations,142 workerFormData,143 new StationInfo(selectedStation.lat,144 selectedStation.lon || selectedStation.lng,145 selectedStation.alt,146 selectedStation.siteId,147 selectedStation.name,148 selectedStation.disabledDates),149 this._errors150 );151 }152 withClearedSelectedStation(){153 return new WorkerData(this._stations, this._workerFormData, undefined, this._errors);154 }155 get selectedStation(){156 return this._selectedStation;157 }158 get isFormAndSelStationSame(){159 return (this._selectedStation.lat === this._workerFormData.lat || !this._workerFormData.lat)160 && (this._selectedStation.lon === this._workerFormData.lon || !this._workerFormData.lon)161 && (this._selectedStation.alt === this._workerFormData.alt || !this._workerFormData.alt)162 && (this._selectedStation.siteId === this._workerFormData.siteId || !this._workerFormData.siteId);163 }164 get isFormAndExistingStationDifferent(){165 return this._selectedStation.isExisting && !this.isFormAndSelStationSame;166 }167 isFormSiteIdExisting(siteId){168 return this._stations.some(st => st.siteId == siteId);169 }170 get isJobDefComplete(){171 const isExisting = this.selectedStation.isExisting;172 const isSiteIdAllowed = (isExisting173 && this._selectedStation.lat == this._workerFormData.lat174 && this._selectedStation.lon == this._workerFormData.lon175 && this._selectedStation.alt == this._workerFormData.alt176 && this._selectedStation.siteId == this._workerFormData.siteId)177 || (!isExisting && !!this._workerFormData.siteId);178 return !this.hasErrors && isSiteIdAllowed179 && !!getDataforForm(this._workerFormData, this._selectedStation, 'lat', isExisting)180 && !!getDataforForm(this._workerFormData, this._selectedStation, 'lon', isExisting)181 && !!getDataforForm(this._workerFormData, this._selectedStation, 'alt', isExisting)182 && !!this._workerFormData.siteId && this._workerFormData.siteId.length >= 3183 && !!this._workerFormData.start184 && !!this._workerFormData.stop;185 }186}187function getDataforForm(workerFormData, selectedStation, key, isExisting){188 if (isExisting){189 return workerFormData[key] ? workerFormData[key] : selectedStation[key];190 } else {191 return workerFormData[key] || (isExisting ? undefined : selectedStation[key]);192 }193}194function round(val){195 if (val && isNumber(val)){196 const valStr = '' + val;197 if (valStr.match(/\.$/) || valStr.match(/\.0+$/)) {198 return val;199 } else {200 return parseFloat(parseFloat(val).toFixed(2));201 }202 } else {203 return val;204 }205}206function isNumber(n){207 return !isNaN(parseFloat(n)) && isFinite(n);...

Full Screen

Full Screen

validation-tests.js

Source:validation-tests.js Github

copy

Full Screen

...10 it('can load the form and find the header', () => {11 assert.equal(browser.getText('.ct-document-header-text'), 'Validations')12 })13 it('has a text element with errors', () => {14 assert.ok(browser.isExisting('.ct-input-invalid.ct-text-input'))15 })16 it('has a number element with errors', () => {17 assert.ok(browser.isExisting('.ct-input-invalid.ct-number-input'))18 })19 it('has a date element with errors', () => {20 assert.ok(browser.isExisting('.ct-input-invalid.ct-date-picker'))21 })22 it('has a datetime element with errors', () => {23 assert.ok(browser.isExisting('.ct-input-invalid.ct-datetime-picker'))24 })25 it('can not be submitted when invalid', () => {26 assert.equal(browser.isExisting('.ct-action=Submit'), false)27 })28 it('accepts a valid text value', () => {29 browser.setValue('.ct-text-input', 'Tjipp')30 blur()31 browser.waitUntil(() => {32 return !browser.isExisting('.ct-input-invalid.ct-text-input')33 }, 10000)34 })35 it('accepts a valid number value', () => {36 const numberInput = browser.element('.ct-number-input')37 numberInput.clearElement()38 numberInput.setValue('42')39 blur()40 browser.waitUntil(() => {41 return !browser.isExisting('.ct-input-invalid.ct-number-input')42 }, 10000)43 })44 it('accepts a valid date value', () => {45 browser.selectByValue('.ct-date-picker .ct-year', 2017)46 browser.waitUntil(() => {47 return !browser.isExisting('.ct-input-invalid.ct-date-picker')48 }, 10000)49 })50 it('accepts a valid date time value', () => {51 browser.selectByValue('.ct-datetime-picker .ct-year', 1999)52 browser.waitUntil(() => {53 return !browser.isExisting('.ct-input-invalid.ct-datetime-picker')54 }, 10000)55 })56 it('can be submitted when valid', () => {57 browser.isExisting('.ct-action=Submit')58 })59 it('submits the form', () => {60 browser.click('.ct-action=Submit')61 })62 it('can display interpolated value', () => {63 return browser.waitUntil(() => {64 return browser.getText('.ct-document-header-text') == 'Paragraph'65 }, 10000)66 assert.equal(browser.getText('.ct-content div#embedded-div'), 'Tjipp')67 })...

Full Screen

Full Screen

my-account.js

Source:my-account.js Github

copy

Full Screen

...20 ;21 });22 it('should display identity link', function () {23 return browser24 .isExisting('.page-content a#identity-link')25 .then(function (isExisting) {26 isExisting.should.be.true;27 })28 ;29 });30 it('should display history link', function () {31 return browser32 .isExisting('.page-content a#history-link')33 .then(function (isExisting) {34 isExisting.should.be.true;35 })36 ;37 });38 it('should display credit splips link', function () {39 return browser40 .isExisting('.page-content a#order-slips-link')41 .then(function (isExisting) {42 isExisting.should.be.true;43 })44 ;45 });46 it('should display vouchers link', function () {47 return browser48 .isExisting('.page-content a#discounts-link')49 .then(function (isExisting) {50 isExisting.should.be.true;51 })52 ;53 });54 it('should display returns link', function () {55 return browser56 .isExisting('.page-content a#returns-link')57 .then(function (isExisting) {58 isExisting.should.be.true;59 })60 ;61 });62 });...

Full Screen

Full Screen

isExisting.js

Source:isExisting.js Github

copy

Full Screen

...14 <div id="zeroOpacity" style="opacity: 0"></div>15 :isExisting.js16 it('should detect if elements are existing', function () {17 var isExisting;18 isExisting = browser.isExisting('#someRandomNonExistingElement');19 console.log(isExisting); // outputs: false20 isExisting = browser.isExisting('#notDisplayed');21 console.log(isExisting); // outputs: true22 isExisting = browser.isExisting('#notVisible');23 console.log(isExisting); // outputs: true24 isExisting = browser.isExisting('#notInViewport');25 console.log(isExisting); // outputs: true26 isExisting = browser.isExisting('#zeroOpacity');27 console.log(isExisting); // outputs: true28 });29 * </example>30 *31 * @alias browser.isExisting32 * @param {String} selector DOM-element33 * @returns {Boolean|Boolean[]} true if element(s)* [is|are] existing34 * @uses protocol/elements35 * @type state36 *37 */38var isExisting = function isExisting(selector) {39 return this.elements(selector).then(function (res) {40 if (Array.isArray(res.value) && res.value.length > 0) {41 return true;42 }43 return false;44 });45};46exports.default = isExisting;...

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 .setValue('#lst-ib', 'WebdriverIO')9 .click('input[name="btnK"]')10 .pause(1000)11 .getTitle().then(function(title) {12 console.log('Title was: ' + title);13 })14 .end();

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 .isExisting('#hplogo').then(function(isExisting) {9 })10 .end();

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 .isExisting('.gb_P')9 .then(function(isExisting) {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);4.init()5.setValue('#lst-ib', 'WebdriverIO')6.click('button[name="btnK"]')7.pause(5000)8.isExisting('h3=WebdriverIO (Software) - Wikipedia, the free encyclopedia')9.then(function(isExisting) {10})11.end();

Full Screen

Using AI Code Generation

copy

Full Screen

1browser.isExisting(selector);2browser.isExisting(selector);3browser.isExisting(selector);4browser.isExisting(selector);5browser.isExisting(selector);6browser.isExisting(selector);7browser.isExisting(selector);8browser.isExisting(selector);9browser.isExisting(selector);10browser.isExisting(selector);11browser.isExisting(selector);12browser.isExisting(selector);13browser.isExisting(selector);14browser.isExisting(selector);15browser.isExisting(selector);16browser.isExisting(selector);17browser.isExisting(selector);18browser.isExisting(selector);19browser.isExisting(selector);20browser.isExisting(selector);21browser.isExisting(selector);22browser.isExisting(selector);23browser.isExisting(selector);24browser.isExisting(selector);25browser.isExisting(selector);26browser.isExisting(selector);

Full Screen

Using AI Code Generation

copy

Full Screen

1browser.isExisting("element selector");2browser.isElementPresent("element selector");3browser.elements("element selector", function(result) {4 if (result.value.length > 0) {5 }6});7browser.isVisible("element selector");8browser.isElementPresent("element selector");9browser.isVisible("element selector");10browser.getText("element selector");11browser.getText("element selector");12browser.getText("element selector");13browser.getAttribute("element selector", "attribute name");14browser.getAttribute("element selector", "attribute name");15browser.getAttribute("element selector", "attribute name");16browser.getCssProperty("element selector", "css property name");17browser.getCssProperty("element selector", "css property name");18browser.getCssProperty("element selector", "css property name");19browser.getProperty("element selector",

Full Screen

Using AI Code Generation

copy

Full Screen

1if (browser.isExisting("div#test")) {2 console.log("Element exists");3} else {4 console.log("Element does not exist");5}6if (browser.isExisting("#test")) {7 console.log("Element exists");8} else {9 console.log("Element does not exist");10}11if (browser.isExisting("div")) {12 console.log("Element exists");13} else {14 console.log("Element does not exist");15}16if (browser.isExisting("div#test")) {17 console.log("Element exists");18} else {19 console.log("Element does not exist");20}21if (browser.isExisting("div.test")) {22 console.log("Element exists");23} else {24 console.log("Element does not exist");25}26if (browser.isExisting("div.test")) {27 console.log("Element exists");28} else {29 console.log("Element does not exist");30}31if (browser.isExisting("div.test")) {32 console.log("Element exists");33} else {34 console.log("Element does not exist");35}36if (browser.isExisting("div#test")) {37 console.log("Element exists");38} else {39 console.log("Element does not exist");40}41if (browser.isExisting("div#test")) {42 console.log("Element exists");43} else {44 console.log("Element does not exist");45}

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