0

I am using AndroidViewClient to automate testing of my android application. I need to press android device buttons like 'Home', 'Back', and 'Enter'. How Can I do it?

HaMi
  • 539
  • 6
  • 23

1 Answers1

3

Here is a function I wrote for pressing the BACK key:

def back(self):
    self.shell('input keyevent KEYCODE_BACK')

In the same way use keyevent KEYCODE_HOME and keyevent KEYCODE_ENTER for HOME and ENTER keys.
I put those functions directly into adbclient.py file but you can also define them in your code file as external methods.

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Thanks Eliyahu, It worked well, but when I put a method in adbclient.py and call it, it says that this attribute is not defined for adbclient!! – HaMi Jun 08 '14 at 09:07
  • Where and how did you put this method into `adbclient`? It should be defined inside the class there. For example put it directly after `def type(self, text): self.shell(u'input text "%s"' % text)` there – Prophet Jun 08 '14 at 09:12
  • You should do more efforts to solve your problems. The code above appears here on StackOverflow just 3-4 questions before when sorting with AndroidViewClient tag. Where and how to put a method into a class is a basic issue when learning Python... – Prophet Jun 08 '14 at 09:22
  • I put the method in correct place, but it dosen't work. after that, I copy&paste one of it's own methods and change it to your 'back' method and I see it's worked. – HaMi Jun 08 '14 at 09:37
  • I guess the problem is somewhere in your copy & paste. Anyway you can copy some original method, paste it 3 times and edit it to all 3 actions you need... – Prophet Jun 08 '14 at 10:13