Android End to End testing with calabash - android

I am new to using calabash for android, which is a end to end testing framework for android. Iam trying to test a feature where on pressing a button in my app I am taken back to the android home screen. Could someone help me with the test for this scenario? Here is what I have till now
Feature: Return to Home Screen
Scenario: As a user
When I press the "GO" button
Then I should see "HomeActivity" screen appear
I am stuck at the second line. I have tried several alternatives like trying to use the id (Don't think I got the correct id. Does the android home activity have a predefined id?) or different names to test if the home activity appears.

I've created a new action to do exactly that on my github branch
For TabActivities it returns the tag of the current tab.
For other Activities it returns the class name.
actual_activity = performAction('get_activity_name')['bonusInformation']
raise Exception "Expected #{expected_activity} activity but was #{actual_activity}" unless actual_activity == expected_activity

Related

Back button closes app after navigation but not before

I've got an xamarin forms/prism app, and my hardware back button does nothing on the initial page.
If I navigate to another page, it closes the app as expected. If I navigate to the initial page again, it also closes the app - but not if the app just started.
Is there something I'm missing?
My class App mainly has an OnInitialized that navigates to the initial page:
protected override void OnInitialized()
{
NavigationService.NavigateAsync( "MyMasterDetail/MyNavigationPage/StartPage", animated: false );
}
On MyMasterDetail, there are buttons that navigate to MyNavigationPage/SettingsPage and other pages like that.
It doesn't matter if I use Android 5 in Emulator or Android 6 on a real device, the behaviour is the same.
When using a MasterDetail as your root, you are not actually navigating anywhere else. You are simply changing the Detail property of the MasterDetail to another Page. This is not a navigation action. So you are not really navigating. If you want to fake it, you need to add the INavigationPageOptions to your MyNavigationPage and set the ClearNavigationStackOnNavigation property to false. This will continuously push new pages onto the MasterDetailPage.Detail MyNavigationPage without clearing the stack (PopToRoot). Then this will allow your bac button to behave like you are wanting.

PhoneGap/Cordova blank screen on pause/resume

I have a simple html/javascript app that starts and works up fine on an Android device. However, when the app is put in background by using the 'home button' and then brought back to the foreground by clicking on the app again - it starts with a blank screen (white blank screen on android ) and stays that way until the 'back button' is pressed.
Once the 'back button' is pressed the screen refreshes to the last page displayed by the app.
I am new to PhoneGap and I am sure there is something simple/fundamental that I am missing - in terms of how to handle the 'resume' event/etc.. I have followed the instructions provided on this link by Phil Mitchell http://wiki.phonegap.com/w/page/35501397/Tutorials (which is a great resource btw..)
Thanks.
Update :
After looking at the DroidGap code, I have tried to add the following line :-
super.setBooleanProperty("keepRunning", false);
But this does not seem to help. I am happy for the app to exit every time the home button is entered and then do a full restart when the app is clicked on the mobile.
Any help is much appreciated..
I was having the same problem and I want to share a hack that worked for me.
My app is based on ionic/angular/cordova and the android version was giving me a white screen around 50% the times on pause/resume.
When it happened, tapping anywhere on the screen or hitting the back button would make the screen to render again just fine.
I added a div tied to a scope variable named random, like this:
<body ng-app="starter" id="body">
<div>{{ random }}</div>
<ion-nav-view>
</ion-nav-view>
</body>
Then I added a listener inside my app.js to capture the resume event fired by cordova, to then change the random variable and call $apply(), like this:
document.addEventListener("resume", function() {
angular.element(document.querySelector('#body')).scope().random = Math.random();
angular.element(document.querySelector('#body')).scope().$apply();
})
Since the ion-nav-view takes over the whole screen that div never shows up, but angular doesn't know that and refreshes the page, causing the whole thing to work.
(I tried to tie the variable to an invisible element but then angular doesn't refresh the page)
I hope this helps someone!
There seem to be issues around rendering the pages thru PhoneGap and 'Dialog'ing thru Client side FB authentication flow using the JS SDK. If I disable the client side authentication, then the rendering and display of the page works very well, when the app is brought to foreground from background (pause/resume/etc).
I am assuming that the page will need to sense that it is being displayed over a mobile device and use the IOS or Androi SDK for client side authentication.. (if/when I get around to testing that, I update the answer - if there is anybody who has any more light to shed, please feel free to embellish).
If you still say "I am happy for the app to exit every time the home button is entered and then do a full restart when the app is clicked on the mobile." then go for it.
#Override
protected void onStop(){
super.onStop();
}
Try this from where you create activity or from the class which "extends DroidGap".

Android back-button-overriding etiquette / guidelines

I have an app in which the user logs in from a main activity, and then can browse through a heirarchy of entities using listviews. So, the Activity stack would look something like this:
A -> B -> B -> B -> ...
where the number of B's is proportional to how deep you are in the tree of entities.
Frequently, I find myself pressing backbackbackbackback to get to the root (the first 'B'), but one too many presses and I log myself out, or even leave the app. I'm considering overriding the back button so that, when pressed from the root B, it will pop up a dialog essentially saying "Log out? (Y/N)", thus blocking a string of back-presses from completely exiting the app.
I've noticed a sort of sensitivity regarding overriding the back button, though, and - while it makes sense to me - I want to know if this is considered a good use of the back button.
So:
Would this be considered an appropriate/conventional override of the back button?
Is there a better/more conventional way to accomplish this without overriding?
Also, so this question might be more generally useful in the future, are there any guidelines for what is acceptable/unacceptable when overriding the back button?
I would find this use acceptable; I've seen a number of apps that ask for a confirm before exit - if the user wants to exit an app, they usually will press the Home button and let Android handle the finish() if and when it's needed.
I know I've accidentally exited an app by pressing back too many times :(
Dotmister's comment about Handcent is spot on - the back button should feel natural to the user; your use seems to adhere to this, in that a user will cycle back through activities as expected for the most part. As he said though, give it a try and test it.
Coincidentally, I have a similar flow in my app, but I've included a button for the root activity.
No it is not normal to overide the back button because the user ecxpects the back button to function as a... ?? back button.
On the other side if it is really that annoying using the back button in the normal way, than a compremise? will always be better. But make sure the user still has the idea he 'controls' the device according his rules, do not make him look for yours. (dutch way of making a point, sorry).
The only way to find out is getting some people to try your application and see if it's annoying or not.

calling an activity that is in another package(android)

I want to call an activity that is in another package....
Say for example I have an Activity(activity1) in my package(package1) and I need to call another Activity(activity2) in another package(package2) from my activity1..
I have tried to import the package2 in my package1 but it did not work...
Can anyone answer me and provide some sample code?
see
Android: Starting An Activity For A Different Third Party App
final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
intentDeviceTest.setComponent(new ComponentName("fm.last.android","fm.last.android.LastFm"));
startActivity(intentDeviceTest);
where you can change the intent to VIEW depending on your case.
here is my challenging scenario..
step 1;
i have opened google.com from web browser on my emulator and opened some images in that and i pressed home key and opened my app in that i have written code for getting the top activity name and package of currently running task, i mean i got browser's top activity information...
step 2;
from that information i have lunched the browser from my activity..fine browser is launched where it was left previous(showing some images) but when i press the back key on my emulator it is not coming to my app instead it is going back to google.com home page and later if i press back key it is coming to my app....and again if i launch the browser app from my code it is launching in google home page..i want to launch it in image section as i need..

Weird Home button behavior

I'm experiencing kind of strange behavior of my application after hard Home button is pressed.
When you press Home, everything is OK - my app goes to the background, showing Home screen. But if you try to choose my app in the main menu or in the list of last tasks it behaves like it was not started before and does not show the last activity you were on - it just starts from scratch, namely, shows the splash screen and starts next corresponding activities. Moreover, old activities of this app remain on the activities stack, and previous instance of the app is not terminated - so if you press Back for a few times you'll just run into those activities which were undoubtedly started during the previous session of work with my app. Splash screen activity is filtered by "android.intent.action.MAIN" filter and "android.intent.category.LAUNCHER" category.
The strange thing is that all of that happens despite the fact that I do not intercept any Back key hits, or override any onPause or onResume methods. What's happening contradicts with my understanding of Android app lifecycle - I was sure that when you hit Home an app just goes to the background, and when you choose it in the menu later - it just unwinds and does not start anew. (Of course, unless stuff like that is stated in the app manifest or corresponding methods are overridden or something else).
I also checked it for some other lifecycle events - such as changing orientation or flipping hard keyboard out - and none of those led to such strange results. It appears that the problem occurs when you try to start the app from main menu or menu of last applications.
I hope you will be able to help me. Any advice on what to pay attention to or where to search for solution would be really great.
Regards, Alex
You need to set android:launchMode="singleTask" in your LAUNCHER activity in your manifest file.
For more info on the launchMode attribute see here
Note that:
The default mode is "standard".
and:
Every
time there's new intent for a
"standard" activity, a new instance of
the class is created to respond to
that intent.

Categories

Resources