My problem is I created two methods that will generate a random first name and random last name from the arrays of names. When the test executes the first and the last name methods, I want to somehow get those two values and combine them into an email in the specific format -> "[email protected]".
But I don’t know how to do it and I can’t find the answer that works. Keep in mind I work in Cypress for a few days. Below is the photo of the fields and HTML of the element (both are the same in terms of where the value is stored).
function generateEmail(){
var email = cy.get("input[placeholder='Enter first name']") + "." +
cy.get("input[placeholder='Enter last name']") + "@gmail.com"
return email
}
I don’t know what to use in order to get the text from the value attribute.
2
Answers
Call generateEmail funtion
Call Another Way
Generally speaking you will use
.then()
to get a value fromcy.get()
but since they are inputs you also need.invoke('val')
to extract the value entered into the<input>
.Return the whole chain and use it with
.then()
, or create a custom command instead of a function.