The quality factor Q0 that can be obtained in a superconducting cavity is known to depend on various factors like niobium material properties, treatment history and magnetic shielding. We believe that cooling conditions have an additional impact, as they appear to influence the amount of trapped flux and hence the residual resistance [1 3]. We constructed a test stand using a niobium rod shorted out by a titanium rod to mimic a cavity in its helium tank to study flux trapping. Here we can precisely control the temperature and measure the dynamics of flux trapping at the superconducting phase transition. We learned that magnetic flux can be generated when a temperature gradient exists along the rod and when the niobium transitions into the superconducting state it subsequently remains trapped. Furthermore, it was shown that the cooling rate during isothermal cooldown through the transition temperature can influence the amount of externally applied flux which remains trapped. The acquired knowledge may be used to modify the cooldown procedure of SRF cavities leading to a reduced level of trapped flux and hence operation closer to the BCS limit