Just write a function in a retry, which checks if the pop-up appears then it calls your login function.
Try to use retryAnalyzer of TestNG
import org.testng.Assert;
import org.testng.annotations.Test;
public class Test001 {
@Test(retryAnalyzer = Tests.RetryAnalyzer.class)
public void Test1()
{
Assert.assertEquals(false, true);
}
@Test
public void Test2()
{
Assert.assertEquals(false, true);
}
}