Re: how to click back button of launcher

1,340 views
Skip to first unread message

naveed

unread,
Jun 14, 2012, 2:53:36 AM6/14/12
to Robotium Developers
Are you able to get activity name of dialogue ? Try to get activity
name of dialogue using
'solo.getCurrentActivity().getLocalClassName().toString()'

If that specific activity is from the your TargetPackage, it should
work fine. Get activity name and then we can see further....

On Jun 13, 3:38 pm, Manasa Muchchatti <man...@ninetology.com> wrote:
> Hi,
>
> I have a activity- OnlineThemesInstallation to be tested. in that activity
> we have two options-1.Latest and 2.Most Popular Themes to choose. when we
> click on Latest->theme image to get installed, another process is getting
> started(confirmation activity-"Do you want ti install"), from where i cant
> proceed further. But in that same test i want to test for Most Popular
> option also.
>
> I have written by TC as below:
>
> public void testOnlineThemeOptions()throws Throwable{
>
>         /* test    Most Popular Tab */
>               testOnlineTheme();
>               solo.clickOnText("Most Popular");
>              // assertEquals("Theme images are not
> found",true,solo.getCurrentImageViews());
>               solo.clickOnImage(2);
>               solo.finalize();
>               solo.sleep(5000);
>
>               /*test Latest tab */
>               testOnlineTheme();
>               solo.clickOnText("Latest");
>              // assertEquals("Theme images are not
> found",true,solo.getCurrentImageViews());
>               solo.clickOnImage(15);
>
> }
>
> Now when it tries to click on Latest that dialogue("Do you want to install
> Theme") is still running. I want to click on Back button of Launcher or do
> some stuff to kill this dialogue.
>
> Anyone have a solution fr this,will be of great help.
>
> Thanks,
> Manasa I M

Manasa Muchchatti

unread,
Jul 11, 2012, 8:40:00 AM7/11/12
to robotium-...@googlegroups.com
Found solution for this,

new Thread() {
                public void run() {
                    Instrumentation inst = new Instrumentation();
                    inst.sendKeyDownUpSync(KeyEvent.KEYCODE_POWER);
                }       
            }.start();


It clicks hardware back button.

Manasa Muchchatti

unread,
Jul 12, 2012, 2:12:57 AM7/12/12
to robotium-...@googlegroups.com
sorry little change in my previous code,


new Thread() {
                    public void run() {
                        Instrumentation inst = new Instrumentation();
                       inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
                    }       
                }.start();

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/robotium-developers/-/uJi1IX_dT0wJ.

To post to this group, send email to robotium-...@googlegroups.com.
To unsubscribe from this group, send email to robotium-develo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotium-developers?hl=en.



--
Thanks and Regards,
Manasa I M

Renas

unread,
Jul 12, 2012, 2:16:33 AM7/12/12
to robotium-...@googlegroups.com
Or you can just use solo.sendKey(KeyEvent.KEYCODE_BACK);

/Renas

Renas

unread,
Jul 12, 2012, 2:16:54 AM7/12/12
to robotium-...@googlegroups.com
Or solo.goBack() :)

/Renas

Manasa Muchchatti

unread,
Jul 12, 2012, 2:24:30 AM7/12/12
to robotium-...@googlegroups.com
thanks.

I have one more problem, i'm writing testcases to lock and unlock device(Pressing on power button). so that i can test on lockscreen,

So is there a way to click on that power button?

Pls i have been searching for this from a long time and not find any solution for this.

Thanks,

Yahor Paulavets

unread,
Jul 20, 2012, 7:15:28 PM7/20/12
to robotium-...@googlegroups.com
Hello,

I have some related articles:


1. If your device is rooted, you can use it from Java layer.

2. Perhaps, if you device is not rooted, input keyevent 26 would work from Java layer.

To unlock any device, you can try to use WakeLock object. To lock device, you can wait 2 minutes, while it looks itself, or try to do a research, how android.intent.action.SCREEN_OFF affects your device (not sure about correct Intent action).

Also, you can create a robot from lego, and control it over bluetooth from device, introduce own framework to handle impossible from Java layer situations, like Device physical rotations, Power button clicks etc :)

What did you try to get this goal achieved?

Happy testing! (:

Best regards,
Yahor

On Fri, Jul 20, 2012 at 7:15 PM, Tony <tonywin...@gmail.com> wrote:
Hi,

> So is there a way to click on that power button?

Is there any update on this yet?

Basically, I want to do this:
  - solo.sendKey(KeyEvent.KEYCODE_POWER) to turn-off and lock the screen
  - solo.sendKey(KeyEvent.KEYCODE_POWER) to turn-on the screen
  - solo.sendKey(Solo.MENU) to unlock the screen (and go back to the app)

Thanks,
Tony
Or solo.goBack() :)

/Renas



To post to this group, send email to robotium-developers@googlegroups.com.
To unsubscribe from this group, send email to robotium-developers+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/robotium-developers?hl=en.
--
Thanks and Regards,

Manasa I M

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To post to this group, send email to robotium-developers@googlegroups.com.
To unsubscribe from this group, send email to robotium-developers+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/robotium-developers?hl=en.

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To post to this group, send email to robotium-developers@googlegroups.com.
To unsubscribe from this group, send email to robotium-developers+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/robotium-developers?hl=en.



--
Thanks and Regards,
Manasa I M

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.

Dacong Yan

unread,
Jul 21, 2012, 5:34:22 PM7/21/12
to ypaul...@agilefusion.com, robotium-...@googlegroups.com
Hi Yahor,

Thanks for the info! I learned a lot.

What I'm trying to do is the following:

1. Test the app behavior when HOME is pressed, and then we go back to the app.
2. Test the app behavior when POWER button is pressed twice, and then
we unlock the screen to go back to the app.

And the whole point is that I need to go back to the original activity
in the app rather than create a new one. Otherwise, the app is not
doing exactly the same thing as we are pressing the buttons manually.

For now, I'm doing it entirely inside an emulator, so rooting is not a
problem yet.

Any suggestions?

Thanks,
Tony
>>>>>>> robotium-...@googlegroups.com.
>>>>>>> To unsubscribe from this group, send email to
>>>>>>> robotium-develo...@googlegroups.com.
>>>>>>> For more options, visit this group at
>>>>>>> http://groups.google.com/group/robotium-developers?hl=en.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Thanks and Regards,
>>>>>>
>>>>>> Manasa I M
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Robotium Developers" group.
>>>>>> To post to this group, send email to
>>>>>> robotium-...@googlegroups.com.
>>>>>> To unsubscribe from this group, send email to
>>>>>> robotium-develo...@googlegroups.com.
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/robotium-developers?hl=en.
>>>>>
>>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Robotium Developers" group.
>>>> To post to this group, send email to
>>>> robotium-...@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> robotium-develo...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/robotium-developers?hl=en.
>>>
>>>
>>>
>>>
>>> --
>>> Thanks and Regards,
>>> Manasa I M
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Robotium Developers" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/robotium-developers/-/QcmR1gjxNl0J.
>>
>> To post to this group, send email to robotium-...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> robotium-develo...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/robotium-developers?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Robotium Developers" group.

Yahor Paulavets

unread,
Jul 22, 2012, 6:34:35 PM7/22/12
to robotium-...@googlegroups.com
Hello,

I thought I gave the answer :)

Simple algorithm:

a) Do your Robotium test
...
b) Invoke input keyevent 26 from your robotium test, it isvery simple code, like: "Runtime.exec("input keyevent 26") bla bla bla
This will simulate power button click

c) sleep N seconds

d) click Power again and use WakeLock (google it, there are a lot of snippets) to unlock the screen

e) your activity should be on the screen 

f) continue testing :)

The same algorithm for Home buttom, except d) step. You will have to fire an Intent for your activity to bring it to the foreground.
You can assert by Robotium solo code, that it is previous activity and not new.

Simple! :)

Happy testing (:

Best regards,
Yahor

Dacong Yan

unread,
Jul 22, 2012, 8:30:56 PM7/22/12
to robotium-...@googlegroups.com
Hi Yahor,

>> b) Invoke input keyevent 26 from your robotium test, it isvery simple >> code, like: "Runtime.exec("input keyevent 26") bla bla bla
>> This will simulate power button click

I thought that would work, and it was what I have been trying. But it
didn't. And now I starting thinking - what is the difference between
doing that and calling solo.sendKey(26)?

I tried another approach based on record-n-replay. I recorded the
sequence POWER-POWER-MENU, and replayed it. It worked fine if I launch
the app manually, and start replay at command line. When I tried to
start replay from within robotium, something like
Runtime.exec("/path/to/replay"), it failed to open /dev/input/event0
saying "EACCESS (Permission denied). I googled it, added the
permission declarations in AndroidManifest.xml, but it didn't work
either. Any clue?

Thanks,
Tony

On Sun, Jul 22, 2012 at 6:34 PM, Yahor Paulavets

SelvaKumar Muruganantham

unread,
Jul 23, 2012, 12:53:48 AM7/23/12
to robotium-...@googlegroups.com
Thank you Yahor Paulavets.
It's more useful for me.

Yahor Paulavets

unread,
Jul 23, 2012, 1:01:54 PM7/23/12
to robotium-...@googlegroups.com
Hello,

Please paste your not working code snippet.

Best regards,
Yahor

Yahor Paulavets

unread,
Jul 23, 2012, 1:04:03 PM7/23/12
to robotium-...@googlegroups.com
Hello,

Magic tip for " it failed to open /dev/input/event0"

~$ adb shell chmod 777 /dev/input/event0

Happy testing (:

Best regards,
Yahor

Dacong Yan

unread,
Jul 23, 2012, 1:09:32 PM7/23/12
to robotium-...@googlegroups.com
Yahor,

Thanks for the tip. I think it should work. But I worked around it by
issuing adb commands from the host side when special logcat messages
are printed by the JUnit test cases. By doing that, I can always use
record-n-replay and do not have to worry about wakelock, permissions
and so on.

The broken code is simply:
Process p = Runtime.getRuntime().exec("input keyevent " +
KeyEvent.KEYCODE_POWER);
p.waitFor();
Log.i(TAG, "POWER pressed");

After executing that, nothing happened.

Thanks,
Tony

On Mon, Jul 23, 2012 at 1:04 PM, Yahor Paulavets

Dacong Yan

unread,
Jul 23, 2012, 1:11:35 PM7/23/12
to robotium-...@googlegroups.com
ps.

Obviously, I would have added enough sleep time after executing the
input command.

Yahor Paulavets

unread,
Jul 24, 2012, 4:47:57 AM7/24/12
to robotium-...@googlegroups.com
Hello,

"After executing that, nothing happened."

If you try to read Error stream, I think you can get the reason, why nothing happens.

Or try to do equivalent manual actions:
~$ adb shell
# su system
$ input keyevent 26

I just checked, my device has locked after this command.

Best regards,
Yahor
Reply all
Reply to author
Forward
0 new messages