RayVantas

dynamicUserPrepare

Jan 27th, 2022 (edited)
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Cypress.Commands.add('dynamicUserPrepare', () => {
  2.     let $fixture
  3.  
  4.     const testAccountsArray = userList
  5.     var account = {}
  6.     var email = []
  7.  
  8.     do {
  9.         var uuid = () => Cypress._.random(10, 1e4)
  10.         var id = uuid()
  11.         var testname = `auto${id}@testing.graviontech.com`
  12.         console.log(testname+' is in account list? - '+testAccountsArray.includes(testname))
  13.    
  14.         window.emailHandler = testname
  15.     } while (testAccountsArray.includes(testname) === true)
  16.    
  17.     console.log('E-mail: '+testname)
  18.     console.log('Accounts test list: '+testAccountsArray)
  19.  
  20.     email.push(window.emailHandler)
  21.     account.id = testAccountsArray.length
  22.     account.email = email[0]
  23.     cy.log('Test run ID: '+account.id)
  24.     window.runID = account.id
  25.  
  26.     testAccountsArray.push({...account})
  27.  
  28.     cy.writeFile("cypress/fixtures/parallel/accountsList.json", (testAccountsArray))
  29.     console.log(testAccountsArray)
  30.  
  31.     cy.checkRegEmail() //Сhecks if the email is registered and completely clears the test account
  32.  
  33.     function fixturePrepare() { //Fixture list
  34.         switch (true) {
  35.             case fxPrepare == 'recoveruser':
  36.                 $fixture = recoveruser
  37.                 window.fxConfirm = 'recoveruser'
  38.                 break
  39.  
  40.             case fxPrepare == 'createaccountuser':
  41.                 $fixture = createaccountuser
  42.                 window.fxConfirm = 'createaccountuser'
  43.                 break
  44.  
  45.             case fxPrepare == 'deleteaccountuser':
  46.                 $fixture = deleteaccountuser
  47.                 window.fxConfirm = 'deleteaccountuser'
  48.                 break
  49.  
  50.             case fxPrepare == 'accountusers':
  51.                 $fixture = accountusers
  52.                 window.fxConfirm = 'accountusers'
  53.                 break
  54.  
  55.             case fxPrepare == 'mainuser':
  56.                 $fixture = mainuser
  57.                 window.fxConfirm = 'mainuser'
  58.                 break
  59.  
  60.             default:
  61.                 cy.log('Cannot prepare fixture')
  62.                 console.log(window.fxPrepare)
  63.                 break
  64.         }
  65.     }
  66.     fixturePrepare()
  67.  
  68.     cy.log('fx ' + fxConfirm + ' is ready')
  69.  
  70.     cy.request({
  71.         method: "POST",
  72.         url: Cypress.env('api_register'),
  73.         json: true,
  74.         headers: {
  75.             'Content-Type': 'application/json'
  76.         },
  77.         body: {
  78.             "email": window.emailHandler,
  79.             "password": $fixture.password,
  80.             "name": $fixture.username,
  81.             "personalDataPermission": true
  82.         }
  83.     })
  84.  
  85.     cy.emailConfirm()//Confirm registration
  86.  
  87.     cy.log(JSON.stringify(userList[runID].email + ' has been created'))
  88.    
  89.     cy.getGQLUrl()//Takes the actual URL for api
  90.     cy.getAccessToken()//Assigns an access token for logging into an account at global level
  91. })
Add Comment
Please, Sign In to add comment