If you have don't have spark, then the electronic ignition module may have failed, or possibly the coil has failed. Either of those could die slowly, causing the intermittent shut off problems before they died completely. Sometimes they initially fail only after the engine is hot.
It is difficult to check the integrity of the electronic ignition, but there are some tests you can do that will partially check the integrity of the coil. However, on some engines the ignition module and coil are combined as one part.
If you do have spark, then I think RANDYT's post about the fuel solenoid is a good idea, but I can't say for sure that your engine has or does not have one.
Tell us what model the mower is. Others on here probably have the same machine, and may have had similar problems. And some of us will look up the parts diagram on-line for your machine so we can give you better suggestions. The more information you provide, the better the responses you will get on this forum.