Php – Code to simulate a users actions, such as logging in

PHPprogramming practicesweb-applications

I've recently begun working on a PHP application, replacing another developer. I believed the application was using an API to communicate with a remote service but when I looked through the code I found that it was using a set of functions to actually log in, fill out forms and submit them as a user might do in a browser.

My intention is to replace this code, to use the services API instead. I've considered leaving the code as is and not replace it. It makes me wonder though is this a common practice in the software industry? To have a programme simulate a users actions in a browser to perform a set of actions? It feels to me that this is clever but poor programming, Have any other developers seen this?

Edit: Sorry, should have added this in the first place, the code I describe isn't part of a testing suite, its live code.

Best Answer

Although many may view this as generally a bad idea to implement such practices, there may have been a legitimate reason for doing this sort of thing.

As developers, many of us do like to perfect our code to minimize our technical debt; however, at the end of the day the one thing we must remember is that we are hired to meet a business goal. Sometimes meeting those goals involve some creativity, thinking outside the box, and doing things that would be considered out of the ordinary and contrary to what the rules/guidelines say to do.

If you wanted to fix the problem, I don't see why you couldn't, but I wouldn't knock the original developer because this tactic -- back when it was implemented -- could have meant the difference between saving a client and losing a client.