I am running multiple test suits in a shot. Current I am hard coding the data for testing
Example
element(by.name('email')).sendKeys(xxxxxx)
element(by.name('password')).sendKeys('password')
This email field has a unique key constraint, so each time when I run tests I have to manually change this values. There are many such fields I need to change and it is becoming too hard for me to do manually. How this is normally handled in protractor e2e testing.?
Is there any reliable third party library or any option in protractor to generate mock data for testing. So each time it will be randomly generated like I can get names, valid email strings, phone numbers, other meaningful strings etc from the library.
I am using protractor with jasmine for e2e testing of an angular single page application.
Any help is greatly appreciated.
Thanks!
I just created my own library of functions that can generate the data I need. For example here is the function I use to generate random numbers:
//Gets a random number between min and max
getRandomNum = function(min, max){
return parseInt(Math.random() * (max - min) + min);
};
and this one for strings:
getRandomString = function(length) {
var string = '';
var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' //Include numbers if you want
for (i = 0; i < length; i++) {
string += letters.charAt(Math.floor(Math.random() * letters.length));
}
return string;
}
You can manipulate these functions to return email addresses or whatever format you need. Or if you are either really lazy or really picky about how your random strings/numbers are generated you can look at https://www.npmjs.com/package/random-js