Test Automation for Mainframe

Test Automation for Mainframe

Today, automation must be an integral part of producing any software product, even at the initial development stage. It helps you regression test and control product quality before going into production, especially when developers are not budgeted enough time for writing unit or integration tests.

For modern projects, be it Web UI or API, you can always find specialized libraries in almost any programming language (for Java, this is usually Selenium/Selenide for UI and Rest-Assured for API) that will help automate your tests.

But what if the ecosystem includes legacy systems/applications for which modern libraries are not suitable, or the cost of their custom automation is more than budgeted for? What if your E2E script includes steps in UI/API (web-based applications) and interaction with a legacy application, for example, running on OS/400?

This article is about how I adapted open-source software (a 5250 terminal emulator for the IBMi (AS/400) written in Java) for test automation applications working on IBMi OS/400.


Intro

Background

At a Silicon Valley-based company, I faced the problem of automating test cases for an application running on OS/400 - PKMS (Pick Ticket Warehouse Management Systems). If you Google? it and do a keyword search for [AS/400 test automation], you will probably be somewhat disappointed.

Of course, there will be many results intended to sell you a product or service, the content usually lacking what interests me as an engineer:

  • What operating system does this tool run on?
  • What actions are available to me in the SDK?
  • Whether multithreading is supported?
  • Integration with which development languages are implemented?
  • Reporting. Is it possible to take screenshots?


Anyway, after a couple of hours, you begin to understand that someone, somewhere, once had to before you, will attend to the same or similar questions and may even come up with and do something.

In one article, you will find a more detailed description of the companies/products you can use for Mainframe testing.

Here is a shortlist (source: testguild.com):

I decided to adopt the open-source software terminal emulator for IBM written in Java for my needs. Let's see what came of it.


What is AS/400?

No alt text provided for this image

Figure 1. IBMi Application System/400


IBM introduced the Application System/400 in 1988. It was an integrated system featuring hardware (AS/400) and an operating system (OS/400), along with many core functions such as an integrated database.

Both the hardware and the software have gone through many upgrades, revisions, and name changes over the years. From the beginning, one of the strongest features of this platform has been its upward compatibility. You can run a program created for the AS/400 in 1988 on a Power Systems server today with little or no changes.

This seamless compatibility is one reason why many companies that purchased an AS/400 years ago continue to refer to it as an AS/400 even though their Power server is an order of magnitude faster and features cutting-edge technologies.

IBM continues to update the platform today. Every two to three years, they release new versions of the hardware and software that feature quantum leaps forward in processing power and functionality.

Source: helpsystems.com

No alt text provided for this image

Figure 2. OS/400 - Main menu

PkMS

One of the programs for which I had to implement tests was PkMS.?

PkMS (Pick Ticket Management System) is a warehouse management system that controls inventory movement, such as receiving merchandise, inventory transactions, picking and packing, and shipping merchandise to a customer, working under the AS/400 OS (Vendor Manhattan Associates).

Source: docs.oracle.com


TN5250J

After a bit of research, I found an open-source terminal emulator, TN5250J, for the IBM i (AS/400) written in Java, and this could not but make me happy. After all, if I can interact through this terminal in manual mode, I can do all the same through its source code (creating a kind of API) and use this dependency in any project.

No alt text provided for this image

Figure 3. TN5250J – Connection’s tab

The tn5250j is a 5250 terminal emulator for the IBMi (AS/400) written in Java. `It was created because there was no terminal emulator for Linux with features like continued edit fields, GUI windows, cursor progression fields, etc….`

There are 3 modes:

  1. A basic mode.
  2. Enhanced mode that implements the features like masked edit fields and those listed above.
  3. The third is a GUI mode that turns the bland green-screen into a windows GUI (See screenshots).

The GUI part comes in by manipulating the 5250 streams and painting the fields like GUI constructs in windowing systems, GUI looking popup windows in place of windows, painting the PF keys on the screen as buttons (hot spots) so when clicked it will send the appropriate aid key. This is basic GUI enhancements that you can receive and interpret from the 5250 stream. Currently, that is all tn5250j does.

Source: tn5250j.github.io


Initially, TN5250J GitHub project used Ant, which seemed to be a little inconvenient for my purposes (Maven - will automatically download all dependencies and add them to the pass class, I'm not talking about all the other goodies, which come with it as a build tool). And I transferred it to the Maven project and slightly corrected those bugs found by static analysis (PMD, CPD, SpotBugs).

I used next tools:

After rebuilding a new project, I got this dependency in my local Maven repository :

<dependency>
? ? <groupId>org.tn5250j</groupId>
? ? <artifactId>as400-tn5250j</artifactId>
? ? <version>0.9.6-SNAPSHOT</version>
</dependency>        

The resulting dependency is a java-archive file (* .jar) of compiled classes, which is the TN5250J standalone application. You can run it as a separate GUI application using the command:

$\> java -jar as400-tn5250j-0.9.6-SNAPSHOT.jar

The project modified for Maven is no different from the original project. As a real AS/400 operating system for the demo, I will use the PUB400.COM project - a public AS400 server.

No alt text provided for this image

Figure 4. Web page of project PUB400.COM


Demo

Intro

So, what is the demonstration going to be? The test will consist of the following steps:

  1. Open the TN5250J terminal.
  2. Log in to the public AS/400 server and verify that.
  3. Go to the [User Task] menu and verify that.
  4. Go back to [Main menu] and verify that.
  5. Logoff.
  6. Attach all test artifacts (screenshots/screen text representation) to Allure.
  7. Close the TN5250J terminal.
  8. Generate Allure report with the screenshots.

Yes, the test is not complicated, but our goal is not to conquer the whole world - this is just a proof of concept (POC). We will run the test itself from the command line using Maven:

$\> mvn clean site -Duri.as400=pub400.com -Duser.as400={username} -Dpsw.as400={password} -Dport.as400=992 -Dssl.type.as400=TSL -DisVisible

Of all the options, I would like to stop at [ -DisVisible ]. This option launches the terminal in GUI mode and allows you to see what is happening in the terminal and take screenshots. We just change the field values in the JFrame object ( jframe.setVisible (false or true) ). Without this option, the terminal will start in headless mode (but the representation of screens in the form of strings will remain, and you can attach them to a report). That solution can be used anywhere where Java is available. For my tests, I used Jenkins Master/Slave nodes on CentOS (with/without virtual monitor) to run test automation in CI (pipeline as code / JenkinsFile).

A few words about the technical part for working with [ 5250J terminal ] before the demonstration: we will use the dependency of the 5250J emulator in our demo project so that we could use its classes, functions, and resources in our program.

No alt text provided for this image

Figure 5. High level diagram of: 5250J terminal + AS/400 + User actions

We will proceed with I/O (Input/Output) for the `green screen` application. The general idea is very similar to Selenium (a library that allows you to communicate with the browser and send commands to it: open page, click etc.), where the 5250J terminal is an analogue of the browser (which receives HTML + JavaScript and forms a page) - displays the contents of the screens and allows you to fill in various input fields and simulate function keys (F1 - F24).

No alt text provided for this image

Figure 6. TN5250J dependency in demo project (Maven)

Selenium uses locators to work with HTML elements. Accessible by XPath, ID, CSS, by name, etc. In our case, for AS/400 applications, you need to know their ID (digits) or text label on the screen before/after the input fields to access the input fields.

No alt text provided for this image

Figure 7. PUB400.COM – Login


+++++++++++++++++++++++ AS400 screens delimiter ++++++++++++++++++++++

Welcome to PUB400.COM * your public IBM i server

Server name . . . : ? PUB400

Subsystem . . . . : ? QINTER2

Display name. . . : ? DEVNAMETES

Your user name:

Password (max. 128):




===============================================================================

> Hope to see you at the Common Europe Congress in Copenhagen

(Oct 31 - Nov 3) see https://comeur.org/cec2021/































connect with SSH to port 2222 -> ssh name§pub400.com -p 2222

visit https://POWERbunker.com for professional IBM i hosting




(C) COPYRIGHT IBM CORP. 1980, 2018.

+++++++++++++++++++++++ AS400 screens delimiter ++++++++++++++++++++++++        

Figure 8. A text representation of the AS/400 screens in the 5250J terminal (logged for debugging).

The application screen in AS/400 in the 5250J terminal is represented as an array of characters (each line of the screen is an element in this array - this solution is not the only solution. It's how I decided to act :) ). I used Regular Expressions to navigate them.

The [ SessionBean ] class is responsible for communicating with the 5250J terminal to open a session, retrieve screen content, and send some commands or keys.

In the interface [ TerminalElementsMethods ], I put those methods that I will need for simple manipulations in the demo (such as sendKeys, fillFieldWith, isTextPresent, etc).

No alt text provided for this image

Figure 9. SRC. Interface [TerminalElementsMethods]

The [ TerminalDriver ] class contains the implementation of the [ TerminalElementsMethods ] interface. If you look at them, see how they manipulate the screen as text. The entire screen with its labels and fields is treated as an array of characters.

No alt text provided for this image

Figure 10. Text label and field ID on the AS/400 screen

Since we will be using TestNG (to run our tests) for the convenience of the code, we will define some test fixtures (open/close terminal) in @BeforeTest and @AfterTest.

No alt text provided for this image

Figure 11. TestNG @BeforeTest / @AfterTest

The same applies to the listener for tests - when the test fails, it will take screenshots of the terminal and grab all screens in a text view for a report in Allure.

No alt text provided for this image

Figure 12. TestNG @Listener implementation

The test uses two screens, and their code is written as a Page Object Model. In general, nothing special if you've written (or are writing) tests for web UI applications. The classes in the POM are written so that they allow for chain invocation (just for convenience).

No alt text provided for this image

Figure 13. POM. Main Menu page

After the above, the test class will turn out to be very concise since the test fixture is defined in @BeforeTest / @AfterTest.

No alt text provided for this image

Figure 14. TestNG. Test method implementation (most of the annotations related to Allure report)

No alt text provided for this image

Figure 15. Allure report (HTML+JS)


Conclusion

Never say never. The purpose of the demonstration is to show that it is possible, using open-source software (TN5250J terminal emulator), to automate the actions of a real user for applications on Mainframe using a set of tools that are standard in Java test automation (Maven, TestNG, and Allure report). The real work was in defining unique text labels (before/after) for input fields and identifying their IDs; complexities like the write locators for the Selenium UI test (dynamic XPath) and a working knowledge of Regular Expression that is part of every SDETs regular work. The tests themselves can be multithreaded in any language that supports it (Java, in this example) and integrated into any CI.


P.S. Post Scriptum

The more detailed information you can find in the GitHub demo repository:?

In [README.md], you can find a full description of the project and command-line options for a demo project along with:

  1. Links and documentation related to the project TN5250J and PUB400.COM
  2. Zipped Allure report (with attached screenshots and text screen representation)
  3. Recorded demo of test execution (MOV) or YouTube link.

Special thanks to Scott S Nelson for reviewing and commenting on the drafts.


References

  1. https://tn5250j.github.io
  2. https://en.wikipedia.org/wiki/IBM_System_i
  3. https://www.helpsystems.com/blog/as400-dead
  4. https://pub400.com
  5. https://testguild.com/mainframe-testing
  6. https://docs.oracle.com/cd/E69185_01/cwdirect/pdf/180/cwdirect_user_reference/WH13_01.htm

Jorge de Paz

Artificial Intelligence Specialist | Software Engineer

1 年

?Powerfull information! ?Have you mixed selenium or cypress with terminal emulators API's?

回复
Andres Acosta ????

SDET | QA Test Engineer Specialist at Scotiabank

1 年

Hi Yurii, really interesting post, do you have details about moving the jar from Ant to Maven or gradle ?

回复

要查看或添加评论,请登录

Yurii C.的更多文章

  • Multi OpenAPI documentation

    Multi OpenAPI documentation

    I. Intro You are probably already familiar with microservices, how good it is to have them (the more, the better :) )…

  • Context. It all depends on context!

    Context. It all depends on context!

    I. Intro I have often been asking if I know REST API and if I can test API (automation/manual).

  • Implementation of custom HTTPS sender for JMeter and InfluxDB

    Implementation of custom HTTPS sender for JMeter and InfluxDB

    Objective Cyber Security - today everyone is concerned about it, whether you are just a user or a company. This topic…

  • Selenide - sugar for Selenium.

    Selenide - sugar for Selenium.

    Do not fear. This is not one of many articles about the Selenium framework.

社区洞察

其他会员也浏览了