Hi Marcin,
thanks for your answer.
First a little informationa bout the Site I am Testing. This site contains several Modules , one of them is the communication module, which in the end is a mailbox similar to gmail. The difference is every message or process i start or read opens up in a new popup window.
The way i implemented the tests at the moment is:
Page A: Communication Page
Page B: Message Page
When i create or read a message i switch from Page A to the new popup Page B and start working in the popup
In Page B I have added the modules like it is described in the manual
This is the PageObejct for the Communication Page
class CommunicationPage extends MainPage {
static final String windowName = mainWindowName
static at = { appName.text() == 'communication' }
static content = {
commTab { type -> $('div.TabPaneHeaderLabelContainer', title: type) }
newMessage(required: false, toWait: true) { $('div#IconHolder_newConversation') }
refreshButton { $('img.Button') }
messageRows(required: false) { $("[id^=row_conversationsListTable_]") }
messageSubject(required: false) { subject -> messageRows.$('a', text: subject) }
}
def commType(String tab) { commTab(tab).click() }
def refreshList() { refreshButton.click() }
def Map startMessage() {
commType('Messages')
newMessage.click()
def Map originals = switchWindow(new MessagePage())
return originals
}
def createMessage(data) {
def Map originals = startMessage()
browser.page.fillMessage(data)
browser.page.send(originals)
}
def checkMessage(data) {
refreshList()
def Map originals = openMessage(data.subject)
browser.page.validateMessage(data)
browser.page.close(originals)
}
def Map openMessage(String subject) {
messageSubject(subject).click()
def Map originals = switchWindow(new MessagePage())
return originals
}
}
switchWindow is defined in the MainPage Class:
def Map switchWindow(Page windowPage) {
def String windowName = windowPage.windowName
def anyMatching = false
def Map originals = [originalWindow: browser.currentWindow, originalPage: browser.getPage()]
final String windowHandle = browser.driver.getWindowHandles().find {
winHandle ->
browser.withWindow(winHandle) {
browser.js.exec('return window.name').toString().startsWith windowName }
}
try {
browser.driver.switchTo().window(windowHandle)
waitFor { !browser.$('img#emptyWaitImg').displayed }
browser.verifyAt()
anyMatching = true
} finally {
if (!anyMatching) {
browser.driver.switchTo().window(originals.originalWindow)
throw new NoSuchWindowException("Could not find a window that would match the given Name $windowName")
} else {
return originals
}
}
}
Here the MessagePage Page Object :
class MessagePage extends MainPage (<- MainPage extends geb.Page) {
static at = { ...at checker...}
static content = {
.
.
.
.
fill { module FillActivity}
verify { module VerifyActivity}
}
def validateMessage(data) {
//assert checkMessageText(data.text)
verify.verifyActivity(data)
}
}
Here the VerifyActivity Module:
class VerifyActivity extends Module {
static content = {
subjectSent(required: false) { $('div.subject') }
recipientsSent(required: false) { $('table.recipients') }
targetDateSent(required: false) { $('div.targetDateContainer') }
frameMessageSent(required: false, wait: true) { $('[id^=frmdbCnv-]') }
messageTextSent(required: false, wait: true) { $('div.msgContents') }
}
def verifyActivity(data) {
assert checkMessageText(data.text)
.
.
.
.
}
def boolean checkMessageText(String text) {
withFrame(frameMessageSent) {
B1 messageTextSent.text().contains(text)
}
}
}
If I use the method 'checkMessageText()' and its locators frameMessagesent and messageTextSent in the Page Object MessagePage, all works fine.
If I use it like this and run the test I get:
at CommunicationPage checkMessage(messagedata)
| | |
| | data.MessageData@1e3d7dd
| groovy.lang.MissingMethodException: No signature of method: geb.waiting.UnknownWaitForEvaluationResult.text() is applicable for argument types: () values: []
| Possible solutions: getAt(java.lang.String), wait(), wait(long), wait(long, int), every(), find()
pages.CommunicationPage
When debugging it , and setting a breakpoint (B1) at messageTextSent.text().contains() ,on evaluating navigator.base I get :
stale element reference: element is not attached to the page document
(Session info: chrome=54.0.2840.99)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9 milliseconds
Hope this helps, or do you need more information?
Regards
Yori