Proper way to close dialogs in Flutter tests - testing

Flutter's WidgetTester has a pageBack() method for popping the route stack. When I open a page as a fullscreen dialog using MaterialPageRoute's fullscreenDialog property, the pageBack() method does not work ("One back button expected on screen"). I can't find an alternative method for the job.
What is the standard way to cancel/close a dialog in a Flutter test?
I am able to close the dialog as follows:
await tester.tap(find.byIcon(Icons.close));
But then I could have instead done a pageBack() as follows:
await tester.tap(find.byIcon(Icons.arrow_back));
Why have the pageBack() method but no equivalent for closing a dialog?
I have not yet written my Cupertino UI yet. Will that test need to look for a different icon?
See also a similar problem I had with selecting the overflow menu.
UPDATE: Maybe pageBack() emulates pressing the system back button, not the back arrow? In that case, there would be no need to emulate the behavior on iOS, and I would have to find the back button by icon to emulate pressing it, anyway.

You can have a dialog that contains a button with a text 'X', which pops the dialog.
This button, you can find with
await tester.tap(find.text('X'));
and don't forget to pump to go through with the tap
await tester.pumpAndSettle();
Have a look at the full code sample the flutter team is using to test dialogs: source code

I think finding by Icons.close seems reasonable. I did similarly in my app. Another option could be assuming the x,y of the button in the navigation bar and just tapping at that location on the screen.

I faced a similar problem earlier and I found the following solution that worked fine for my case.
Navigator.of(context, rootNavigator: true).pop('dialog')
Or you can write like,
Navigator.of(context).pop();
Navigator.pop(context);
You can check the brief documentation on Flutter Navigation and Routing here.
Hope, this would work. Have a great day.

Related

react-native-router-flux - Resetting navigation stack in tab

What we want
We use react-native-router-flux in our application and find ourself in a situation where we need to reset the navigation stack (at least) for one tab. This is our scene structure:
tabs
listTab
listView
recordingView
creationTab
recordView
descriptionView
publishView
Concretely, our application lets users create and view recordings. There's a listTab, with two sub-scenes (list of recordings and view a single recording) and a tab for creating (creationTab) recordings with several steps (recordView, descriptionView, publishView). After the last step, the recording is published and we redirect to the viewRecording scene for that recording in the listTab.
When pressing the creationTab again, we would like to get back to the first scene of the creation process again, but instead we of course land on the last step (publishView) again.
What we tried
After reading through the documentation and issues connected to this, we figured the option reset might help us. However, if we try to add type='reset' to the props of creationTab, when pressing the tab, all other tab icons disappear (as documented in this issue).
So instead, we then tried to set the type of our push from publishView to recordingView to reset, but that also did not work (although the right action is dispatched and the back button is removed on the new scene, when hitting the recordingTab icon again, we still get back to our old publishView).
We also though about using Switches, to unmount the components but it doesn't seem like this is how they were intended to be used...
Versions
react-native: 0.30.0
react-native-router-flux: 3.32.0
We're now getting a bit desperate after days spent on issues like this and similar ones and I am not sure how we should proceed. Has anybody experienced similar problems or found a solution?
I faced the same issue. As a temporary workaround, I do not use the reset option but instead follow the redirection immediately with a pop action.
In my case, my view is only one level deep so this is not too dirty. I'll look for a cleaner solution but I hope it can help in the meantime.
react-native: 0.35.0-rc
react-native-router-flux: 3.35.0

Apple's latest (2015) 'link to app store' directive causes unwanted Safari behaviour

I want to add a link from my app to another of my apps on the appstore.
Question How to link to apps on the app store showed that the itunes.apple.com link was,until recently, the normal way to go. I've tried this and everything is fine. The problem begins when I disgard this and use Apple's new recommendation of using appstore.com. I use the following line of code:
[UIApplication sharedApplication] openURL:[NSURL URLWithString:#http://appstore.com/myappname"]];
The first time I call this from my app it works well. You see it jump through Safari and move onto the appstore where it displays my app.
At this point if you look back into Safari you will notice a new blank tab labelled Favourites has been created.
If I go back to my app and perform the same action to link to the appstore again I'm prompted with one of the two popup boxes:
"Open this page in "App Store"? [Cancel] or [Open].
or
"Cannot Open Page. Safari cannot open the page because the address is invalid" [OK]
I've found that manually deleting the blank tab in Safari will allow the link to work properly but this behaviour isn't what I want my users to see- and I wouldn't be expecting them to delete the blank tabs from Safari.
Any advice on stopping this behaviour whilst following Apple's new rules greatly appreciated.
A simple and clean solution is to present an instance of SKStoreProductViewController inside your app (modally) to display information on the products you are interested in. The user can interact with it as a small view on the App Store and you can simply dismiss it when done.

how to navigate to settings in android emulator using robotium?

I am a newbie for Robotium and till then I managed to learn a lot by directly writing test cases for public websites and sorted out several issues from answers in stackoverflow. now, I seemed to hit the wall at this (probably)trivial problem.
I would like to navigate to 'Settings' icon which is inside 'Apps' menu of the android emulator using some sort of 'robotium-solo' method.
This is my failed attempt:
solo.sendKey(KeyEvent.KEYCODE_HOME);
//solo.clickOnImageButton(2); // no success!
//solo.clickOnActionBarItem(2); // no success!
solo.clickOnText("Settings");
solo.clickOnText("Music");
I checked for any KEYCODE_var for home screen 'app' icon but couldn't find one.
There is no useful log message in DDMS to figure out the starting activity when clicked/tapped on that button.s
Please guide me whether my approach is any good and help me with an answer. Thanks.
you can check with getCurrentViews() and have the list of views displayed before clicking the menu button and after clicking the menu button.By comparing them you can get the view of the new views displayed (i.e. settings button).
After getting the view,you can go with solo.clickOnView(ViewNameObtained);
This will solve your problem for sure.
As far as I know, navigating to settings is not possible with robotium. Even if you would be able to go there you cannot perform any other action as Settings are not port of your application. Android Instrumentation allows performing actions only within one package and robotium is only wrapper for that, so it's not able to click outside your application as well.
You can use UI Automator for that.

How to use AssistiveTouch UI in iOS

I'm now developing an app on iOS. With some reason, I want to use AssistiveTouch UI in my app. For example, there will display a button in my app like AssistiveTouch, if anyone press this button, four buttons will appear like AssistiveTouch, if anyone press one of there four buttons again, some action i set before will excuse.
Does apple support api about this? Or Is there any source code available?
You would have to reimplement this from scratch. There is no public API for either accessing the existing Assistive Touch feature (it has to be turned on by the user in the settings) or for creating a similar UI.

Is it possible to enable or disable VoiceOver within an iOS app?

I would like to be able to turn VoiceOver on or off within my iOS app. The reason for this is I am trying to help a person with disabilities which render her unable to read messages (hence the need for VoiceOver), and who is also unable to triple click the home-button due to motor coordination problems. The way to the setting through Settings>General>Accessibility>VoiceOver>VoiceOver>Flipswitch is far too long and complicated.
Is it possible, without jailbreaking the device, to change this setting in an app? The app doesn't need to make it to the App Store, if that helps.
Alternatively, is it easy to do this with a jailbroken device?
Another approach may be to simulate the triple-click on the home-button that automatically turns on VoiceOver. Is there any way to do this?
Get the app aHomeIcon.
Open the app and tap URL.
Insert the url: prefs:root=General&path=ACCESSIBILITY
Tap 'Done'.
Insert a name to be shown below the icon.
Tap the export button at the bottom of the page. Safari opens.
Add a bookmark and select 'to home-screen'.
Now you can tap that icon and you are redirected to the accessibility part of the settings app.
See this link for reference.