That's called amniocentesis in which Amniotic fluid is taken out from the embryonal sac using an Injection and tested. It's main objective was to check for any chromosomal disorder at a very early stage of pregnancy but Here in India people started using that for detecting the sex of the embryo and illegally aborting the child.