lundi 21 août 2017

JUnit stops executing after click closes the popup window

I'm helping a friend of mine with one of his first tests in jUnit. We had a problem recently and I have no idea what can be the cause of that.

We're executing the test which pops up the Facebook login window on our page, then fills up the inputs for login, it's going to close the window and refresh the browser. After logging in we want to continue testing the functionalities for logged in users.

The thing is... After executing click() function on Facebook's login modal window (which closes the modal), test does not follow and acts like it restarts the work, but after a while stops.

To specify the issue better... here's the code sample:

@Before
public void setUp() throws Exception 
{
    driver = new FirefoxDriver();
    baseUrl = "http://ift.tt/KIwo0Y";
}

@Test
public void OrderWithLoginFbCash() throws Exception
{
    driver.get(baseUrl);

    // remembers the parent Windowhandle
    String parentHandle  = driver.getWindowHandle(); 

    // Opens Facebook login window
    WebElement FbLogin = (new WebDriverWait(driver , 20)).until(
        ExpectedConditions.presenceOfElementLocated(By.id("fblogin"))
    );
    FbLogin.click();

    for (String winHandle : driver.getWindowHandles()){
        driver.switchTo().window(winHandle);
    }

    // ... filling up the inputs ...

    WebElement FbLoginFacebook = (new WebDriverWait(driver, 20)).until(
        ExpectedConditions.presenceOfElementLocated(By.id("u_0_0"))
    );
    // everything's still fine here
    FbLoginFacebook.click(); // logs in, closes the window and reloads the page

    // !!! Test won't continue here for some reason. !!!

    System.out.println("Did the logging in stuff"); // Won't be printed

}

I'm not a tester myself, so it's hard for me to say why it's stopping there. I thought it might be because the window it's set for, gets closed on click() of the element, but then I can't think of any walk-around for that problem. Any help would be appreciated. Thank you.

Aucun commentaire:

Enregistrer un commentaire