Update/Edit: I have a fixture file which contains firstname, lastname and email and it loops through beforeeach()
and enters them in the respective fields. The verification i want to do is lets say a bad email is entered without '@','.com' or just '@' present or just '.com' these should fail when the field is verified.
const availablefixtures = [
{
"name": "data3",
"context": "1"
},
{
"name": "data2",
"context": "2"
}
]
data from fixture file is:
{
"firstname": "Lambda",
"lastname": "Jonas",
"email": "[email protected]"
}
describe('demoniftyhappysuite', function () {
//loop through both the fixtues
availablefixtures.forEach((afixture) => {
describe(afixture.context, () => {
enter code here
cy.fixture(afixture.name).then(function (data) {
this.data = data;
})
Currently i am reading the email value from a data file in fixtures
it('demoniftyhappytest', {}, function () {
cy.get('input[name="personal.email"]').type(this.data.email, {
log: false
}).invoke('val').should('not.be.empty')
From: How can I check email validation in cypress the best way to do is have a set of emails in a array. (may be in a JSON) and loop through them and check for the email validity.
Eg:
{
"Email_1":"['[email protected]','valid']",
"Email_2":"['robotmail.com','InValid']",
}
Second Solution: Example Try the following code for email validation.
<script type = "text/javascript">
<!--
function validateEmail() {
var emailID = document.myForm.EMail.value;
atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf(".");
if (atpos < 1 || ( dotpos - atpos < 2 )) {
alert("Please enter correct email ID")
document.myForm.EMail.focus() ;
return false;
}
return( true );
}
//-->
</script>
I want it to be something simple like even if it verifies @symbol and .com in the email entered for time being.
You can use a
.forEach()
to iterate through the array of emails and determine the behavior that way. As you've currently constructed your email json, we'll need to get the array fromObject.values()
.If you wanted to change your object to be an array of arrays, it would be something like this:
Or if you wanted to make it an array of objects