The test is not painful, but it does cause some cramping like when you have your period.
The following is taking from a radiology website:
WHAT TO EXPECT FROM A HYSTEROSALPINGOGRAM:
This exam should cause only minor discomfort.
There may be slight discomfort and cramping when the catheter is placed and the contrast material is injected, but it should not last long. There may also be slight irritation of the peritoneum, the lining of the abdominal cavity, causing generalized lower abdominal discomfort, but this should also be minimal and not long lasting. Most women experience vaginal spotting for a few days after the examination, which is normal.
Hope this helps to ease your fears. If you need the test done, you should have it done. Good luck.
You should know that there are several methods of doing this test - x-ray, ultrasound, and surgery. Please verify which method your doctor will be choosing and ask them for information. In all likelihood, it will be fairly tolerable, but be sure to take ibuprofen before the test.