The next generation of surveys will greatly improve our knowledge of cosmological gravity. In this paper we focus on how Stage IV photometric redshift surveys, including weak lensing and multiple tracers of the matter distribution and radio experiments combined with measurements of the cosmic microwave background will lead to precision constraints on deviations from general relativity. We use a broad subclass of Horndeski scalar-tensor theories to forecast the accuracy with which we will be able to determine these deviations and their degeneracies with other cosmological parameters. Our analysis includes relativistic effects, does not rely on the quasistatic evolution and makes conservative assumptions about the effect of screening on small scales. We define a figure of merit for cosmological tests of gravity and show how the combination of different types of surveys, probing different length scales and redshifts, can be used to pin down constraints on the gravitational physics to better than a few percent, roughly an order of magnitude better than present probes. Future cosmological experiments will be able to constrain the Brans-Dicke parameter at a level comparable to Solar System and astrophysical tests.