Web- Get text from another Custom Keyword

Custom Keyword1

@Keyword
def custkeyword1(Name) {
‘Fetch Confirmation Message and Accept Alert’
String alert = driver.switchTo().alert().getText()
‘Contact Admin Message’
String contactadmin = driver.switchTo().alert().getText()
driver.switchTo().alert().accept()
‘Message status’
List message = [alert, contactadmin]
return message

}

Custom Keyword2

@Keyword
def custKeyword2(Name) {
(new PackageName.className()).custKeyword1(Name)
}

How to get Text of Custom Keyword2 alert and contact admin messages when i run Custom Keyword2

I tried
String message = (new PackageName.className()).custKeyword1(Name)
List getmessage = [message]
return getmessage
but not working could you please help me on this

custkeyword1 is not returning a String, it’s returning a List, so your problem is with the first line. It should be something like this:

List messages = (new PackageName.className()).custKeyword1(Name)
return messages.get(0) // ... or messages.get(1), depending on which message you want to retrieve
1 Like

Is that possible to use return messages in another custom keyword by storing values and sending
Eg
@Keyword
def cusKey1(){
‘Fetch Confirmation Message and Accept Alert’
String alert = driver.switchTo().alert().getText()
driver.switchTo().alert().accept()
WebUI.delay(2)

‘Contact Admin Message and Verify the Agent is not Deleted’
String contactadmin = driver.switchTo().alert().getText()
driver.switchTo().alert().accept()

‘Message status’
List message = [alert, contactadmin]
return message — I will use this message in Testcase
}

@Keyword
def cusKeyword2(){
‘Messages’
Listmessage = (new packagename.class()).cusKeyword1()
return message
}
In this case I am calling first keyword in second Keywordbut unable to get messages , since its returned in First Keyword
I used to store like def alertmsg = alert
but still i couldnt get the message what to do in this case, can you please help me

I don’t understand why you need cusKeyword2(). All it’s doing currently is calling cusKeyword1() and returning the same list of messages. It’s not providing any value. But if you want to do this kind of thing, it would be something like:

def keyword1() {
    List list = [...]
    return list
}

def keyword2() {
    List list = keyword1()
    return list
}

def keyword1() {
List list1 = […]
return list1
}

def keyword2() {
List list2 = keyword1()
return list2
}
Unable to print list 2 since the values(list1) returned in keyword1 itself
need to print list 1 list in keyword2.

You certainly can print the list:

def keyword2() {
    List list = keyword1()
    println list
}

But again, I don’t see any added value of this.