Skip to main content

Posts

Showing posts with the label #cypress

Use of for Loop & return in Cypress Automation

  Use of  For Loop & return method in Cypress automation : describe(" Use Of For Loop and return method ",function(){   it ( 'Test Case 15' ,  function () { cy . visit ( 'www.exapmle.com/',{timeout:1000} );        cy . get ( '.tab-tools > .icon > .svg-inline--fa' ). click ({ force : true }); // Now this method will fetch the text which is already displayed & will save it.      cy . get ( '.last-updated-date > span' ). then (( $txt )  =>  {  const   txt  =  $txt . text ()      cy . log ( txt )                  // For loop will run 50 times & after each 3 seconds // it will check Visibility of element. // If it gets newly appeared element/Text It will be terminated before 50 runs var   i ;          for  ( i  =  0 ;  i  <  50 ;  i ++) {              cy . wait ( 3000 )                           cy . get ( '.last-updated-date > span' ). each (( $text )  =>  {   c

How to select a random option from dropdown in cypress ?

  Suppose that you have the following values in dropdown.   Step (1) Define all these values which are in your dropdown in an array for example. πŸ‘‡   var   Reference  = [ "LinkedIn" ,  "Facebook" ,  "Twitter" ,  "Other" ,  "Instagram" ,  "Email" ,  "Friends" ]; Step (2) Then define a random function for exampleπŸ‘‡ var   randreferences  =  Reference [ Math . floor ( Math . random () *  Reference . length )]; Step (3) Call this random function in Select() method. for example πŸ‘‡ cy . get ( '#aboutUs' ). select ( randreferences ) Important Note:This code should be in same test case where you are trying to do this one Enjoy✌ Full Code ==>πŸ‘‡πŸ‘‡πŸ‘‡ var   Reference  = [ "LinkedIn" ,  "Facebook" ,  "Twitter" ,  "Other" ,  "Instagram" ,  "Email" ,  "Friends" ]; var   randreferences  =  Reference [ Math . floor ( Math . random () *  Reference . lengt