How can I click buttons in Control Center? - ios

I'm a newbie when it comes to Swift and UITesting. I have a test case that must turn off the internet connection of the device but since I can't do that, I tried to access the control center by swiping the bottom most element available in the app
let app = XCUIApplication()
app.buttons["Device"].swipeUp()
app.buttons["Device"].swipeUp()
Now that shows the control center, but when I try to click the airplane mode or the Wi-Fi button, it fails.
app.otherElements["Airplane Mode"].tap()
app.otherElements["Wi-Fi"]
See Screenshot Here
Please help me how to do that or if not, a workaround to turn on or off the internet connection of my device, thanks!

There is no reliable way to do this using UI Testing. In UI Testing you can see the view hierarchy of only App under test.
Control Center is outside your App, so you do not have access to its view hierarchy.
If you would like to really do this, one way is it hard code the coordinates and then perform tap actions. Since UI Testing does not have a mechanism to specify coordinated directly, best way to do this is using coordinateWithNormalizedOffset(normalizedOffset: CGVector).

Related

For iOS, is it possible to have a Toast message that can display on top of system app Settings?

I have a button in my app that brings up the system app settings UI. Instructions are given around the button.
I want to provide further instructions to the user via a toast message after the settings page shows up so they know exactly what to do. It's not a super intuitive setting, related to notification style, and such instructions would be a lot clearer when the user is actually on the settings page.
In Android, this is easily done via toast.makeText().show(). The resulting toast would have no problem going on top of the system settings UI.
In iOS though, I've looked up several guides, mostly using the UIView animation. The problem is, the resulting toast window seems to only work inside the app itself. It cannot go on top of the system settings UI.
Is what I want to achieve technically possible in iOS?
No. You are sandboxed; Settings is a different app and you cannot impose anything on to its interface.

Can the click method in XCUIElement be used outside of the testing framework?

I would like to click an element without user input. I see it's possible in XCUIElement which is a part of the XCTest framework to ensure things are working correctly, and I'm aware of various other testing frameworks that support E2E testing with simulated clicks. But is it possible to trigger this in production outside of testing? E.g. How app remotes work for a TV - pressing a button on the app will move right, left, or click an object on the TV (only remove the TV from this question and have it target the OS it's running on)
It seems accessing other apps might not be possible - https://developer.apple.com/forums/thread/698795?login=true
But they did recommend a way to programmatically click a button that was found in another stack overflow post here - how to programmatically fake a touch event to a UIButton?

Take screenshots programmatically of entire scrollable area of another app in iOS

Currently it is cumbersome for the user to repeatedly scroll and take a screenshot if they want to capture more than what can fit on the screen at a time.
I would like to implement functionality such that at the request of a user (e.g. via tapping a special button on a custom keyboard), screenshots of the entire scrollable area of the currently opened app are automatically taken and stitched together.
Is this possible? And if so, how?
To clarify, the application containing the scrollable area is a third party application over which I have no control, e.g. iMessage or Facebook.
Edit: I am aware of answers like this one and this one that are about taking screenshots within an app that I control. As far as I can tell, these are not applicable in my situation. Please correct me if I am wrong about this.
This is not possible. Each app is contained in a protected sandbox that no other apps have access to.
You could make a custom keyboard, but you still wouldn't have access to any of the views in the app that you don't control.

How to create a popup window in Xcode Swift?

I have an iOS info app. The main screen of the app consists of rows of icons. I want that after tap on certain icon card with information appears and background blurs. To close the card I need to swipe up or down. It is very similar to Instagram's imageviewer.
Please help me create that.
P.S. This is my first project so please keep this in mind when you going to describe the method.
It should look like this
The answer to your question is probably hidden beneath the layers of how you can segue between the scenes of a storyboard. First, you create a scene like this in the storyboard and use some third party libraries to present it as a 'pop-up'. It is not possible for you to do that natively as Apple has not added any segue style showing the scene like a pop-up on the iPhone screens (On iPad it's possible - check how Apple presents choose Wi-fi network in Settings). For that purpose, you can use BlurryModalSegue or CNPPopupController to perform such operations.
Thank You!

Show a view on main screen while the app is in background in ios

Thanks in advance.
Is it possible to show a capture screen like assistive touch view in ios when we click on application icon.Means i want to show the iPad screen and top on the with transparent background a view need to display.
I want to create an app like this after clicking the app icon i want a screen like this on my main screen and i can able to customize it and capture the selected area. is it possible to do that. and is there any api for that.
i don't think you are allowed to capture the home screen in public api. this question had similar request.
How can I take a screenshot of the iPhone home screen programmatically
UIGetScreenImage() mentioned in the answer is very useful, if you only targeting Jailbroken phones.
However, i found an open source library called "Record My screen", which claim can
Record the display even on non-jailbroken iPhones.
I personally didn't test that, since i believe Apple would somehow find that and pull the app off (that happened to several apps before). If you really interested in it, maybe you can learn something from that library.
Hope that helps you.

Resources