5

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!

Vishnu Sureshkumar
  • 2,246
  • 6
  • 35
  • 52
  • 1
    Nobody except you can tell what kind of data the fields should be filled with. A simple helper function that accepts a map of css selectors and input strings would do the trick. [Some faker library](https://www.npmjs.com/browse/keyword/faker) may be helpful but not too much, because a fixture still should be generated beforehand. – Estus Flask Apr 26 '16 at 13:51

1 Answers1

5

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

KCaradonna
  • 760
  • 6
  • 13