How can I use random string in my cypress test so that whenever my gitlab-runner runs the code, the system will use difference strings like the Email and Phone number majorly.
I have my class created which i do call in my script.
here is the class that i created .
export class SignupPage{
enterFirstname(firstname){
cy.get('.grid-cols-2 > :nth-child(1) > .relative > .w-full').type (firstname)
}
enterlastname(lastname){
cy.get('.grid-cols-2 > :nth-child(2) > .relative > .w-full').type(lastname)
}
enterEmail(email){
cy.get('.space-y-3 > :nth-child(2) > .relative > .w-full').type(email)
}
enterBusinessName(businessName){
cy.get(':nth-child(3) > .relative > .w-full').type(businessName)
}
enterBusinessType(){
cy.get('#headlessui-listbox-button-1').click()
cy.get('#headlessui-listbox-option-4 > .font-normal').click()
}
enterPhoneNumber(phoneNumber){
cy.get(':nth-child(5) > .relative > .w-full').type(phoneNumber)
}
enterPassword(password){
cy.get(':nth-child(6) > :nth-child(1) > .relative > .w-full').type(password)
}
clickAgreementBox(){
cy.get('.h-4').click()
}
clickContinue(){
cy.contains('Continue').click()
}
}
here is my test script
import { SignupPage } from "./pages/signup_page"
const signupPage = new SignupPage()
describe('Registration', () => {
it ('SoftPay registration page', () =>{
cy.viewport(1280, 720)
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
cy.visit('softpayfront.softalliance.com/')
cy.contains('Create Account').click()
signupPage.enterFirstname('Adunola')
signupPage.enterlastname('Adunola')
signupPage.enterEmail(makeid(6) + "@mailsac.com")
signupPage.enterBusinessName('SoftPay TESTING')
signupPage.enterBusinessType()
signupPage.enterPhoneNumber(makeid(8)+ "82090808070")
signupPage.enterPassword('Password#1')
signupPage.clickAgreementBox()
signupPage.clickContinue()
cy.end()
})
})
this only work for the random email but not for the phone number
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
Aucun commentaire:
Enregistrer un commentaire