Please advise how & when do the test hysterosalpingography for fertility?

Timed to period. It is usually done right after your period bleeding stops. I do them myself for my patients. I place a speculum in the vagina, clean off the cervical mucous, and injection dye into the cervix for about 1-2 minutes. Most patient never even feel anything. Then i show them the x ray films and the results. So if done properly it is short and non painful.
Just after menses. Hsg is performed just after menses, day 5-9 of the cycle. Hsg is used to diagnose tubal patency, and to investigate the health of the uterus and endometrial lining. It is commonly performed as a part of the fertility evaluation.