Send random text everytime on chat screen

Asked by Harry

class chatting:
    def chat1(self,chatmsg1):
        if exists("person1.png"):
            type(chatmsg1)
        else:
            click("person1.png")
            while not exists("person1.png",0):
                wait(1)
            wait(2)
            type(Key.TAB * 2)
            type(chatmsg1 + Key.ENTER)
            wait(2)

    def chat2(self,chatmsg2):
        if exists("person2.png"):
            type(chatmsg2)
        else:
            click("person2.png")
            while not exists("person2.png",0):
                wait(1)
            type(Key.TAB * 5)
            type(chatmsg2 + Key.ENTER)
            wait(2)

#comres (Common resource)
chatmsg1 = ''.join(random.sample(string.letters, num1))
chatmsg2 = ''.join(random.sample(string.letters, num2))

#Calling
chatting.chat1(comres.chatmsg1)
chatting.chat2(comres.chatmsg2)

Every time it is sending the same text. Is anything wrong in this code.Please help

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Harry
Solved:
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

HI,

I'm not sure where exactly your problem is.
I can see that your chatmsg1 and chatmsg2 are definitely creating a random string of lengths num1 and num2. I'm not sure how your Calling part works though. Are you calling your chat1 and chat2 functions with the same chatmsg or generating a new one each time?

Revision history for this message
Harry (iam-harishetty) said :
#2

Yes it is generating every time the same string as the string is stored in chatmsg1 and chatmsg2 whenever i call chat1 and chat2 function . Is there any alternative to this.

Revision history for this message
Eugene S (shragovich) said :
#3

So why won't you pass a new ''.join(random.sample(string.letters, num1)) to your function every time rather than saving it in a variable?

Revision history for this message
Harry (iam-harishetty) said :
#4

Yes i did that and now it seems to be generating random string