Yes, certainly comfort breaks are made on long bus rides. There are smokers on the buses, and they want a break, too. It's just that I had that one bus trip...
Virtually every regular European train I've been on has had toilets. I say "regular" because I don't think the little Yellow Train in the (French) Pyrenees had them, and I can't guarantee that commuter-rail cars are so equipped, because trips on them would be rather short; some are a bit like subways that run above ground. Occasionally one of the toilets on a regular train is out of commission and locked, but generally you can just walk into the next car to find a working toilet.
Back to the bus situation: It's not uncommon for a bus to be stopped at a town of some size for about five minutes as people retrieve luggage from the hold and new passengers put their luggage in the hold and show their tickets. If you're ready to hop off the bus the moment the driver opens the door, you might have time. Just say "toilet" in the local language as you hop off the bus. No promises on this; I can't 100% guarantee the bus won't abandon you. But it's what I did on the Granada-Valencia bus ride.