Detroit-based Compuware Corp. said today it has agreed to buy privately held Gomez, Inc., a Lexington, Mass., software firm, for $295 million in cash. Gomez is a leader in Web application experience management. The acquisition is expected to close in November.