Everyone loves a bit of Bug Magnet!

I’m still in the random data creating mood, so I thought I would extend my last post slightly by showing / explaining how you can quickly add some of the random data that you have created, into Bug Magnet as a custom config file.

If you haven’t heard of this Chrome and Firefox extension…where have you been?! I’m a huge fan of this tool, it’s assisted me during numerous testing sessions since I discovered its existence.  A while back, a new feature was added allowing you to add your own JSON files  – This was a game changer for me, It allowed me to create lots of different custom files specific to my context, for me to use whenever I needed too. Adding and Removing Files is soooo quick and easy that it really makes having something this valuable in your testers toolbox, an absolute no brainer.

A better explanation of what you can do with Bug Magnet can be found here. Neil Studd is extremely good at walking through how you can/could use the tool.

Let’s extend what we have already…

Open a command prompt or terminal, in the directory where you saved the random-data-generator app (Go and check out my last blog post if you’ve forgotten already). We’ll need to bring in the jsonfile module to our app, this will help us create the file that we can use with Bug Magnet.

Type the following command and press Enter. This will install the module and also add it as one of the dependencies in our previously created packages.json file.

npm install --save jsonfile

install_jsonfile

Once that has finished installing, it shouldn’t take very long, create a new file and save this in the random_data_generator directory. For this example, I’ve named the file cardDetails.js. As you can tell by the name, this will create some random payment card details.

Add the following code to the new file:

// Dependencies

var casual   = require('casual');
var jsonfile = require('jsonfile')

var file = 'cardDetails.json'
jsonfile.spaces = 4

// Random Card Data Set

casual.define('cardDetails', function() {
 return {
     Name        : casual.full_name,
     Card_Type   : casual.card_type,
     Card_Number : casual.card_number(casual.card_type),
     Card_Expiry : casual.card_exp
   };
});

// Write the result to a json file

jsonfile.writeFile(file, casual.cardDetails);

Like before, I’ll briefly explain what’s going on here – At the top we are bringing in the modules, casual is our random data helper and jsonfile is the module that’s going help us out with creating the JSON file (Say’s it all in the name really). Next, we have the file variable and this, as you would have guessed, is where we are naming the output file. At the moment this is just getting saved to the root directory of the app but you can specify a location anywhere on your system if you like, entirely up to you. Just down from this is the spaces that you would like to set, I’ve set it to 4 on this occasion as the default value is null and 4 gives you a lovely pretty print feel. Have a play about with it and set what you think is right.

In the middle of the file is the meat of the operation, this is creating your random data. Previously, we used user data and saved this in the user.js file, I’ve just mixed it up a bit and used a different data set. Lastly, we have the line that will write all the output to the JSON file.

Time to create the JSON file…

In a terminal, type the following command and press Enter. This will do the business and create the JSON file.

node cardDetails.js

create_json_file

You should now be able to navigate to the file, in the location that you set in cardDetails.js and it can be opened up in a text editor.

The cardDetails.json file will look something like this (with different data obviously).

{
    "Name": "Kristopher Hickle",
    "Card_Type": "Visa",
    "Card_Number": "4485446830945271",
    "Card_Expiry": "04/17"
}

Add the file to Bug Magnet…

I’m assuming that you have the extension already installed, if not, go do that now.

In the Chrome browser type chrome://extensions/ into the address bar and press Enter, Select the “Options” button on the Bug Magnet extension. 

Select the “Add Configuration File” button.

bm_add_file

The Name that you enter in this field, will be the name that appears within the context menu in Bug Magnet, next to the default ones (Names, Cities, E-Mail addresses etc.).

bm_name

Press the “Select File” button and navigate to the cardDetails.json file. Select the “Open” button and this will then add the new config file to Bug Magnet. That’s it, it is now ready to be used in anger against the site you’re testing.

We’re now done – I’ve taken you this far, it’s now up to you to create the data and start using it in association with Bug Magnet.

To finish off…

These guides are obviously very basic and full of potential problems, I can see loads myself. They are not intended to be perfect, I view them more as a helping hand to get you started. Even if you don’t follow my method of creating random data, please do go and check out Bug Magnet – The default data that comes with the extension has found me so many bugs over the last couple of years!! At NVM, we have created our own repository of JSON files that is in a shared location, these can be tapped into and used by anyone, not just testers. All we need to do is import them into Bug Magnet before a test session and we’re set.

I created a really poor set of instructions for my team on how to create these custom files (using manually added data) a while back – you can find them here.

I’m still learning how to use GitHub and I continued my learning by trying to add all the files I’ve mentioned in the blog posts to a new repository. I think I sussed it but there are a few dodgy commits on there – Feel free to take a look here.

I’ve enjoyed writing these, it helps cement in my mind what i know and whIt i need to improve on, thank you for reading!!

 

Advertisements

My own personal Testability experiment!

Two weeks ago I decided to focus my learning on a particular area each month, historically i’ve been rubbish at concentrating on one thing. Testing is so vast with lots of different interesting areas to research it can become a little overwhelming at times. Something had to change for me:


I wanted the choose a subject that i was aware of and what I thought i knew it to be but i was never too sure about how wide it stretched. Testability was going to be the main focus!

I had a basic plan in mind – Split the month into two parts. The first 2 weeks will be research and observation (My team and the wider Test Team) and the second 2 weeks will be trying to implement some improvements or make improvement suggestions. The test community has massively helped me during the research phase, there’s many great things that have been written about Testability over the last few years and these normally reference other articles or conference talks so it’s actually been a really enjoyable experience discovering a bunch of very interesting things.

Here’s a list of the Blogs, Articles and Talks that i’ve read over the last two weeks:

Blog Posts

Articles

Models

Conference Talks

It’s going to be an interesting couple of weeks coming up, I’m planning doing a follow up post when the time is up to explain what worked and what didn’t work. I’ve had a lot of fun concentrating on one area, i’ve slipped up a few times and wondered down different paths but i’ve been focused enough to indentify these lapses and then got on track.
Huge thanks must go out to Huib Schoots – His Great Resources page was the starting point for my research.

Does anyone else take a similar approach to their learning or maybe you have a different method? I’d love to hear about it!

Creating Random Data on my Lunch Break…

A few days ago I read a great post by Alan Richardson called “How to write a simple random test data sentence generator” and i loved it, it’s exactly what I try and do all the time. In my current context, data is king, without data flowing through our service we effectively have no service. While testing stories, I create tools that do loads of little things but I have a selection of ones that create specific test data. Now, I’m not a developer, I don’t have any sort of development background but what I am, is an inquisitive learner.

I love writing code, not because I’ve been made too or I’ve been told too by my company so that I can automate all the things, I do it because it’s fun! I get a massive sense of achievement when I’ve had an idea for a tool, wrote some code and it’s worked!! It’s not the best looking and most efficient code but it’s my code and i’m proud of it!

So where was I, the random data generator – I read Alan’s post just before lunch and just before i tucked into my food i wrote a very basic app that spit’s out random data. All in all it took me less than 5 mins, it was done as a kind of exercise to prove that absolutely anyone can code something that creates test data. Don’t be afraid of just giving something a go, you might actually surprise yourself!

*This is wrote using Node.js but there’s probably tons of modules and libraries in your preferred language that will allow you to do the same thing*

We need to start somewhere…

In order to get your hands on this random data you’re going to have to download Node.js it won’t take very long and it’s so worth it, not only for this but for many other awesome things that you can create using Node.

Once you have it installed, type node -v into a command prompt or terminal. You should be presented with the current version that you have on your machine. If you’re not seeing the version, don’t panic, you might have to add the node directory to the path environment variable. You’ll find loads of step by step guides for this if you Google it.

node -v

node_version

Let’s do the code part!

So first things first, we need to create a new directory for your new and wonderful data generator to live. Open a command prompt or terminal (you may have one still open) and enter the following commands, as seen below. It’s entirely up to you what the root directory should be, after all, you’re doing this on your own machine.

mkdir random_data_generator
cd random_data_generator

*You don’t have to create this but I just like creating it so that i can give the app to other people*

Next, we need to create the package.json file this is the config file for your node app, it lists all the dependencies that you have in your project and also a bunch of other stuff you may need to add, as the app starts growing legs. You can read all about what this file is and what it does here but for now, we’ll crack on…

In the terminal enter the following and press Enter. Press enter through all the questions and type Y or Yes at the end.

npm init

Now we have that json file created we need to bring in the node module that’s going to do all the leg work for us and create the random data. Casual is a great helper module that rapidly speeds up the process of creating random data. There are a couple more great modules out there that do the same thing, like Chance.js and Faker.js but were going to use Casual this time because it’s the first one I thought of and I’m writing this post so that’s what you’ve got!

Install Casual by entering the following command into your terminal and pressing Enter. The –save in the command adds this module to the packages.json file, honestly, go and have a look if you don’t believe me.

npm install --save casual

When it has finished installing the module, leave the terminal open as you’re going to need it in a few mins.

Create a new file with your favorite text editor (Sublime Text, Notepad++ etc.) and save this in the new random_data_generator directory. For this example, I’ve named the file data.js but you can choose a name that’s more relevant to you.

In the file add the following code…

 // Dependencies
var casual = require('casual');

// Using the module to create random data
var number = casual.array_of_digits(n = 4);

var name = casual.first_name;

// Log the result
console.log(number);
console.log(name);

There are a couple of things going on here and I’ll explain (probably really poorly) what they are, so starting from the top, the first line after the comment brings in the Casual module so that we can use all of that goodness. Next, in the middle section, we’re using a couple of the in-built Casual functions that will create the random data and assigning these to the variables. Finally, we are just logging the output in the console. Very basic and extremely simple.

Using the terminal that you previously opened, type node data.js and press Enter to run the command. If everything has been setup correctly, you will be presented with some random data. It’s as easy as that.

data_output_02

 

If you create another file in the same directory and save this one as user.js I can show you a simple way of creating a set of basic user data. Add the following code below to the file and hit save again. To get an idea about what you can do with the Casual module, check out the documentation.

// Dependencies
var casual = require('casual');

// Custom Data Set

var password = '#A#B#C#D#E#F#';

casual.define('user', function() {
 return {
 Firstname: casual.first_name,
 Lastname: casual.last_name,
 Password: casual.numerify(password)
 };
});

// Write the result to the console

console.log(casual.user);

What this file is doing is creating a data set, defined and configured to your needs. Using the define function of Casual you can package this all together in a lovely little ball and do what ever you like with the output. On this occasion, I’m just logging it out to the console again. There are a few other things happening in this data, i’m using a couple of other inbuilt functions to create a different (very rubbish) password.

In the terminal type node user.js and press Enter to run the command. There you go…some more data for you!

data_output

Where do you go from here…

As you can tell this is very basic and the only thing it really does is print data out to the console – Not that helpful. This was only ever a 5 min task to quickly knock something together, we can expand this out to push the data to a certain file format that your system uses or feed the data into an already established test tool that you have been manually creating random data sets for, etc etc….I like the idea of creating Json files that can be added to apps like Bug Magnet so that you have the data there for you, while you’re doing an exploratory session.

We are only ever limited by our own imagination so it’s entirely up to you where you go from here but i’d love to hear about it so drop me a message!

*If you really can’t be bothered to create a tool yourself – Just Google “Random Data Generator” there’s bloody tons of them knocking about!!

Cheers for reading!

I now have a follow on post where you can put some of this beautiful data to good use…https://dannydainton.com/2016/09/28/everyone-loves-a-bit-of-bug-magnet/