You need to use Page.getTitle()
to retrieve current page title, $('title')
won't work. Your code should be:
@Then("target page was opened")
void targetPageWasOpened() {
withWindow({title == 'title'}) {at(TargetPage)}
}
EDIT
If the window is opened asynchronously then you can wrap your code with a waitFor()
call.
@Then("target page was opened")
void targetPageWasOpened() {
waitFor {
withWindow({ isAt TargetPage }) { true }
}
}
isAt()
will suppress any assertion errors and will return false if you're not on TargetPage
. If a window with that page is not found then withWindow()
will throw NoSuchWindowException
imposing another loop inside of waitFor()
closure. If the window is found then true will be returned and the waitFor()
will complete.