Tag: Testing

Continuous Delivery – OPA and Postman, Newman and Jenkins #3

Continuous Development – OPA and Postman, Newman and Jenkins #3

Following on from the two previous episodes, (part one / part two) the stage is almost set to move to automation over and above the simple concept of a Postman Collection. In this chapter we will see how to use data files in Postman to facilitate making use of CSV or JSON data in a dynamic way, and we will get Newman up and running. So let’s start with the first element.

In our Collection, we currently have one request which is sending information to OPA and getting a journey time and plan back in response. Great. But we want to test our journey planner with more than one journey. And we want to be able to easily change the journeys without having to mess with our request. So this is where the ability to load data into a Collection from a text (CSV or JSON) file comes in very handy in deed. In pictures

  • Create a CSV file with your data in it. For the project used in this example we would need to have something like this

Collection Data File

Notice the headers are origin and destination. They will become variables that we need to add to our request.

  • Make sure that the request is updated

So now my request looks like this:

Request Modified

Don’t forget to save your request. Now if you go to Collection Runner and run your Collection, you can use the Select File button and select your file:

Using a Data File in Postman

As soon as you select the file, you will see that the number of iterations changes to take into account all the rows in your file. Now when you want to push a new set of journey tests all you need is to change that file. Awesome!

Armed with all of this, we can now move to the next challenge. Postman is great but not everyone wants to use the graphical user interface all the time. How about the ability to run a Collection from the command line? That would be great AND would open up lots of options to running Windows Scripts and the like. Well, the news is good. Newman is the CLI (Command Line Interface) for Postman. Setting it up if you are not familiar with Node.js can be a bit daunting, but let’s just make a shopping list first:

  1. Install Node.js (here)
  2. Install Newman using the Node Package Manager
    This step should be as easy as opening the Node Command Prompt (which got installed in your Windows Start Menu in the first part) and typing something like the following:

    Installing Newman

  3. Run Newman from the Node.js prompt to use Postman Runner with your chosen Collection and Data File using the ultra simple command line.

So the last step might look a little like the following – notice that in the command line you specify the Collection (which you must first export to a file from inside Postman) and the Data File (wherever it is – I put both files in the same location for ease of use. And once the job is done, Newman reports back with it’s own inimitable, Teletext-style display of the output. A word of advice – before exporting a Collection make sure you have saved all the recent changes!

Exporting Ready for Newman


Once the Collection is exported, you might run it like this. This is just a simple example. It is possible to also load environment variables and more to fine tune it.

Newman Command Line

After a few seconds we get the output from Newman. Note the 4 iterations, and that iteration 3 failed due to an excessively long journey time.

Newman Output in Teletext

Now this is of course a major step forward – running Collections from the command line, feeding in data sets just by using a simple command line switch – these features mean we can really now start to think of automation in our approach to testing this project. But we are not done yet. The output from Newman is pretty ugly and we need to change that. By installing Newman HTML Reporter, we can get a much nicer file. Follow the steps in the link and then change your example command line to something like this:

Note the new command line option -r html (which means, use the HTML reporter) and the –reporter-html-export option (with two dashes) which ensures the output file is stored in the folder of my choice. And the HTML output is so much better:

Newman HTML Reporter

What a nice document. So far so good. We can spin these collections with just a command line. But wait a minute, what about running tests when you are not in the office – sure, you could write yourself some sort of Powershell Script in Windows. But what if you wanted to run a set of tests every day at 3pm, then again on Tuesdays, then once on the first Monday of every second month…it would get quite hard. And what if you wanted to send the HTML Report automatically to all your colleagues on the testing team…but only if there were failures?

And so, we march onward to the next phase. See you shortly!

Setting up Selenium for IE Testing with OPA

Setting up Selenium for IE Testing with OPA

I appreciate that a post about setting up Selenium has, in theory, not a great deal to do with Oracle Policy Modeling but if you come across a customer, who has Internet Explorer and wants to test their Interviews using their official browser, you will need to do it. The process is not very complicated but it took a bit of hunting around the internet so I reproduce it here

  1. Install Firefox

Of course, Selenium is mostly thought of as a Firefox Plugin IDE : a place for recording and editing scripts to test in Firefox and it is certainly the easiest way to get started.

  1. So go ahead and install the plugin from the Firefox Plugin Store. It is free. Install Selenium as a Firefox plugin so that you have an easy way to record and save your tests.
  2. Install Selenium stand-alone server and IE WebDriver.

You are going to need these to actually drive the tests through Internet Explorer.

  1. I installed selenium java version 2.53.1 since I could not get the newer release (3.x) to work the way I wanted it to, and I was not the only one it would appear.( http://selenium-release.storage.googleapis.com/index.html)
  2. Download the Internet Explorer Driver Server from the same page using the 32bit or 64bit version 2.53.1 depending on your Internet Explorer. Put them in a folder on your hard disk like c:\seltest or whatever you like.
  3. Ensure that JRE or JDK is installed so that you can actually run the java application
  4. In the Options Dialog of the Selenium plugin in Firefox, set the following to indicate you want to use the WebDriver for Internet Explorer.
    Selenium with OPA Setup
  5. Open your Oracle Policy Automation Interview in Firefox and record your script using the selenium plugin (File > New Test Case, then Action > Record). When you have finished recording the basic steps, Action > Record in the plugin dialog. You should have something like this : your script has been recorded.Selenium with OPA Script
  6. Start the IEDriverServer with a command line like
    java -jar -Dwebdriver.ie.driver=IEDriverServer.exe selenium-server-standalone-2.53.1.jar

    from the folder where you dropped the selenium server and IEDriverServer files (c:\seltest in my example)

  7. Actions > Play Current Test Case (or variations on that, as you build more test cases)

Your test will run in Internet Explorer and the output recorded in your selenium window for review.

Selenium with Final Script for OPA

Hint : When you have recorded your initial test case, find the first line (the one that opens the session) and replace the session-specific URL recorded with the base URL from the Deployment Page of your OPA Hub. Otherwise you will have an error with a session being expired (naturally) when you run through the script.

Hint : IE has some difficulties with selecting radio buttons, especially ones that have been replaced with images. You might find you have to rewrite some of the script with check, uncheck or something similar or even with the command RunScript to trigger a click on the image.

Hint : If you get an error about Protected Mode, ensure that all your Security Zones have the same Protected Mode setting (checked or unchecked, they just need the same setting)

Logo by Southpaw Projects LLC