Having spent many hours trying to work out why my printer HP 5740 wasnt able to print a test page or be able to print from office applications, even though the install is correct, I can ping it on the network and even run the scanner.
It turns out that the user logged in needs to have full control access to the temp and tmp folders for the system. Very strange requirement but it does work.
Found the solution here
https://h30434.www3.hp.com/t5/Printer-Software-and-Drivers/Test-Page-Failed-to-Print/td-p/5880738
My setup was a network connection using a TCP/IP port, very basic setup.