Why even call mainpage.get()
after loginPage.clickJoin()
? Wouldn't the interaction with elements on the page take you to the next/previous one?
In general, you should be able to interact with the mainPage
object returned from clickJoin()
right away. You should not have to call get()
again. If you're getting errors without it, it's probably because of the code executing too fast, without actually waiting for the page to load properly.
To avoid this, you can have the loginPage.clickJoin()
method make sure that the main page has loaded again.
public MainPage clickJoin() {
joinLink.click(); //clicking some link/button or whatever should take you to the page
new WebDriverWait(driver, timeToWait).until(
//here you can use the ExpectedConditions class to wait for the title
//to change to a specified value or something similar. There's a wide
//variety of methods provided. Alternatively, you can implement the
// ExpectedCondition interface yourself
);
return new MainPage(driver);
}
If the page fails to load, you'll get an exception and the test will fail.
You don't have to do it the exact same way as in the pseudocode above but a WebDriverWait
seems like a way to make sure the right pages load when navigating between them.