Possible to write tests for windows?

After some headaches with a project where I made some mindless mistakes where I’d change something that broke something else, I realized I really wish I had a way to test my window and go through all the possible outcomes programatically to make sure after I make a change everything is still working right.

I know that Ignition does not really have this built in, but is it possible? Seems like it should be but I have a few different idea’s on how to do it. I’m looking for input from anyone who does have some meaningful way to test their windows.

Idea #1:

def testWindow():
    import system
    system.nav.openWindow("Test Window", {'param1':'testValue'})
    window = system.gui.getWindow("Test Window")
    rc = window.getRootContainer()
    button = rc.getComponent('submitButton')
    button.doClick()
    etc...

and from here run buttons.doClick(), fill in forms with test data, and then check after to make sure that my database updated appropriately. Down side is having to script all the GUI interactions, and also it’s writing data to my actual database though I can always save and delete the appropriate id’s at the end of the test. The other downside is that this will run all gateway scripts and do file changes if the window asks for it, which sometimes may be appropriate to test but not always desirable to end up having 100 test .txt files.

Idea #2:
Requires some preplanning and desire to do this from the start. But, each button/action that the user can do runs a function, and each function has a parameter “testMode=False” which is tied to a client tag. The functions would be called like project.myWindow.doSubmit(testMode=system.tag.read(‘testMode’).value)

def testWindow():
    import system
    system.tag.write('testMode', True)
    system.nav.openWindow("Test Window", {'param1':'testValue'})
    window = system.gui.getWindow("Test Window")
    rc = window.getRootContainer()
    button = rc.getComponent('submitButton')
    button.doClick()
    system.tag.write('testMode', False)

The obvious downside is having to make sure the tag rewrites to False along with the extra scripting in each function like

if not testMode:
    # do some file manipulations
else:
    # simulate file manipulation/just check and don't actually write file

These were two ways I’ve thought of. Is there some way that is used?

There is, unfortunately, no easy way to do this, as you’ve noticed. You might look into java.awt.Robot for testing UI automation, and for a variety of reasons I’d recommend moving as much scripting logic as possible to project script modules, which then makes it easier to test, although still not particularly easy.

One option, that’s a bit “risky”, would be to “stub” functions like system.tag.write() - I can’t remember whether we made this impossible, but I remember someone in support rebinding system to their own variable, so within a scope you could define a new write function, a new tag class, and a new system class, then define that as system - but making sure that doesn’t “leak” outside of your testing setup could be tricky.

1 Like